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 assign different rules to different categories.
What is a ‘protected’ category in WooCommerce?
A protected category in WooCommerce simply means a user can’t access the category or its 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.
Reasons to create private categories in WooCommerce
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.
- 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 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 the WooCommerce Members Only plugin.
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
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.
In the example above, the ‘Members Only’ category will be restricted to any users who aren’t logged in.
Protecting 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).
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.
Some of the main advantages to using passwords to protect your 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 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.
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.
- 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
Creating 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.
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 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.
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.
What happens when a user tries to access a protected 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.
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.
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.