Automatically change user roles after purchasing a product in WooCommerce

Do you want to automatically change your customers’ user roles after they purchase a product in WooCommerce? In this article, I’ll show you how to automatically change the user’s roles after making a purchase depending on which WooCommerce product(s) they’ve bought.
We’ll also look at how to set an expiration date for the new role and how to send a reminder email before the role expires.
Why change user roles after purchase?
One of the main reasons that you might want to automatically change the user roles of customers after they check out is if you’re running a membership 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.
Even better, you could create a variable ‘Membership’ product with variations for Gold, Silver, Bronze etc. You can assign a different role depending on which variation the user purchases.
To allow you to automatically update user roles after checkout, you’ll need Members Only, which is a WooCommerce membership plugin:
For more information about WooCommerce user roles, please see this article.
Change user roles after purchase in WooCommerce
We’ll look at two methods for changing the user’s role after they purchase a product.
Method #1: A single, simple product
The simplest way is to assign a new role for a single product. When the user purchases the specific product, Members Only will automatically assign the new role to that user.
To update a single product:
- 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.
Method #2: Using membership plans
Membership plans are sets of rules that determine which users can see which content on your site. So, for example, you might have a membership plan that only allows users with the ‘Gold member’ role to view certain product categories and blog content; users with the ‘Silver member’ role can view different categories and content; and so on.
Membership plans have the option to specify a product which needs to be purchased in order to access the plan’s privileges. So the user might need to purchase the ‘Gold Membership’ product in order to gain the ‘Gold member’ role.
To create a membership plan in WooCommerce that requires a specific product to be purchased:
- Go to Members Only > Plans and click ‘Add New Plan’
- Enter details in the ‘Restriction Settings’ and ‘Content Settings’ sections that determine what content will be restricted in the plan. For example, you could choose to restrict content from certain product categories, certain post types, and/or certain post categories
- Enable the ‘Requires Purchase’ setting
- Select which product the user needs to purchase to access the membership plan in the ‘Product(s)’ field. Note that this could be a variation – so you could create a single variable product with variations for ‘Gold’, ‘Silver’ and ‘Bronze’ memberships
- Enter the role(s) that the user will be assigned after purchase in the ‘Assign User Roles’ field

Let’s take a look at some options when the membership period has expired.
Removing the user role after specified time period
Both the methods above, allow you to remove the user role when the membership period comes to an end.
If you’re using Method 1 on a single product, you can set an expiry date after a set period of time. In the ‘Expires after’ field, enter a value like 6 months, 1 year, etc. The date of purchase will be recorded and the user role will be removed when the expiry period has been exceeded.

For Method 2, there is more flexibility. You can specify the length of the membership in different formats and even assign role(s) when the membership expires.
- Optionally, enter the role(s) that the user will be assigned if their membership lapses
- Choose an option in ‘Membership Length’. You can choose from:
- No expiry: select this option if there’s no end date on the membership plan
- Specific length: choose this if the membership will run for a set period of time, e.g. 1 year
- Fixed date: choose this if the membership will end on a specific date
- Depending on what option you select above, you’ll be able to set either a fixed period or a specific date when the membership will end

Just enter the period that the roles should be assigned to the user. After that period, the roles will be removed and the user can be invited to extend their membership.
Sending a reminder when the user role is due to expire
You might want to send the user a courtesy email to remind them that their membership is due to expire. You can do this by entering a period in the ‘Send reminder’ field. This will then automatically trigger a reminder email at the specified period before the role expires.

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 WooCommerce customers when they make a purchase:
- Go to WooCommerce > Accounts & Privacy
- Enable the ‘During checkout’ option. This ensures that an account is created automatically for any new customers
- Enable the ‘Send password setup link’ option so that the user is not forced to create a password on the checkout page itself. Instead, they’ll receive an email with a link to create the password. This means users aren’t forced to think of a password on the spot and reduces any friction at the checkout
- Also, enable the ‘User email address as account login’ so that the user doesn’t have to think of a user name on the spot

Now, new users will have their account automatically created when they make a purchase – so you can now assign them with a new user role.
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 Members Only > User Roles
- To create a new role, enter the name of your new role at the base of the ‘Roles’ field and click ‘Add role’

- If you’d like to edit the role name, just click ‘Edit’ and update the role name in the text field
- Finally, to delete a role, just click ‘Delete’. Note that it’s not possible to delete roles that are created by WordPress or WooCommerce, only roles created manually
You can then check current user roles using a number of methods:
- Using the wp_get_current_user() function to get the WP_User object and accessing the roles property.
- Utilizing the current_user_can() function to check if the current user has a specific capability.
- Using the user_can() function to check if a specific user has a certain capability.
- Through the get_userdata() function and then accessing the roles property.
- Employing third-party plugins that provide role management features.
Tell the user their role has changed
A great way to ensure your customer knows that their role has been updated is to use the WooCommerce Thank You Pages plugin to add some custom content to your Thank You page.
There’s a tutorial on creating a WooCommerce custom Thank You page here.
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.
You should also read this article for more information on WooCommerce user approvals.
Recap
That’s a pretty short and sweet look at how to automatically change user roles in WooCommerce after purchasing a product. You just need the WooCommerce Members Only plugin.
Hi,
The option to allow a customer to switch roles for a preset period of time when purchasing a product is exactly what we need. But how can I solve this with the existing customers. Is there a possibility to give this a deadline as well?
Hi – this plugin doesn’t allow users to switch roles; it just allows you to assign a new role to any customer (whatever their existing role) when they purchase a product. You can define how long this role will be assigned for if you wish.
Thanks.
But how can I solve this with the existing customers. Is there a possibility to give this a deadline as well?
Hi
It’s not possible to set this parameter for existing customers without some custom code. I could recommend some developers who would be able to help with this if you liked?
Thanks.
What happens to the users role when their paid role expires? Can we set their membership to revert to a certain role after expiration of the premium role?
When a user role expires, it’s deleted from the user. You can then use the following snippet to apply another role if you wish: https://pluginrepublic.com/documentation/add-new-user-role-when-existing-role-expires/.
Thanks
Gareth
Hi, Cool plugin!
Question: Is the user role added after the order is placed or after the customer has succesfully paid (e.g. order on status processing)?
If 1, how can we get it tot work with 2 (e.g.) paid order / status processing?)
As this would be crucial for our use case.
Hi
There’s an option to set this to trigger either on Order Processing or Order Complete.
Thanks.
Thank for your reply!
Hi, I’m using User Role Editor Pro plugin to create roles, and then to manage displaying pages according to them.
Will Members Only be able to choose between roles and to assign one within roles that have been created using User Role Editor Pro to a new customer in Woocommerce checking process ?
Thanks.
Hi
Yes, Members Only will be able to work with roles created using User Role Editor Pro.
Thanks.
That’s fine ! Thanks for your quick reply.
I like the design of your page !
Sincerely.
Hello,
This is almost exactly what I need. If this plugin is used to update a user role when they purchase a “subscription” product, will the role be removed if they cancel the subscription?
Thanks!
Hi
Yes, the role is removed when the subscription is cancelled.
Thanks.
Hi,
When used with WooCommerce Subscriptions, do you set an expiry date for the role for the same length of the subscription, or do you just let the subscription expire/get cancelled and thus have the role removed?
Regards
Mark
Hi Mark
You can set an expiry date for the length of the subscription or you can set it for the roles to be remove when the subscription is cancelled.
Thanks.
Hello,
I have the same question, but I am not certain about the answer you gave…
I have the WooCommerce Subscriptions add-on as well as the WooCommerce Memberships add-on. These two work fine together.
However…
What I need is this:
When a user purchases a WooCommerce Subscription, that user should automatically be assigned a specific user role.
– AND –
When the WooCommerce Subscription ends (either because it expires, or because it is cancelled manually), that user role should be removed from that user account.
Can your Members Only plugin handle this situation?
Hi Rob
Yes, with Members Only, when a user purchases a WC Subscriptions product, the user can be automatically assigned a specific user role. This role will be removed from the user account when the subscription ends.
Thanks.
Hello Gareth,
Wow, that was fast! Thank you so much!
One more question… although I have a suspicion that this is not possible, in which case I would like to make this a feature request for a future version.
Besides WC Subscriptions and WC Memberships, I also have the addon Teams for WooCommerce Memberships.
Ideally I would like to be able to assign a “role” to a team, so that all team members automatically have this role. When the subscriptions ends, or when a member of the team leaves, he would loose this role.
Is that possible?
Hi Rob
Teams are not currently supported by Members Only. We’ll log this as a feature request.
Thanks.
Hello and thank you for your very complete plugin, but I have a question.
My site will offer 2 subscription products.
The first one is an annual subscription, renewable.
The second one is a monthly subscription that can be stopped at any time by the customer (no commitment), but the access to the current month remains until the end of the period.
In case of renewal via a subscription system in woocommerce, will the 2 products automatically be renewed for “one year” or “one month” respectively without interruption?
Hi Benjamin
You’d need the WooCommerce Subscriptions plugin to create your subscription products. One can be set to renew yearly, the other can be set to renew monthly. Then you can use Members Only to assign a role to a user who purchases one of the subscriptions. This role will grant them access to certain products until their subscription expires.
Please let me know if you need any more information.
Thanks.