【问题标题】:Add alternate customer role to WordPress / WooCommerce将备用客户角色添加到 WordPress / WooCommerce
【发布时间】:2020-10-07 16:34:42
【问题描述】:

我正在尝试向 WordPress 和 WooCommerce 添加另一个客户角色。当用户登录时,我将使用这个新的客户角色来分配替代价格。我的代码有效,但我无法找到客户在 WordPress/WooCommerce 中默认拥有的权限。我希望这个新角色具有与默认客户帐户相同的权限。下面的代码位于我的子functions.php文件中。

/* Custom user roles */
add_role('distributor', __(
   'Distributor'),
   array(
       'read'            => true, // Allows a user to read
       'create_posts'      => true, // Allows user to create new posts
       'edit_posts'        => true, // Allows user to edit their own posts
       'edit_others_posts' => true, // Allows user to edit others posts too
       'publish_posts' => true, // Allows the user to publish posts
       'manage_categories' => true, // Allows user to manage post categories
       )
);

【问题讨论】:

    标签: wordpress woocommerce


    【解决方案1】:

    当您使用 wordpress 的add_role() 函数创建新用户角色时,您可以使用另一个角色的能力并将其用作“能力数组”。我假设您希望复制功能的角色称为customer。你可以调整这个。

    add_role( 'distributor', 'Distributor', get_role( 'customer' )->capabilities );
    

    该函数接受一系列功能。使用get_role(),您可以获得一个角色对象并访问该角色的功能。

    因此我们创建了一个具有现有角色功能的新角色。

    【讨论】:

      猜你喜欢
      • 2017-02-17
      • 2019-01-17
      • 2015-01-05
      • 1970-01-01
      • 1970-01-01
      • 2021-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多