【发布时间】:2020-07-31 12:43:45
【问题描述】:
我希望特定用户只看到 WooCommerce -> 设置 -> 运输菜单。我设法删除了其他标签,例如产品、付款等,但坚持以下两件我想要完成的事情:
- 删除 WooCommerce 设置中的“常规”选项卡。
- 从插件中删除“订单状态”选项卡。 (注意:这不是一个标签,蛞蝓是 'edit.php?post_type=wc_order_status')
当我尝试删除常规选项卡时,它会删除整个设置菜单。至于“订单状态”,我的代码不起作用。
add_filter( 'woocommerce_settings_tabs_array', 'remove_woocommerce_setting_tabs', 200, 1 );
function remove_woocommerce_setting_tabs( $array ) {
global $current_user;
//Declare the tabs we want to hide
$tabs_to_hide = array(
'general' => 'General', //this one removes the entire Settings menu
'wc_order_status' => 'Order Statuses'// this doesn't work, maybe bc it's a post_type
);
// Remove tab if user role is shipping_manager
if ( in_array("shipping_manager", $$current_user->roles) ) {
$array = array_diff_key($array, $tabs_to_hide);
}
}
我还尝试了以下代码来删除“订单状态”选项卡,但仍然没有成功:
add_action( 'admin_menu', 'remove_order_statuses_tab', 999);
function remove_order_statuses_tab()
{
global $current_user;
if ( in_array("shipping_manager", $current_user->roles) ) {
remove_menu_page( 'edit.php?post_type=wc_order_status' ); //not working either
}
}
【问题讨论】:
-
抱歉耽搁了。所以它并没有一直起作用,并且不确定是否将其标记为整个问题的答案。现在回应所有的 cmets。
标签: php wordpress woocommerce settings hook-woocommerce