Creating a login page for your WooCommerce protected categories
If you’re using the WooCommerce Protected Categories plugin, then you’ll need a way for customers to log into your protected categories. This will depend on whether you’re using password protected or user/role protected categories. We will cover both options below.
Password protected categories login page
There are two ways for visitors to log into WooCommerce password protected categories:
- When they visit a password protected product category (i.e. the category archive) or visit one of the products inside the category, or one of its sub-categories. The visitor will be shown the login form where they can enter a password. They must enter the correct password for the category to unlock it and reveal the contents.
- From a central login page. The central login page allows the visitor to login to any password protected category in your WooCommerce store. A login form is displayed on this page where the user can enter a password.
If the user enters a correct password for a category, they will automatically be redirected to that category. The login form will direct them to the first matching category that it finds, so it makes sense to use a different password for each category to avoid any potential conflicts.
Create a central password login page
There are 2 ways to create a central login page for your password protected WooCommerce categories. If you only need one login form for your password protected categories, then you should select a page from the ‘Password entry page’ option on the plugin settings page. The password login form will automatically be added to this page, and you can link to it as required (e.g. from your navigation menu).
If you want to add different login forms to different parts of your site, then the plugin also comes with a shortcode that you can use to create additional login forms. To do this, simply add the shortcode
[category_login]. You can add it to a ‘Shortcode’ or ‘Paragraph’ Gutenberg block, to a text widget, or to the main page content within the classic WordPress editor:
Password login form shortcode options
By default, the message that you have entered on the plugin settings page will appear above the password protected categories login form.
You can override this for each individual login form using the following shortcode options:
heading="Your heading here"– overrides the heading above the password login form.
show_heading="false"– hides the heading above the password login form. This shortcode option is set to “true” by default, so you only need to use it if you want to hide the heading.
message="your message here"– overrides the message displayed above the password entry field.
label=""– overrides the ‘Label’ text which appears in or next to the password entry field (depending on your theme).
button_text=""– overrides the button text on the category login form.
For example, the following shortcode will create a password login form with all of these options:
[category_login heading="Login Below" show_heading="false" message="Please enter your password below:" label="Enter password" button_text="LOGIN"]
User and role protected categories
The plugin also has options to restrict categories so that they are automatically available to specific logged in users or user roles. With these options, the protected categories will automatically be unlocked whenever a user logs into their account on your website. This means that you don’t need a special login form for your protected categories – you just need a normal login form.
This is not part of our plugin, but here is advice on different ways you can allow users to log into their accounts:
- The default WordPress login page at [your-domain.com]/wp-login.php.
- Logged out users are shown a login form when they try to access the WooCommerce Account page.
- You can also create a professional-looking front end user account login form with a plugin such as Theme My Login.
Whichever method you use for people to log into their accounts, they can access their protected categories after logging in.
Once people have logged in, you will need to consider the best way for them to navigate to their protected categories.
Can customers automatically log into a protected category by clicking a link/URL?
This is not possible for password protected categories, because the user must enter a correct password to unlock the category. You can achieve this for user or role protected categories by using our plugin with a WordPress auto-login plugin such as Autologin Links.