我正在尝试向订购金额等于或大于100.00€的用户授予特定角色:条件操作非常接近成就,但我没有采取行动(需要PHP)。
如何在Ubercart条件操作中使用PHP操作授予角色?
答案 0 :(得分:3)
基于几个related threads,我认为您希望按照以下方式添加“执行自定义PHP代码”操作(替换为第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');
答案 1 :(得分:3)
提供的代码需要关闭两个括号。我删除了if
语句,从命令中抓取了uid并修复了uid设置(它为'1'):
$uid = $order->uid;
$role_name = 'customer';
$rid = db_result(db_query("SELECT rid FROM {role} WHERE name = '%s'", $role_name));
// Load user object
$account = user_load(array('uid' => $uid));
// Save the user object with the new roles.
$roles = $account->roles + array($rid => $role_name);
user_save($account, array('roles' => $roles));
watchdog('user', 'uc ca added role to Ubercart created user');