• Resolved Howdy_McGee

    (@howdy_mcgee)


    Hello,

    I have a strange scenario…

    I’ve installed the User Role Editor and have given the Shop Manager the 6 User Capabilities: Create, Delete, Edit, List, Promote, Remove. This allows the Shop Manager role to manage users. This does work as expected for the built-in WordPress types.

    The problem is that if I add a custom user role, the Shop Manager is no longer able to manage users within that custom role; no editing or deleting options. If I disable WooCommerce, Shop Managers can edit and delete users in custom roles as expected.

    Additionally, if I do the same treatment to the Editor role to manage users, I don’t run into this issue at all. It appears to be related specifically to Shop Manager, WooCommerce, and custom user roles. Any idea why this may be and how I could go about fixing it?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    It sounds like the issue is related to the User Role Editor plugin. We recommend reaching out to the plugin support directly.

    If you are using this User Role Editor plugin, here is the direct link to its support page: https://www.ads-software.com/support/plugin/user-role-editor/

    Thread Starter Howdy_McGee

    (@howdy_mcgee)

    Hello,

    I do not believe this is an issue with the User Role Editor plugin. If I add a custom user role and the user capabilities to the shop_manager through code on a fresh install, I get the same results. This seems like a bug within WooCommerce itself.

    If I do the same thing to the Editor user role, I can manage users as expected. Here’s the code I used to verify the issue as an MU Plugin.

    add_action( 'init', function() {
    	
    	global $wp_roles;
    	
    	if( $wp_roles->is_role( 'foobar' ) ) {
    		return;
    	}
    	
    	add_role( 'foobar', 'FooBar', array(
    		'read' => true,
    	) );
    	
    } );
    
    add_action( 'init', function() {
    	
    	$manager = get_role( 'shop_manager' );
    	
    	if( $manager->has_cap( 'list_users' ) ) {
    		return;
    	}
    	
    	$manager->add_cap( 'create_users', true );
    	$manager->add_cap( 'delete_users', true );
    	$manager->add_cap( 'edit_users', true );
    	$manager->add_cap( 'list_users', true );
    	$manager->add_cap( 'promote_users', true );
    	$manager->add_cap( 'remove_users', true );
    	
    }, 999 );

    The end goal here is really to just allow Shop Managers to manage users in full. List, Create, Read, Edit, Delete.

    Plugin Support Gabriel – a11n

    (@gabrielfuentes)

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    If you do require more help with the actual coding, we’d recommend you hire a developer who can take a look at this, quote you for their services, and help you add this feature to your site. We’d recommend getting in touch with a web developer or one of the customization experts listed at https://woocommerce.com/customizations/.

    Cheers.

    Thread Starter Howdy_McGee

    (@howdy_mcgee)

    Hello,

    Allen Smith from the WooCommerce Slack Channel pointed out a filter hook that solved the issue. The hook is woocommerce_shop_manager_editable_roles.

    /**
     * Add editable (custom) roles to an array
     *
     * @param Array $roles - role slugs
     *
     * @return Array $roles
     */
    add_filter( 'woocommerce_shop_manager_editable_roles', function( $roles ) {
    	return array_merge( $roles, array( 'foobar' ) );
    } );
    Plugin Support Gabriel – a11n

    (@gabrielfuentes)

    That’s wonderful! Glad to know that Allen Smith could help you ??

    Great! If you have any further questions, you can start a new thread.

    Cheers!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Shop Manager Unable to Manage Users with Custom Roles’ is closed to new replies.