Shop Manager only list users

WooCommerce built-in role “Shop Manager” (shop_manager) by default can see the list of users and edit/delete users with ‘Customer’ role. What if you wish that shop manager can only see the list of users, but can not edit/delete them?

Shop Manager can not edit user
Shop Manager can not edit user

Direct step is open ‘shop_manager’ role in User Role Editor and revoke ‘edit_users’ and ‘delete_users’ capabilities from it. But you will see that this role has the only ‘list_users’ capability in the “Users” group:

Shop Manager list users capability
Shop Manager list users capability

What’s the mess? How such role can edit users with ‘Customer’ role? WooCommerce adds to shop_manager permissions to edit users the fly (got from the woocommerce/includes/wc-user-functions.php, version 6.4.1):

WooCommerce allows shop manager to edit customer user
WooCommerce allows shop manager to edit customer user

Really shop_manager can edit only users with ‘customer’ role. WooCommerce manage this using this code:

shop manager can edit customers only
Shop manager can edit customers only

shop manager can edit customers only
Shop manager can edit customers only

As you can see from lines 505 and 543 WooCommerce allows to change this via woocommerce_shop_manager_editable_roles filter. So returning to our prime purpose – prohibit to Shop Manager edit users, we can use this code:

add_filter('woocommerce_shop_manager_editable_roles', 'shop_manager_read_only', 10, 1);

function shop_manager_read_only( $roles ) {
    return array();
}

Just place it to the end of the active theme functions.php file or put on the site as a Must Use plugin. Shop Manager will can not edit users with customer role as a result.

Share