如何允许角色编辑器管理 worpdress 中的 woocommerce 分类法?

use*_*058 7 php wordpress backend capability woocommerce

我希望角色编辑器可以访问所有 woocommerce 管理,我通过向该角色添加功能来实现:

    $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' );
Run Code Online (Sandbox Code Playgroud)

除了产品类别和标签之外,所有东西似乎都可以正常工作,我一直在搜索但什么也没有,我想必须有它的功能,但我不知道是哪一个,希望有专家可以指导我一下。

非常感谢。

tot*_*rds 6

您也可以像您尝试的那样以编程方式执行此操作,但是您必须授予更多角色才能使其工作。

我通过查询 Woocommerce Shop Manager 角色并将功能与编辑者角色进行比较发现了这一点。

这是添加全部内容的代码(在撰写本文时):

    //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");
Run Code Online (Sandbox Code Playgroud)

请注意,这将为所有编辑者添加 woocommerce 的完整功能。

要检查您是否不需要其他角色,请将这些角色与授予商店经理角色的功能进行比较,如下所示:

    $role = get_role("shop_manager");
    print_r($role->capabilities);
Run Code Online (Sandbox Code Playgroud)


Mau*_*uro 5

如果您阅读本文,您可以看到 woocommerce 推荐两个插件工作,请尝试:thisthis

或尝试添加此功能

  1. manage_product_terms
  2. edit_product_terms
  3. delete_product_terms
  4. assign_product_terms
  5. manage_categories