How to let role editor manage woocommerce taxonomy in worpdress?

I want the editor to have access to all woocommerce management, I succeeded by adding features for 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' );

Everything seems to be working fine, with the exception of product categories and tags, I searched, but nothing, I think there is an opportunity for this, but I don’t know which one, I hope some expert can help me a little on this .

Many thanks.

+4
source share
3 answers

this, , woocommerce , : this this

  • manage_product_terms
  • edit_product_terms
  • delete_product_terms
  • assign_product_terms
  • manage_categories
+3

, , , .

, Woocommerce .

( ):

    //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");

, FULL- woocommerce .

, , , :

    $role = get_role("shop_manager");
    print_r($role->capabilities);
0

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

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 show the capabilities of custom roles in the wp control panel, you can also add something like if current_user_can('administrator')if you need

0
source

Source: https://habr.com/ru/post/1570306/


All Articles