I need to assign a kind of "premium status" to members that purchase an amount equal or greater than 100 € via PHP.
Conditional Actions are already set up (user = anonymous/authenticated AND total amount = equal/greater than 100 AND user =! premium) but I'm missing the PHP part to actually say "then grant him the premium membership".
How can I achieve this?
EDIT: is the below code correct?
if ($account) {
$uid = $account->uid;
$role_name = 'authenticated user';
$rid = db_result(db_query("SELECT rid FROM {role} WHERE name = '%s'", $role_name));
db_query("INSERT INTO {users_roles} (uid, rid) VALUES(%d, %d)", $uid, $rid);
watchdog('user', 'uc ca added role to Ubercart created user');
}
You can do this with
user_load()
anduser_save()
:If you wanted to do this in bulk for multiple users, there's
user_multiple_role_edit()
:Edit
If you wanted to do this for the current user (like part of the check you mentioned in a comment), you can do:
I'd rather use user_role_load_by_name function.
Just though I'd update the snippet for Drupal 7. Otherwise it works fine :)
for drupal 7:
thanks rix.