我如何在 Ubercart 中授予特定角色?

发布于 2024-09-15 11:22:45 字数 113 浏览 5 评论 0原文

我正在尝试向订购金额等于或大于 100.00 欧元的用户授予特定角色:条件操作非常接近成就,但我在该操作上失败了(需要 PHP)。

如何在 Ubercart 条件操作中使用 PHP 操作授予角色?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深海少女心 2024-09-22 11:22:45

基于一些相关 线程,我认为您想要添加一个“执行自定义 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');

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');
伊面 2024-09-22 11:22:45

提供的代码需要关闭两个括号。我删除了 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');

Code provided needs to close two brackets. I dropped the if statements, grabbed the uid from the order and fixed the uid setting (it was '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');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文