How To Hide Products in WooCommerce Based on User Roles

As store owners, you don’t always want all of your users to be able to see all of your products. In this article, We’ll teach you how to hide products in WooCommerce based on the roles of the users who access them.

Hide Products by User Roles in WooCommerce

For store owners having limited edition products in their store, they can use the WooCommerce Hide Products by User Roles Plugin. Through this plugin they can make products available to only a certain group of customers. To guarantee that only the appropriate people see these items, one of the most straightforward methods is to block their access from users who do not have the appropriate role.

In this article, we will take you to two ways to implement Hide Products by User Roles in WooCommerce:

  • Method #1 – Using a plugin
  • Method #2 – Programmatically 

1: WooCommerce Product Visibility by User Roles – Plugin

Product Visibility by User Roles is a plugin that was built exclusively for the purpose of hiding entire categories and products for specified User Roles in WooCommerce. If you are a merchant who offers customized products, has restricted shipping options, and serves customers from a diverse range of industries, this tool is worth investing in.

Installation

To install this plugin, follow the steps below:

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

Setup & Configurations

blank

After activating WooCommerce Product Visibility by User Roles, you can see the “Product Visibility” appearing under the WooCommerce menu. Click Product Visibility to open the settings page.

The Settings page further provides 3 different tabs to configure the product as per your requirements. These requirements are as under:

  • Global Visibility Settings
  • Visibility by User Roles Settings
  • General Settings 

Global Visibility Settings

The global visibility settings allows store owners to hide/show products for not logged in customers or all registered customers irrespective of their user roles. With this setting, you can choose to hide either Products or Categories. There is an option to set a customized message that will be displayed to such visitors trying to access the restricted page. 

After choosing “Show” or “Hide” products, you can choose specific products and set their category visibility by user role to display or conceal the products.  

At the backend, you can choose to show a product on the shop page by selecting “Show” for that specific product and choosing it’s category as desired. This is shown in the image below. 

blank

Similarly, to hide the product on the shop page, select “Hide” for that specific product and choose its category as desired. This is shown in the image below.

blank

Visibility by User Roles

The Visibility by User Roles tab allows you to choose which products should be visible or hidden for each user role. To change the visibility of your catalog for a specific role, select it from the drop-down menu. To make the new catalog visibility modifications effective, select “Enable for this Role” from the drop-down menu. This plugin enables the ability to show and hide products and categories for all user roles at the same time. These user roles include Administrator, WholeSale, Customer, Guest, etc. 

There are separate visibility settings for each user role. Store owners are able to configure settings separately. After the users select “Enable for this role” users get two catalog visibility options: either Show or Hide the products. With this, you can keep the catalog visibility hidden or shown for the user roles. After this, you get the option to choose products that need to be shown or hidden. 

For instance, you choose “Belt” as a product, select its category and choose to “Show” it to that specific user role, it will be visible on the shop page. 

blank

Similarly, if you choose to “Hide” that belt as a product on the shop page to that same user role, it will be hidden from the shop page and will not be visible to the user anymore. 

blank

General Settings

The general settings allow you to control whether or not search engines are allowed to crawl, index, and rank your website. Specific products and categories can be hidden from non-logged in consumers, and they will remain hidden from Google. This option must be checked in order for search engines to be able to crawl and rank such private pages.

blank

Situations Which Favor This Plugin

Below are some common use cases:

Wholesale Stores 

WooCommerce wholesale companies and B2B stores that sell to both retail and wholesale customers may require a mechanism to limit the availability of specific products to wholesale customers alone. Depending on the situation, these could be product bundles or entirely distinct products.

Membership Sites

WooCommerce membership sites frequently offer unique products in addition to the products that are available to ordinary (non-member) buyers. Tickets to events, engraved merchandise, and limited-edition products are examples of what you might find.

Members-only Stores 

Members-only stores are ones that only make their products available to members who are logged in. To put it another way, in order to browse and purchase things, you must first become a registered member.

There are, of course, a multitude of other instances in which you can find yourself needing to develop hidden products for WooCommerce.

2: Hide Products by User Roles Programmatically

To hide products from the catalog, we can use woocommerce_product_is_visible filter. If the admin selects any user role and hides the specific product then it will be hidden in the shop page for that specific user role.

add_filter( 'woocommerce_product_is_visible',array($this, 'af_product_visible_by_user_role'),10, 2 );

public function af_product_visible_by_user_role( $visible, $product_id ) 

{

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

    $products_to_hide  = array( 100, 150 );       // product IDs

    $roles_to_hide_for = array('customer' ); // empty string is for the "guest" user role

    if (is_array( $roles_to_hide_for ) && in_array( $current_user_roles,$roles_to_hide_for,true )) {

    if (is_array( $products_to_hide ) && in_array( $product_id,$products_to_hide,true )) {

    $visible = false;

    }

  }

    return $visible;

}

Closing Thoughts

We hope this article has given you the basic details regarding the need to hide WooCommerce products in your store according to user roles. We explained the user roles and catalog visibility options using this plugin. Moreover, we looked at the different options for hiding products i.e. individually, category wise, or globally.

Frequently Asked Questions

What is product visibility by user role in WooCommerce?

In WooCommerce, product visibility by user role lets store owners decide which customers, based on their roles, can see or buy specific products. This feature allows a more customized shopping experience for different groups of customers.

How do I restrict products by user role in WooCommerce?

You can control product access by using a plugin like WooCommerce Product Visibility by User Roles by Addify or by writing code. The plugin provides an easy setup, while the code method involves creating rules, like hiding certain products for specific user roles. Choose the method that suits your needs for a more personalized online store.

Avail The Opportunity

Subscribe to Our Updates and Newsletters.