Embed Snippet on Your Site
Allow Shop Managers to edit and promote wholesale users.
/**
* Allow Shop Managers to edit and promote wholesale users.
*/
function wws_add_shop_manager_user_editing_capability() {
$shop_manager = get_role('shop_manager');
if ( ! $shop_manager ) {
return;
}
// Only add capabilities if they don't already exist
if ( ! $shop_manager->has_cap('edit_users') ) {
// Core WP + WooCommerce capabilities
$shop_manager->add_cap('list_users');
$shop_manager->add_cap('edit_users');
$shop_manager->add_cap('create_users');
$shop_manager->add_cap('promote_users');
$shop_manager->add_cap('add_users');
}
}
add_action('init', 'wws_add_shop_manager_user_editing_capability');
/**
* Allow Shop Managers to edit wholesale roles.
*/
function wws_allow_shop_manager_wholesale_roles( $roles ) {
$wholesale_roles = array(
'wholesale_customer',
'wholesale_gold',
);
foreach ( $wholesale_roles as $role ) {
// Only add if the role exists in WordPress
if ( get_role( $role ) && ! in_array( $role, $roles, true ) ) {
$roles[] = $role;
}
}
return $roles;
}
add_filter('woocommerce_shop_manager_editable_roles', 'wws_allow_shop_manager_wholesale_roles', 20);
/**
* Some versions of Wholesale Prices Premium use their own editable roles filter.
* Note: This filter may not exist in current versions - keeping for backward compatibility.
*/
function wws_allow_shop_manager_wholesale_roles_wholesale_suite( $roles ) {
$wholesale_roles = array(
'wholesale_customer',
'wholesale_gold',
);
foreach ( $wholesale_roles as $role ) {
// Only add if the role exists in WordPress
if ( get_role( $role ) && ! in_array( $role, $roles, true ) ) {
$roles[] = $role;
}
}
return $roles;
}
add_filter('wwp_shop_manager_editable_roles', 'wws_allow_shop_manager_wholesale_roles_wholesale_suite', 20);
| |
Comments