views:

17

answers:

1

I'm trying to grant a specific role to users that order an amount equal or greater than 100.00 €: Conditional Actions is going really near the achievement, but I'm failing on the action (PHP required).

How can I grant a role using a PHP action in Ubercart Conditional Actions?

+2  A: 

Based on a couple of related threads, I think you want to add an "Execute custom PHP code" action along the lines of the following (substituting in the appropriate role name in line #3):

if($account) {
  $uid = $account->uid;
  $role_name = 'YOUR SPECIFIC ROLE NAME GOES HERE';
  $rid = db_result(db_query("SELECT rid FROM {role} WHERE name = '%s'", $role_name));

  // Load user object
  $account = user_load(array('uid' => 1));

  // Save the user object with the new roles.
  if ($account !== FALSE) {
    $roles = $account->roles + array($rid => $role_name);
    user_save($account, array('roles' => $roles));

  watchdog('user', 'uc ca added role to Ubercart created user');
Matt V.