How to create WooCommerce protected categories (by user role or password)

WooCommerce hidden category featured image

Would you like to create protected categories in your WooCommerce store – so that access is restricted to certain users, user roles, or via password? WooCommerce gives you some basic options for achieving this – in this article, we look at some simple ways to keep your categories locked and protected.

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 call 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

In this article, we’ll look at what basic functionality WooCommerce and WordPress has to accomplish this – and we also look at the WooCommerce Members Only plugin for more advanced features.

WordPress ‘password protected’ posts

First, WordPress itself provides a setting out of the box for you to password protect posts and products. To create a password protected product:

  • In the ‘Publish’ panel of your product, click the ‘Edit’ link next to ‘Visibility’
  • Select ‘Password protected’
  • Enter the password that will be required to view the product page
  • Click ‘OK’
Password protect post or product in WordPress

However, there are some drawbacks to this:

  • You need to apply this product by product. It’s fine if you only want to password protect one product but it doesn’t work for multiple products or by category
  • You can only have one password per page. With the Members Only plugin, you can create multiple passwords
  • This only works if you want to protect content through passwords – there’s no method to protect via user or log-in status

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.

WooCommerce Members Only featured image

WooCommerce Members Only

Create protected categories in WooCommerce

Find Out More

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 Members Only > Settings to view the settings.

Members Only global settings

On this page, you can define the main settings for your site, including:

  • Restriction Method: how to decide who can see your protected content. You can choose from:
    • No restriction
    • Log-in status – so only logged in users can see the content that you want to protect
    • Password – only users with the right password can see the protected content
    • User role – only users with the necessary user role can see the content
  • After Logging In: here you can choose whether to redirect users to a specific page after they log in
  • After Log In, Redirect To: select which page to redirect users to
  • Password Form Page: if you are restricted content with passwords, the plugin will automatically create a page with a password form
Protected category settings

Membership plans

Once you’ve updated the main settings, you can create one or more membership plans. Plans are a set of rules that define what content is restricted. Having multiple plans means you can protect different product categories and other content from different users – so wholesale and retail customers could be prevented from seeing one another’s products.

To create a membership plan to protect product categories:

  • Go to Members Only > Plans and click ‘Add New Plan’
  • To create protected categories, update the ‘Restricted Content’ field to ‘Product Categories’
  • In the ‘Restricted Product Categories’ field, select the product categories that you wish to protect in this plan
  • If you’re using passwords to protect content, enter the passwords in the ‘Passwords’ field, one per line
  • If you’re protecting content through user role, enter the roles that can view the categories in the ‘Permitted User Roles’ field. You can also select specific users who are permitted to view the content
Membership plan settings

In the example above, the ‘Hoodies’ category will be restricted to any users who have the ‘Gold member’ user role.

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.

Protecting different categories with different passwords or user roles

You can protect different categories with different passwords or user roles by creating multiple membership plans.

For instance, if you have created a plan plan to restrict products in the ‘Hoodies’ category to ‘Gold members’ only, you could create a second plan to restrict products in the ‘Accessories’ category to ‘Silver members’ only.

Likewise, if you are using passwords as your restriction method, you can create multiple plans, each with different passwords, that restrict different content.

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 main 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.

Hide in archive setting

What happens when a user tries to access a protected WooCommerce category?

If the user tries to access protected categories, they can be redirected to a landing page. Each plan can have its own landing page – so you can direct users to different pages depending on which category they try to access.

To set a landing page, just select a page from the ‘Landing Page’ field in the plan settings.

Landing page setting

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?

By default, if a product is in one category that has no restrictions and in another category which is only open to users with the ‘Member’ role, then that product will only be available to users with the ‘Member’ role.

However, if you would like to allow users to access a product that is in a non-protected category (even if it’s in a protected category as well), you can enable the ‘Permit across Multiple Categories’ option.

Permit multiple categories x.jpg

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.

WooCommerce Members Only featured image

WooCommerce Members Only

Create protected categories in WooCommerce

Find Out More

Two comments

Leave a Reply

Your email address will not be published. All fields are required.