Okay
  Public Ticket #2777668
Stock visibility for user roles
Closed

Comments

  • Jose Luis started the conversation

    Hi!

    I am interested in B2B extension for Woocommerce so our distributors can check their dealer prices as well as updated stock availability for each product.

    However we don't want to show the product stock availability (number of units) for B2C end customers. Is it possible to show it only for a specific user roles (distributor)? 

    Thanks

  •  2,167
    WebWizards replied

    Hi Jose,

    Thank you for getting in touch,


    The plugin doesn't have a feature for this, but it's easy to set up by adding a code snippet to the site.

    For example, the following snippet will hide stock for all B2C & Logged out users:

    $is_b2b_user = get_user_meta(get_current_user_id(),'b2bking_b2buser', true);
    if ($is_b2b_user !== 'yes'){
        add_filter( 'woocommerce_stock_html', function($html, $text, $product){
            return '';
        }, 10, 3 );    
    }
    

    You can also show stock only to specific groups by slightly modifying the above snippet.


    Kind regards,

    Stefan