1. WooCommerce Bulk Variations
  2. Advanced Usage

Display the bulk variations grid for wholesale users only

Lots of people use our WooCommerce Bulk Variations and WooCommerce Wholesale Pro plugins together because the bulk variations grid provides a quick way to buy many variations at once. By default, the variations grid will be used for all your customers - including non-wholesale users and guests. This article contains code snippets which allow you to display variation dropdowns for normal customers, while showing the bulk variations grid for wholesale roles only.

We have provided a choice of two code snippets, depending on whether or not you want to display the variations grid for administrators as well as wholesale users.

Please note that these code snippets are aimed at developers. If you don't know how to use them then we recommend posting a job on Codeable where one of their WordPress experts will send you a quote.

We've partnered with Codeable to provide our customers with expert help if required.

Code snippet #1: Display the variations grid for wholesale roles

add_action( 'wp', 'hide_wcv_table_for_non_wholesale_customers', 20 );
function hide_wcv_table_for_non_wholesale_customers() {
    if ( class_exists( '\Barn2\Plugin\WC_Wholesale_Pro\Util' ) && ! \Barn2\Plugin\WC_Wholesale_Pro\Util::is_wholesale_user( wp_get_current_user() ) ) {
        remove_action( 'woocommerce_before_single_product', array( 'Barn2\Plugin\WC_Bulk_Variations\WC_Bulk_Variations_Products', 'hook_into_summary_actions' ), 1 );
    }
}

Code snippet #2: Display the variations grid for wholesale roles AND administrators

add_filter( 'wc_bulk_variations_get_table_output', 'hide_wcv_table_for_non_wholesale_customers', 11 );
function hide_wcv_table_for_non_wholesale_customers( $table_content ) {
    if ( current_user_can( 'manage_woocommerce' ) || ( class_exists( '\Barn2\Plugin\WC_Wholesale_Pro\Util' ) && Util::is_wholesale_user( wp_get_current_user() ) ) ) {
        return $table_content;
    }
    return '';
}

Related Articles

If searching the knowledge base hasn't answered your question, please contact support.