Hi, is it possible to hide stock levels for certain user roles? I would like stock levels to display on the single product pages for only the user role reps?
Thank you. The Reps role is a WP User Role. I would like to hide stock on all the single product pages for everyone except users role reps? I wasn't sure if I could do this with B2B king.
B2BKing doesn't have any feature allowing you to hide stock. But if I can help with a snippet, unrelated to the plugin, I'd be happy to do so.
I think the following snippet can do it:
$user = new WP_User( get_current_user_id() );
$roles = ( array ) $user->roles;
if (!in_array('reps', $roles)){
// if user does not have the reps role, hide stock
add_filter( 'woocommerce_stock_html', function($html, $text, $product){
return '';
}, 10, 3 );
}
I tested it and it seems to work. You may need to refresh the page once or twice after adding it.
Hi, is it possible to hide stock levels for certain user roles? I would like stock levels to display on the single product pages for only the user role reps?
Thanks
Darren
Hi Darren,
You can achieve this by adding a PHP snippet to your site: https://woocommerce-b2b-plugin.com/docs/how-to-add-a-snippet-php-or-js/
For example, the following snippet will hide stock for all B2C & Logged out users:
The REPS role - is that a WP User Role (like administrator, editor, etc)? or is it a B2BKing B2B Group?
Kind regards,
Stefan
Hi Stefan,
Thank you. The Reps role is a WP User Role. I would like to hide stock on all the single product pages for everyone except users role reps? I wasn't sure if I could do this with B2B king.
Thanks
Darren
Hey Darren,
B2BKing doesn't have any feature allowing you to hide stock. But if I can help with a snippet, unrelated to the plugin, I'd be happy to do so.
I think the following snippet can do it:
I tested it and it seems to work. You may need to refresh the page once or twice after adding it.
Thank you for your help Stefan, this works brilliant.
Thanks
Darren