Drupal :: order a full hook and update user permissions / roles

I want to be able to update the user's permission after the order status is completed.

I realized that for this you need to use hook_order hook. But how do you know which user created this order, and how to proceed to update permissions, and also automatically set the expiration time of this role.

I want this hook to be called as soon as the payment is made and the order is completed.

Any pointers would be helpful.

+4
source share
1 answer

3 parameters are passed to hook_order . The third parameter depends on the first. When the first parameter is "update", the third parameter is the status the order goes to.

 hook_order($op, &$order, $arg2){ switch($op){ case 'update': if($arg2 === 'completed'){ // This order got marked completed } } } 

$order->uid will provide you with the user who created the order. You can do something like the following

 $user = user_load(array('uid' => $order->uid)); // update the roles assigned to user user_save($user); 

To expire the role, you will need to write a module that will track the duration and will do something like above when the time runs out. Or you can use the role_expire module and see if that helps.

+3
source

Source: https://habr.com/ru/post/1316001/


All Articles