I installed and configure Drupal commerce successfully in Drupal 8 and now I want to change the role of a user when he/her purchase a product. E.g I have a product type test and user role paid now when the test user purchase a product I want to assign the paid role to this user after successful purchase.

I did this in Drupal 7 via rules module but how in Drupal 8.

3 Answers 3


For Drupal Commerce on Drupal 8, Rules is not complete or integrated. This leaves many such tasks like this for custom development. Fortunately, it's also easier to alter individual parts of the Commerce system thanks to Drupal 8's object oriented architecture. In this case, you'd write a new class called an event subscriber to assign that user role on the "placed" transition - the point at time an order completes checkout or is placed by an administrator. It should then handle assigning the user role to the order owner.

There may be contributed modules available for Rules integration to support individual tasks like this, but it hasn't been a core priority as of yet while we focus on other major feature groups (e.g. shipping, addressbook, recurring billing, etc.).


Commerce license provides this feature out of the box. From readme.txt :

The Commerce License allows the creation of products that sell access to some aspect of the site. This could be a role, publication of a node, and so on.

This access is controlled by a License entity, which is created for the user when the product is purchased.

The nature of what a License entity grants is handled by License type plugins.

The modules ships with a Role plugin.


To create products that grant a role when purchased :

  1. Configure a checkout flow which does not allow anonymous checkout.
  2. Configure an Order Type to use this checkout flow.
  3. Configure an Order Item Type to use this Order Type, and work with Licenses.
  4. Configure a Product Variation Type to use this Order Item Type, and provide Licenses.
  5. Configure a Product Type that uses this Product Variation Type.
  6. Create one or more products that provide licenses. In the product variation, configure the license type to use the Role license type provided by the plugin

And that's it ! Additionally this almost smoothly integrates with recurring subscriptions.


Ryan Szrama has a good answer. This may require a custom module to get it to do what you want since Rules is no longer a part of Drupal 8, 9 or 10. There are no modules that do this either.

Commerce License does not work here since that is more for subscription variation types that will require expiration/renewal.

If your store sells digital files for example, that is also managed by commerce license and does not allow both a role license and a file license on the same product variation and will not manage both.

Therefore the best solution is a simple custom module that on commerce order being marked completed to a registered user, assign user role X to buyer. If guest checkout (anonymous user) ignore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.