在WordPress管理仪表板上的WooCommerce中删除“添加订单"子菜单 [英] Remove submenu for 'Add Order' in WooCommerce on WordPress admin dashboard

查看:55
本文介绍了在WordPress管理仪表板上的WooCommerce中删除“添加订单"子菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的WooCommerce版本是4.5.2.

我想为自定义用户删除"添加订单",以使其无法访问 wp-admin/post-new.php?post_type = shop_order .

我已使用用户角色编辑器创建了具有以下权限的自定义用户:

这样,用户只能查看现有订单,然后单击订单预览以更新为已完成".

我尝试使用这个:

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

...但是无法访问订单"主菜单.

我碰到了这篇帖子

  • 如何重命名WordPress管理控制台上WooCommerce标签下的菜单标签

  • My WooCommerce version is 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.

    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.

    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

    [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:

        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:

        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.

    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:

    这篇关于在WordPress管理仪表板上的WooCommerce中删除“添加订单"子菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆