Addify Summer Sale 2024 - Get all extensions at a Flat 30% Discount. Hurry Up! Discount is available for limited use only. Use Code: Summer24

How to Restrict Product Visibility for Specific User Roles in WooCommerce?

b2b for woocommerce

When managing an eCommerce website with WooCommerce, there may arise situations where you need to limit product visibility to specific users. This could involve offering exclusive products to VIP or wholesale customers or hiding certain products from regular customers. In this tutorial, we will explore how to restrict product visibility in WooCommerce based on user roles, ensuring a personalized shopping experience for different customer groups.

Restrict Product Visibility for Specific User Roles in WooCommerce – 2 Methods

You can restrict product visibility for specific user roles in WooCommerce using two methods:

  1. B2B for WooCommerce by Addify
  2. Program-based Implementation

Method#1: B2B for WooCommerce by Addify

B2B for WooCommerce by Addify is a comprehensive wholesale solution designed to enhance your online store for both B2B and B2C customers. It provides all the necessary features and functionality to cater to the unique needs of wholesale buyers while maintaining a seamless shopping experience for your B2C customers. 

With B2B wholesale for WooCommerce, there is no need to go through the hassle of setting up a separate store for your B2B and wholesale customers. The combined features of the plugin includes:

  • Restrict Product Visibility by User Roles
  • Manage B2B Customer Registrations 
  • Adjust Pricing by User Roles
  • Offer Tax Exemption to Customers
  • Add Quote Information on Order Detail Page 
  • Restrict Shipping Methods by User Roles
  • Restrict Payment Methods by User Roles

While B2B for WooCommerce offers an all-in-one solution to your online store; here, we will proceed with how you can restrict products to be visible to selected users in your store. 



  1. Download the .zip file from your WooCommerce account.
  2. Navigate to WordPress Admin > Plugins > Add New and Upload Plugin the file you have downloaded.
  3. Install Now and Activate.

Setup & Configuration

After installing and activating the WooCommerce B2B plugin, a new option, “B2B” will appear in the WordPress admin menu. Click to view and configure the settings of the plugin to your store’s requirements. 

To configure the Product Visibility by User Roles feature, go to B2B > Settings > Products Visibility. You can configure this feature using:

  • Global products visibility options
  • Products visibility by user roles
  • General settings linked to product visibility

Global Settings for Products Visibility

The global visibility settings in WooCommerce wholesale plugin provide store owners with the ability to control the visibility of products for different customer groups. These settings allow you to hide or show products to two main categories: not logged in customers and all registered customers, regardless of their user roles. 

With this functionality, you have the flexibility to customize the product visibility based on your specific business requirements and customer preferences. These include:

  • Enable/disable global visibility for user roles
  • Show/hide products for user roles
  • Select the products on which you want to apply the restriction
  • Choose categories to apply visibility by user roles
  • Set a customized message to display when a user access restricted page

Product Visibility by User Roles

In this section, choose the user role(s) for which you want to activate the restriction. You can show or hide products based on specific user roles and customize error messages for each role.

For example, if you show “Product A” to wholesale customers, they will only see “Product A” in the catalog, and all other products will be hidden from them.

If you choose to hide “Product A” from wholesale customers, only “Product A” will be hidden for them, while the rest of the products will remain visible.

Note: The visibility settings for user roles only affect the selected roles, while all other customers will be able to see the entire catalog unless you have a general global setting that overrides this restriction.


General Settings for Product Visibility

In the “General Settings” tab, you have the option to specify whether you want to allow or disallow search engines from crawling and ranking your restricted or private pages. This setting allows you to control the visibility of these pages in search engine results.


Use Cases

Wholesale Stores: Ideal for wholesale for WooCommerce companies and B2B stores that need to restrict certain products exclusively to their wholesale customers.

Membership Sites: Perfect for WooCommerce membership sites offering special products, such as event tickets, personalized merchandise, or limited-edition items, to their members.

Members-only Stores: Suited for stores that provide exclusive access to products only for registered members, requiring customers to log in to browse and make purchases.

Various Other Use Cases: The plugin can be valuable in many other scenarios where you need to create hidden products in your WooCommerce store to cater to specific customer groups or enhance the shopping experience.

Method#2: Restrict Product Visibility for Specific User Roles Programmatically

The second method to restrict product visibility for specific user roles is through a program-based implementation.

add_action( 'woocommerce_product_query', array( $this, 'afpvu_custom_pre_get_posts_query' ), 200, 2 );

ublic function afpvu_custom_pre_get_posts_query( $q ) {

global $product;

$afpvu_enable_global = get_option('afpvu_enable_global');

$curr_role           = is_user_logged_in() ? current( wp_get_current_user()->roles ) : 'guest';

$role_selected_data  = (array) get_option('afpvu_user_role_visibility');

if ( empty( $role_selected_data ) && 'yes' !== $afpvu_enable_global ) {



$role_data = isset( $role_selected_data[$curr_role]['afpvu_enable_role'] ) ? $role_selected_data[$curr_role]['afpvu_enable_role'] : 'no';

if ( 'yes' === $afpvu_enable_global ) {

$afpvu_show_hide          = get_option('afpvu_show_hide');

$afpvu_applied_products   = (array) get_option('afpvu_applied_products');

$afpvu_applied_categories = (array) get_option('afpvu_applied_categories');


if ( 'yes' === $role_data ) {

$_data                    = $role_selected_data[$curr_role];

$afpvu_show_hide          = isset( $_data['afpvu_show_hide_role'] ) ? $_data['afpvu_show_hide_role'] : 'hide' ;

$afpvu_applied_products   = isset( $_data['afpvu_applied_products_role'] ) ? (array) $_data['afpvu_applied_products_role'] : array() ;

$afpvu_applied_categories = isset( $_data['afpvu_applied_categories_role'] ) ? (array) $_data['afpvu_applied_categories_role'] : array();


if ( empty( $afpvu_applied_products ) && empty( $afpvu_applied_categories ) ) {



$products_ids = array();

if ( !empty($afpvu_applied_categories) ) {

$product_args = array(

'numberposts' => -1,

'post_status' => array('publish'),

'post_type'   => array('product'), //skip types

'fields'      => 'ids'


$product_args['tax_query'] = array(


'taxonomy' => 'product_cat',

'field' => 'id',

'terms' => $afpvu_applied_categories,

'operator' => 'IN',


$products_ids = (array) get_posts($product_args);


$afpvu_applied_products = array_merge( (array) $afpvu_applied_products, (array) $products_ids );

if (!empty($afpvu_show_hide) && 'hide' == $afpvu_show_hide) {

$post__not_in = (array) $q->get('post__not_in');

$q->set('post__not_in', array_merge($post__not_in, $afpvu_applied_products));

} elseif (!empty($afpvu_show_hide) && 'show' == $afpvu_show_hide) {

$q->set('post__in', $afpvu_applied_products);


do_action('addify_query_visibility_applied', $q );



If you haven’t got the plugin yet, get B2B for WooCommerce now and start restricting your product by user roles. Not only this, you can take use of the additional powerful features offered by this plugin.

If you have any additional inquiries or require further assistance, please feel free to contact our dedicated support team. They are readily available to help and can address any questions or concerns you may have.

Subscribe to Our Newsletters.

Be the first to get an exclusive offer and the latest news.