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: