Automatically update user roles after purchasing a product in WooCommerce

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.

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

WooCommerce Members Only

Create a membership site by restricting access to your content and selling members only products

Find Out More

For more information about WooCommerce user roles, please see this article.

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 the steps below.

Simple products

This method works well if you want to have a different product for each membership level.

  1. Edit the product
  2. Click the ‘Members Only’ tab
  3. Enter the user roles that will be assigned to the customer after they purchase the product
Assign user role after purchasing product

Now, whenever a customer purchases that product, they will be assigned the additional role(s) you’ve specified.

Variable products

This option might be neater if you have multiple membership levels that you want to be purchased from the same product.

  1. Edit the variable prodcut
  2. Click on ‘Variations’
  3. Enter the user role that will be assigned when the user purchases the product
Assign roles after user purchases a variation

Removing the user role after specified time period

If you’re using user roles as part of your membership site, you might want to limit the period that a membership is active for. To do this, you can set an expiry date for user roles that are automatically assigned when a user purchases a product.

You can do this for simple and variable products. The screenshot below is from a simple product. To find the same setting for a variable product, just click on the Variations tab.

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.

WooCommerce disable guest checkout

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 automatically create account new user

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:

  1. Go to WooCommerce > Settings > Members Only > User Roles
  2. In the ‘User roles’ field, select a user role to duplicate
  3. Enter the name of the new role in the ‘New role name’ field
  4. Click the ‘Duplicate role’ button
WooCommerce create new user role

To edit the new role:

  1. Select the user role to edit from the ‘User roles’ field in the ‘Edit Role’ section
  2. A list of capabilities will be displayed. Select or deselect capabilities for the role as required
  3. Click ‘Update Role’
WooCommerce edit user role

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 set user roles in WooCommerce after purchasing a product. You just need the WooCommerce Members Only plugin.

WooCommerce Members Only

Create a membership site by restricting access to your content and selling members only products

Find Out More

16 comments

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

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

  2. 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?

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

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

  5. 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!

Leave a Reply

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