1

well, I'm using woo-commerce plugin to manage a shop. I need to add a user who can manage products(add new, edit). so I added a user and gave him a shop manager role, but the permissions granted for this role is much more than what I wanted (e.g. listing other users, accessing orders, being able to change shop's setting and ...).

And I can't figure out how WordPress is managing roles and permissions and in which PHP file woo-commerce is defining this role so that I can edit it.

2
  • 1
    This is treading the line of "Off-Topic" since it does deal with Third Party Plugins ( WooCommerce ) but the core of your question deals with user permissions. I suggest Editing your question to be more ask the more specific question of "How do I change permission of a specific role" so that the question does not get closed. Another fine option is to search this site for managing user permissions.
    – Howdy_McGee
    Commented May 5, 2015 at 19:42
  • 1
    @Howdy_McGee I see how you mean this is off topic but I found a tag for woocommerce and just thought related questions are on topic,
    – azerafati
    Commented May 6, 2015 at 20:30

2 Answers 2

4

This is treading very close to being off-topic as it asks specifically about a particular plugin, but the answer is quite generic:

You can remove the capabilities you don't need.

function remove_cap_wpse_186316(){   
  remove_cap( 'yourwoorole', 'yourwoocap' );
  remove_cap( 'yourwoorole', 'yourwoocap1' );
}
add_action( 'admin_init', 'remove_cap_wpse_186316' );

The above is code is for demonstration/experimentation only. Note the note in the codex about this needing to only run once:

Note: This setting is saved to the database (in table wp_options, field 'wp_user_roles'), so you should run this only once, on theme/plugin activation and/or deactivation.

You can use get_role() and dump the output to see what capabilities you are dealing with:

var_dump(get_role( 'yourwoorole' ));
2

Please add the following code to the functions.php of your wordpress theme. And change the true to false for the following you don't need to provide access for shopmanger.

 add_role('shop_manager', __('Shop Manager', 'woocommerce'), array(
    
    'read' => true,
    
    'read_private_pages'    => true,
    
    'read_private_posts'    => true,
    
    'edit_posts' => true,
    
    'edit_pages' => true,
    
    'edit_published_posts'  => true,
    
    'edit_published_pages'  => true,
    
    'edit_private_pages'    => true,
    
    'edit_private_posts'    => true,
    
    'edit_others_posts' => true,
    
    'edit_others_pages' => true,
    
    'publish_posts' => true,
    
    'publish_pages' => true,
    
    'delete_posts' => true,
    
    'delete_pages' => true,
    
    'delete_private_pages'  => true,
    
    'delete_private_posts'  => true,
    
    'delete_published_pages'    => true,
    
    'delete_published_posts'    => true,
    
    'delete_others_posts' => true,
    
    'delete_others_pages' => true,
    
    'manage_categories' => true,
    
    'manage_links'  => true,
    
    'moderate_comments' => true,
    
    'unfiltered_html'   => true,
    
    ‘upload_files’  => true,
    
    ‘export’    => true,
    
    ‘import’    => true,
    
    ‘manage_woocommerce’    => true,
    
    'manage_woocommerce_orders' => true,
    
    'manage_woocommerce_coupons'    => true,
    
    'manage_woocommerce_products'   => true,
    
    'view_woocommerce_reports'  => true
    
    ));
1
  • please dont use curly quotes in code
    – 111
    Commented Jul 16, 2021 at 22:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.