WordPress has a user role management system which defines what a specific user can do on your website. WooCommerce can use this to restrict content and grant access to products on purchase. Permissions can be edited with the help of plugins.
When you install WordPress, there are five default user roles:
WooCommerce User Roles
When you install WooCommerce, it registers two additional user roles. These are:
- Shop Manager
Furthermore, it gives additional capabilities for the Administrator to:
- Manage WooCommerce Settings
- View WooCommerce Reports
Access to posts, pages and custom post types such as products can be restricted by user roles. Any existing role can be used to restrict access and you can create as many different roles as needed to protect entries, so that only members of the corresponding groups can view them.
As an example, you could have a user role “SEO Course” and with a membership plugin you can set that only this user role would have access to the SEO Course offered on your blog.
Create/Add User Role to WooCommerce
If you want to add an extra user role to WordPress, you need to use a plugin. The most basic plugin to do this is called Members. It is a user, role, and content management plugin. Its purpose is to make WordPress a more powerful CMS by giving you control over the users of your site.
The components are the following:
- Edit Roles: Edit your user roles and their capabilities.
- New Roles: Create new roles for use on your site.
- Content Permissions: Adds a meta box on your write post/page editor that allows you to restrict content to specific roles.
- Widgets: Adds a login form widget and user-listing widget that you can use in any widget area on your site.
- Shortcodes: Creates shortcodes that you can use to restrict or allow access to certain parts of your posts and pages (or any other shortcode-capable area).
- Template Tags: New functions for use within your WordPress theme for various things.
- Private Blog: Allows you to create a private blog that can only be accessed by users that are logged in (redirects them to the login page).
- Integration: Members is highly recommended by other WordPress developers. Many existing plugins integrate their custom roles directly into it.
Change User Role After Purchase In WooCommerce
The above plugin is missing one key element: Assigning a user a certain role when he makes a purchase.
If you sell digital products, this feature is vital.
After you have created the needed user roles with the Members plugin, the YITH Automatic Role Changer plugin allows you to automatically assign roles to your customers following a specific purchase or amount spent.
Note: After creating roles you can even uninstall the members plugin so that you don’t have too many plugins working.
In this example, when someone purchases my online course Blogging On The First Page Of Google…
The user will gain the role “Google First Page”.
I have a specific role that has all free courses assigned to it.
Product Prices In WooCommerce Based On User Role
You may also want to have a site where people with a certain membership level can get discounts.
As an example, those who are registered users or those who pay a monthly fee.
Customizing Existing User Roles
Default WordPress user roles are designed to have capabilities that fits the requirement of most websites. For example if you run a magazine site, then you can assign Editor user role to your senior staff and author user role to the junior staff. You can assign contributor user role to your guest authors and subscriber user role for your site visitors.
But what if you wanted to modify the permissions of an existing WordPress user role?
One thing we do not like about the author role is that not only can they publish their own posts, but they can also delete them after it’s published. This can undermine your entire editorial workflow. Also can be disastrous if a paid author leaves on bad terms and decides to delete all the posts they wrote (the ones you paid them for).
Let’s suppose that you want to modify the author user role, so that the authors cannot delete their posts once they’re published.
First thing you need to do is install and activate the Capability Manager Enhanced plugin. Upon activation, go to Users » Capabilities to modify user roles.
Next, select the user role you want to edit from the top box in the right column and then click the load button. This will load users capabilities in the boxes on the left.
All you need to do is uncheck the capabilities that you want to remove from that user role. For example, in this case we want to remove the capability to delete published posts from authors. We will uncheck ‘Delete Published’ capability. Once you are done, scroll down to the bottom of the page and click on the save changes button to store your settings.
User roles in WordPress help in providing a stable structure and organization to varied users of your site. Moreover, it helps you create selective access to your site’s content.