How to create WooCommerce protected categories (by user role or password)
![](jpg/belinda-fewings-977695-unsplash-856x642.jpg)
I recently looked at methods to create private categories in WooCommerce. In this article, we’ll take things a stage further and look at how to create WooCommerce password protected categories or categories that are only available to certain user roles.
What are WooCommerce protected categories?
A WooCommerce protected categories simply mean a user can’t access certain categories or their products unless the user has the correct permissions. You could also called this a private or restricted category.
In any case, a protected category simply means that, in order to gain access, the user must either:
- Enter a password
- Have a certain user role
- Be logged in
We’ll look at the first two methods in this article.
What are the reasons for creating WooCommerce protected categories?
For detailed reasons behind creating private categories, you can check out this post on How to create private categories in WooCommerce. That article mainly looked at creating one or more categories with a single restriction rule, e.g. defining categories that were only accessible by admins, or creating categories that could only be accessed if you had the correct password.
In brief, the main reasons include:
- Incentives for your customers
- Membership sites that offer members only products
- Staff only products
- Wholesale/retail products
- Age restricted sites where you need verification of a user’s identity before you can sell to them
Different permissions for different categories
Those are all great reasons for creating private categories. However, there are times when you want to extend this and allow different users access to different categories or products.
Having a single restriction rule might be a bit simplistic for your needs. What if you want to have more than one protected category, available to different sets of users? Maybe you’ve got a user role for ‘Gold’ members and one for ‘Silver’ and you want to offer those users different products. The way to do this is to assign category-specific restriction rules.
With category-specific rules, you can create different rules for each category if you wish. You could, if you wanted, create a different category for each user role.
(By the way, click here to find out how to automatically set user roles when customers purchase one of your products.)
For instance:
- You sell client-specific products, like photographs, customised products, stationery, graphic design, music, and many others
- Your site has different membership tiers so you’d like to offer members in one tier different products or prices from members in a different tier
- You’d like to offer customers different products based on what they’ve bought from you previously
- You’re selling Business to Business or wholesale and you have different categories of pricing and product for different business types
In all these cases, you want to allow different users access to different categories. We can achieve this with WooCommerce Members Only, a membership plugin for WooCommerce.
Setting up WooCommerce Members Only
Members Only is a really quick plugin to configure. Once you’ve installed and activated it, you can go to WooCommerce > Settings > Members Only to view the settings.
Members Only global settings
![WooCommerce Members Only settings page](https://pluginrepublic.com/wp-content/uploads/2018/12/members-only-setting-page.jpg)
If you’d like to create protected categories, you just need to update the ‘Restricted Content’ field to ‘Specified Categories’.
At this stage, if you want to restrict all categories in the same way, you can enter your restricted categories in the ‘Restricted Categories’ field.
![](https://pluginrepublic.com/wp-content/uploads/2019/03/wcmo-restricted-categories.jpeg)
In the example above, the ‘Members Only’ category will be restricted to any users who aren’t logged in.
Protecting WooCommerce categories by password or user role
As we’re looking to define different restriction rules for different categories, we also need to change the ‘Restriction Method’ field to either ‘Password’ or ‘User Role’. (You can also restrict access by the user’s log-in status but that’s not relevant for the purposes of this article).
![WooCommerce Members Only protect categories by password or user role](https://pluginrepublic.com/wp-content/uploads/2019/03/wcmo-restriction-methods.png)
Which is better – protecting your categories by user role or by password?
Let’s take a look at the pros and cons of each method.
Password-protecting WooCommerce categories
Some of the main advantages to using passwords to protect your WooCommerce categories include:
- Passwords are handy if some or all the visitors to your site do not yet have an account on your site – e.g. if they haven’t purchased from you before or if you don’t require customers to create an account on your store.
- You can create passwords ad hoc, just whenever you require, and hand them out as you wish to different customers
- With Members Only, you can assign multiple passwords to categories or you can have a single, unique password for all users
- Passwords can be very useful if you’re running promotions on your store – for instance, you can email your newsletter subscribers with a password to gain access to products on sale
The main disadvantage to using passwords as a restriction method is that you can never be sure who is using the password. Passwords can be easily shared (this might be a good thing for you) so you can’t be 100% confident that the person using the password is the person you gave it to.
Protecting WooCommerce categories by user role
What is a user role?
User roles are incredibly powerful – they define what capabilities a user has on a site. For more information, you can take a look at user roles in WordPress in the Codex. Or, read this article for specific information on user roles in WooCommerce.
The main advantages to protecting categories by user role include:
- Granularity of control – this means you can apply some fine-tuning to which users can access which categories. For instance, you can apply a user role of ‘Gold’ to any customer who purchases a gold subscription product from you. You can then automatically grant these users access to specific categories that other customers would be excluded from.
Disadvantages include:
- Your site visitors need to have a user account in order to have a user role. So if you are planning to protect categories from users who are not logged in or who don’t have a user account, then protecting categories with passwords is the best option
For more information on hiding products by user role, take a look at this article.
Creating WooCommerce protected categories
So far, we’ve just looked at installing the Members Only plugin and configuring its global options. If you plan to apply different rules to different categories, you can do that from the ‘Edit category’ screen.
Override global rules with category-specific rules
Go to the product category that you’d like to restrict access to. In this example, we’re going to create a category that can only be accessed by admins.
At the bottom of the settings, notice a couple of extra fields.
![WooCommerce edit categories screen](https://pluginrepublic.com/wp-content/uploads/2019/03/wcmo-edit-category-1120x1200.jpeg)
Select ‘Override Global Restrictions’ to enable a specific rule for the category.
Depending on what you have set your ‘Restriction Method’ to in the global settings, you’ll either get a field to enter ‘User Roles’ that are permitted to access this category (as above) or ‘Passwords’ where you can enter category-specific passwords.
This category now has a different protection rule from any categories set in the global settings.
Decide whether to display protected categories or hide them completely
You can decide whether to display protected WooCommerce categories to users who can’t access them. You might want to do this in order to encourage users to upgrade to a different membership plan, for instance.
In the global settings screen, select or deselect the ‘Hide Products in Archives’ field. If you select this field, then protected categories and products will not be visible to users who don’t have access to them.
![WooCommerce hide products](https://pluginrepublic.com/wp-content/uploads/2019/02/woocommerce-hide-products.jpeg)
However, if you leave this field deselected, protected categories and products will still be visible as a kind of teaser to let the user know what they’re missing.
![WooCommerce protected categories](https://pluginrepublic.com/wp-content/uploads/2019/03/wcmo-woocommerce-protected-categories.jpeg)
What happens when a user tries to access a protected WooCommerce category?
If protected categories and products aren’t hidden, as in the image above, and the user tries to access a category, they’ll see products blocked in the same way.
![WooCommerce protected products](https://pluginrepublic.com/wp-content/uploads/2019/03/woocommerce-protected-products.jpeg)
In the image above, the two products indicated belong to protected categories.
If the user tries to access a product that is restricted, they can be redirected to a page containing a password form, to a log-in form, or to a landing page. The Members Only plugin will automatically create the password page and form for you.
Note that products in protected categories are automatically protected.
Are subcategories also protected?
Yes, subcategories inherit the restriction properties from their parent category.
What happens when a product is in more than one category?
If a product is in one category that has no restrictions, and another category which is only open to users with the ‘Subscriber’ role, then that product will only be available to users with the ‘Subscriber’ role.
If a product is in categories with different restriction levels, it will follow the restriction rules for the first category created.
In most cases, life will be much easier for you if you don’t allocate products across multiple categories when those categories have different, or even conflicting, restriction rules.
How to hide a WooCommerce category – video
The easiest way to protect WooCommerce categories
Hopefully this article has given you some insight into how easy it is to password-protect WooCommerce categories or to protect categories by user role.
You can find out more about the Members Only plugin by clicking the image below.
where is the plugin?? There is no link to download this plugin???
Hi
The plugin is Members Only. You can purchase it here: https://pluginrepublic.com/woocommerce-protected-categories/?utm_source=PluginRepublic&utm_medium=content-marketing&utm_campaign=woocommerce-protected-categories.
Thanks