1. Home
  2. Knowledge Base
  3. WooCommerce Wholesale Prices Premium
  4. Backend
  5. How To Allow Shop Managers To Edit Users & Wholesale Users In WooCommerce

How To Allow Shop Managers To Edit Users & Wholesale Users In WooCommerce

On WooCommerce version 3.4.6, they released a security fix that prevents shop managers to edit other users except for users with a Customer role.

This means from this version onwards, Shop Managers will not be able to edit Users with the wholesale user roles generated from our WooCommerce Wholesale Prices and Prices Premium plugin by default.

If you want to just let your Shop Managers edit those users, you will need to do two things:

  1. Allow them to edit users
  2. Allow them to edit users with the roles that you say they can

Allow Shop Managers To Edit Users (Customer Role Users Only)

In the first part you just need to adjust the capabilities of the Shop Manager role:

/* Lets Shop Managers be able to edit users again */
function wws_add_shop_manager_user_editing_capability() {
$shop_manager = get_role( 'shop_manager' );
$shop_manager->add_cap( 'edit_users' );
$shop_manager->add_cap( 'edit_user' );
}
add_action( 'admin_init', 'wws_add_shop_manager_user_editing_capability');

Note that the above snippet will not let Shop Managers promote/demote a user, meaning they can’t change the User Role of a customer. Read on for how to do that.

Add The Ability To Edit Users With Wholesale Roles

Next, you need to say which user roles the Shop Managers are allowed to edit. If you don’t do the following, it will mean they can only edit users with Customer roles.

/* Lets Shop Managers edit users with these user roles */
function wws_allow_shop_manager_role_edit_capabilities( $roles ) {
$roles[] = 'wholesale_customer'; // insert the wholesale role here, copy+paste this line for additional user roles
return $roles;
}
add_filter( 'woocommerce_shop_manager_editable_roles', 'wws_allow_shop_manager_role_edit_capabilities' );

If you want to allow your Shop Managers to also be able to promote/demote users from Customer to Wholesale Roles, you will need to explicitly give them that capability. You can do so by editing the top snippet to add the following line:

$shop_manager->add_cap( 'promote_users' );

Please use this snippet to allow shop managers to edit users with the default wholesale_customer roles. If you have additional wholesale roles, you can include them in roles in the snippet, just copy and paste the line and adjust to use the proper role slug.

The Full Code Snippet (Includes Everything Above)

/* Lets Shop Managers have the capability of editing and promoting users */
function wws_add_shop_manager_user_editing_capability() {
$shop_manager = get_role( 'shop_manager' );
$shop_manager->add_cap( 'edit_users' );
$shop_manager->add_cap( 'edit_user' );
$shop_manager->add_cap( 'promote_users' );
}
add_action( 'admin_init', 'wws_add_shop_manager_user_editing_capability');

/* Lets Shop Managers edit users with these user roles */
function wws_allow_shop_manager_role_edit_capabilities( $roles ) {
$roles[] = 'wholesale_customer'; // insert the wholesale role here, copy+paste this line for additional user roles
return $roles;
}
add_filter( 'woocommerce_shop_manager_editable_roles', 'wws_allow_shop_manager_role_edit_capabilities' );

These snippets should be placed in your theme/child theme’s functions.php or in a drop-in or custom plugin.

NOTE: Keep in mind the above snippets change the way security operates for the Shop Manager role in your store. So please be careful and ensure you understand what capabilities you are opening up.

Was this article helpful?

Related Articles