简体   繁体   English

在 WordPress 管理仪表板上的 WooCommerce 中删除“添加订单”的子菜单

[英]Remove submenu for 'Add Order' in WooCommerce on WordPress admin dashboard

My WooCommerce version is 4.5.2.我的 WooCommerce 版本是 4.5.2。

I will like to remove the ' Add order ' for a custom user so that it cannot access wp-admin/post-new.php?post_type=shop_order .我想删除自定义用户的“添加订单”,使其无法访问wp-admin/post-new.php?post_type=shop_order

I have created a custom user using User Role Editor with the following permissions:我使用具有以下权限的用户角色编辑器创建了一个自定义用户:

With this, the user can only view existing orders, and click the order preview to update to 'Completed'.这样,用户只能查看现有订单,并单击订单预览以更新为“已完成”。

I tried using this:我尝试使用这个:

remove_submenu_page( 'edit.php?post_type=shop_order', 'post-new.php?post_type=shop_order');

...but the Order main menu becomes not accessible. ...但订单主菜单变得不可访问。

I came across this post Remove or hide "add new" button on woocommerce on bulk order panel , which hides the 'Add order' from the page using CSS.在批量订单面板上的 woocommerce 上看到了这篇文章删除或隐藏“添加新”按钮,它使用 CSS 从页面中隐藏了“添加订单”。

I wish someone can point me to a direction on how to achieve what I am looking for.我希望有人能指出我如何实现我正在寻找的方向。


UPDATE:更新:

Based on 7uc1f3r's answer, this is my output基于 7uc1f3r 的回答,这是我的输出

[edit.php?post_type=shop_order] => Array
    (
        [5] => Array
            (
                [0] => Orders 
                [1] => edit_shop_orders 
                [2] => edit.php?post_type=shop_order
            )
            
        [10] => Array
            ( 
                [0] => Add order 
                [1] => edit_shop_orders 
                [2] => post-new.php?post_type=shop_order 
            )
    ) 

Using the provided solution, I use this so that the custom user cannot Add order and access wp-admin/post-new.php?post_type=shop_order:使用提供的解决方案,我使用它以便自定义用户无法添加订单和访问 wp-admin/post-new.php?post_type=shop_order:

    unset( $submenu['edit.php?post_type=shop_order'][10][0] );
    unset( $submenu['edit.php?post_type=shop_order'][10][1] );
    unset( $submenu['edit.php?post_type=shop_order'][10][2] );

In addition, I apply CSS to hide the 'Add order' at the admin panel:此外,我应用 CSS 来隐藏管理面板中的“添加订单”:

    ul.wp-submenu.wp-submenu-wrap {
        display: none !important;
    }

It now looks like this:现在看起来像这样:

I'm using WC 4.4.1 & WC 4.6.0 and in both versions there is no possibility to create a new order from the menu.我正在使用WC 4.4.1WC 4.6.0并且在两个版本中都无法从菜单中创建新订单。

UPDATE: Due to the output you posted, this should suffice to remove "Order: add new"更新:由于您发布的输出,这应该足以删除“订单:添加新”

function action_admin_menu() {
    global $menu, $submenu;

    // Unset 'Order: add new'
    unset( $submenu['edit.php?post_type=shop_order'][10] );
}
add_action( 'admin_menu', 'action_admin_menu' );

Optional: For "Products: add new" and DEBUGGING you could use可选:对于“产品:添加新”和调试,您可以使用

// DEBUG: This displays the complete wordpress admin menu on your dashboard for admin only. (Remove afterwards)
function debug_admin_menus() {
    global $menu, $submenu, $pagenow;
    if ( current_user_can('manage_options') ) {
        if( $pagenow == 'index.php' ) {  // print on dashboard
            echo '<pre>', print_r( $menu, 1 ), '</pre>'; // top level menus
            echo '<pre>', print_r( $submenu, 1 ), '</pre>'; // submenus
        }
    }
}
add_action( 'admin_notices', 'debug_admin_menus' );

function action_admin_menu() {
    global $menu, $submenu;

    // Unset 'Products: add new'
    unset( $submenu['edit.php?post_type=product'][10] );
}
add_action( 'admin_menu', 'action_admin_menu' );

Related:有关的:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 删除“主页”并直接转到 WordPress 管理仪表板上的 WooCommerce“订单” - Remove "Home" and go direct to WooCommerce "Orders" on WordPress Admin dashboard Wordpress:更改管理员子菜单顺序 - Wordpress: Change admin submenu order remove_submenu_page(&#39;woocommerce&#39;, &#39;wc-admin&#39;); 功能不删除仪表板 - remove_submenu_page('woocommerce', 'wc-admin'); function not removing dashboard 将子菜单条目添加到 WooCommerce“产品”管理菜单 - Add submenu entry to WooCommerce "Products" admin menu Woocommerce / Wordpress - 在管理面板上添加按钮到订单/产品页面 - Woocommerce / Wordpress - Add button to Order / Product Page on Admin Panel 在 Woocommerce 中删除管理员添加订单的国家/地区计费和运输字段 - Remove country billing and shipping fields on admin add order in Woocommerce 在管理控制台中删除Wordpress评论计数器 - Remove wordpress comments counter in Admin dashboard 在 Wordpress/Woocommerce 管理员订单详细信息中提交表单 - Submitting a Form in Wordpress/Woocommerce admin order details 如何重命名 WordPress 管理仪表板上 WooCommerce 选项卡下的菜单选项卡 - How to rename a menu tab under WooCommerce tab on WordPress admin dashboard 在 WordPress 管理仪表板中更改 WooCommerce 产品菜单标题 - Change WooCommerce products menu title in WordPress admin dashboard
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM