1

I made a site that sells services in Commerce 2. I want to hide access to the "Orders" and "Payment info" pages until a user purchases the first product.

To do this, I created a role, Paid, for users who have purchased something. This role has permission to view orders and so forth.

Which hook should I use to give the user the Paid role after making a purchase?

3

In Drupal 8 Commerce is using Event dispatcher instead of hooks.

In this case, you should subscribe into the event named commerce_order.order.assign, the hook invoked then a order is assigned to a user. In this moment you can code to grant the role to the user. You can see an example of how commerce_log submodule from commerce used this event here.

If you need, you have this tutorial which tells you how to subscribe to a event from event dispatcher.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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