Do you want to assign your customers with different user roles when they purchase certain products? In this article, I’ll show you how to automatically set the user’s roles after making a purchase depending on which WooCommerce product(s) they’ve bought.
Why update user roles after checkout?
One of the main reasons that you might want to automatically assign user roles to customers after they check out is if you’re running a members only site or store.
In this case, users would join your site by purchasing a membership plan, which is simply a WooCommerce product. For example. a user purchases your ‘Gold’ membership plan so would be allocated the ‘Gold Member’ user role after checkout.
Having the ‘Gold Member’ user role would then entitle them to certain benefits on your site, like being able to access restricted content or getting a discount on certain products.
To allow you to automatically update user roles after checkout, you’ll need the WooCommerce Members Only plugin:
Assigning user roles automatically after purchasing a product
To automatically assign one or multiple user roles to a customer after they purchase a product, just follow these steps:
- Edit the product
- Click the ‘Members Only’ tab
- Enter the user roles that will be assigned to the customer after they purchase the product
Now, whenever a customer purchases that product, they will be assigned the additional role(s) you’ve specified.
Automatically assign roles to new customers in WooCommerce
The method described above works perfectly for both existing customers and new customers.
If you want to ensure that customers are registered and logged in before they check out, you’ll need to disable the ‘Guest checkout’ option in WooCommerce.
Go to WooCommerce > Accounts & Privacy and deselect the ‘Allow customers to place orders without an account’ checkbox.
How to automatically create an account for new WooCommerce customers
However, you can also automatically register an account for new customers in WooCommerce. This will ensure that user roles will get allocated to all customers, even if they haven’t previously created an account.
To automatically create an account for new users in WooCommerce, go to WooCommerce > Accounts & Privacy and check the ‘When creating an account, automatically generate a username from the customer’s email address’ option. You can also check the ‘When creating an account, automatically generate an account password’ option if you wish.
WooCommerce user roles
WooCommerce Members Only is a fully-fledged user roles plugin. Not only does it allow you to automatically assign roles after purchase, it is a user role manager.
With Members Only, you can create, edit and delete user roles. You can also assign or remove capabilities from roles.
How to create and edit user roles in WooCommerce Members Only
To create a new user role in WooCommerce:
- Go to WooCommerce > Settings > Members Only > User Roles
- In the ‘User roles’ field, select a user role to duplicate
- Enter the name of the new role in the ‘New role name’ field
- Click the ‘Duplicate role’ button
To edit the new role:
- Select the user role to edit from the ‘User roles’ field in the ‘Edit Role’ section
- A list of capabilities will be displayed. Select or deselect capabilities for the role as required
- Click ‘Update Role’
How to set product price by user role in WooCommerce
Once you’ve assigned a user role after purchase, you might want to provide some benefits to customers with that user role.
A typical benefit would be to get a discounted price. You can see how to set prices by user role in WooCommerce here.
You can also find out how to hide products by user roles in WooCommerce.
That’s a pretty short and sweet look at how to automatically set user roles in WooCommerce after purchasing a product. You just need the WooCommerce Members Only plugin.