8

I want the role Editor to have access to all woocommerce management, I managed to do so by adding capabilities to this role:

    $role = get_role( 'editor' );
    $role->add_cap( 'manage_woocommerce_products' );
    $role->add_cap( 'manage_woocommerce_taxonomies' );
    $role->add_cap( 'manage_woocommerce_orders' );
    $role->add_cap( 'manage_woocommerce' );
    $role->add_cap( 'view_woocommerce_reports' );
    $role->add_cap( 'manage_woocommerce_coupons' );

    $role->add_cap( 'edit_product' );
    $role->add_cap( 'read_product' );
    $role->add_cap( 'delete_product' );
    $role->add_cap( 'edit_products' );
    $role->add_cap( 'publish_products' );
    $role->add_cap( 'read_private_products' );
    $role->add_cap( 'delete_products' );
    $role->add_cap( 'delete_private_products' );
    $role->add_cap( 'delete_published_products' );
    $role->add_cap( 'edit_private_products' );
    $role->add_cap( 'edit_published_products' );
    $role->add_cap( 'edit_products' );

Every thing seems to work ok except the products categories and tags, I have been searching but nothing, i guess there has to be a capability for it but I don't know which one, Hope some expert can guide me a bit on this.

Thanks a lot.

user2957058
  • 270
  • 5
  • 16

3 Answers3

6

You can also do this programmatically like you were trying to, however there are several more roles you must grant for it to work.

I found this out by querying the Woocommerce Shop Manager role, and comparing the capabilities with the editor role.

Here's the code to add the whole lot (at time of writing):

    //add caps to editor role
    $role = get_role("editor");

    //for woocommerce
    $role->add_cap("manage_woocommerce");
    $role->add_cap("view_woocommerce_reports");
    $role->add_cap("edit_product");
    $role->add_cap("read_product");
    $role->add_cap("delete_product");
    $role->add_cap("edit_products");
    $role->add_cap("edit_others_products");
    $role->add_cap("publish_products");
    $role->add_cap("read_private_products");
    $role->add_cap("delete_products");
    $role->add_cap("delete_private_products");
    $role->add_cap("delete_published_products");
    $role->add_cap("delete_others_products");
    $role->add_cap("edit_private_products");
    $role->add_cap("edit_published_products");
    $role->add_cap("manage_product_terms");
    $role->add_cap("edit_product_terms");
    $role->add_cap("delete_product_terms");
    $role->add_cap("assign_product_terms");
    $role->add_cap("edit_shop_order");
    $role->add_cap("read_shop_order");
    $role->add_cap("delete_shop_order");
    $role->add_cap("edit_shop_orders");
    $role->add_cap("edit_others_shop_orders");
    $role->add_cap("publish_shop_orders");
    $role->add_cap("read_private_shop_orders");
    $role->add_cap("delete_shop_orders");
    $role->add_cap("delete_private_shop_orders");
    $role->add_cap("delete_published_shop_orders");
    $role->add_cap("delete_others_shop_orders");
    $role->add_cap("edit_private_shop_orders");
    $role->add_cap("edit_published_shop_orders");
    $role->add_cap("manage_shop_order_terms");
    $role->add_cap("edit_shop_order_terms");
    $role->add_cap("delete_shop_order_terms");
    $role->add_cap("assign_shop_order_terms");
    $role->add_cap("edit_shop_coupon");
    $role->add_cap("read_shop_coupon");
    $role->add_cap("delete_shop_coupon");
    $role->add_cap("edit_shop_coupons");
    $role->add_cap("edit_others_shop_coupons");
    $role->add_cap("publish_shop_coupons");
    $role->add_cap("read_private_shop_coupons");
    $role->add_cap("delete_shop_coupons");
    $role->add_cap("delete_private_shop_coupons");
    $role->add_cap("delete_published_shop_coupons");
    $role->add_cap("delete_others_shop_coupons");
    $role->add_cap("edit_private_shop_coupons");
    $role->add_cap("edit_published_shop_coupons");
    $role->add_cap("manage_shop_coupon_terms");
    $role->add_cap("edit_shop_coupon_terms");
    $role->add_cap("delete_shop_coupon_terms");
    $role->add_cap("assign_shop_coupon_terms");
    $role->add_cap("edit_shop_webhook");
    $role->add_cap("read_shop_webhook");
    $role->add_cap("delete_shop_webhook");
    $role->add_cap("edit_shop_webhooks");
    $role->add_cap("edit_others_shop_webhooks");
    $role->add_cap("publish_shop_webhooks");
    $role->add_cap("read_private_shop_webhooks");
    $role->add_cap("delete_shop_webhooks");
    $role->add_cap("delete_private_shop_webhooks");
    $role->add_cap("delete_published_shop_webhooks");
    $role->add_cap("delete_others_shop_webhooks");
    $role->add_cap("edit_private_shop_webhooks");
    $role->add_cap("edit_published_shop_webhooks");
    $role->add_cap("manage_shop_webhook_terms");
    $role->add_cap("edit_shop_webhook_terms");
    $role->add_cap("delete_shop_webhook_terms");
    $role->add_cap("assign_shop_webhook_terms");

Note that this will add FULL capabilities in woocommerce for all editors.

To check that you don't need additional roles, compare these with the capabilities granted to the shop manager role like so:

    $role = get_role("shop_manager");
    print_r($role->capabilities);
totallyNotLizards
  • 8,489
  • 9
  • 51
  • 85
  • What about duplicating products? Where did u find this list? – Patrick Aug 27 '17 at 06:13
  • @PortalP if you run the code at the end of the answer you'll get a list of the capabilities for the shop_manager role, which is where I got the info from. Not sure if there's a separate role for duplicating products. – totallyNotLizards Aug 28 '17 at 11:10
5

if you read this, you can see that woocommerce recommend two plugins to work, try: this or this

Or try adding this capabilities

  1. manage_product_terms
  2. edit_product_terms
  3. delete_product_terms
  4. assign_product_terms
  5. manage_categories
Mauro
  • 1,472
  • 12
  • 22
1

Sorry, I'm a little late to the party. I wanted to share this snippet for debugging user roles, it has helped me greatly.

add_action( 'admin_notices', 'debug_user_roles' );
function debug_user_roles() {
  global $pagenow;
  if( $pagenow == 'index.php' ) {
    $MYrole = get_role("seo_specialist");
    echo '<pre>';
    print_r($MYrole->capabilities);
    echo '</pre>';

    $MY_other_role = get_role("shop_manager");
    echo '<pre>';
    print_r($MY_other_role->capabilities);
    echo '</pre>';

  }
}

This will display the capabilities of user roles on the wp-dashboard, you could also add something like if current_user_can('administrator') if you need to

RobBenz
  • 589
  • 1
  • 7
  • 21