我正在尝试向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
)
);
答案 0 :(得分:2)
当您使用wordpress的add_role()
功能创建新的用户角色时,可以使用另一个角色的功能并将其用作“功能数组”。我假设您要复制功能的角色称为customer
。您可以对此进行调整。
add_role( 'distributor', 'Distributor', get_role( 'customer' )->capabilities );
该函数接受一系列功能。使用get_role()
,您将获得一个角色对象并访问该角色的功能。
因此,我们创建了一个具有现有角色功能的新角色。