Skip to content

Instantly share code, notes, and snippets.

@webdados
Last active April 14, 2021 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webdados/05ca4e356b36c7d0c77fba8be4a844e3 to your computer and use it in GitHub Desktop.
Save webdados/05ca4e356b36c7d0c77fba8be4a844e3 to your computer and use it in GitHub Desktop.
Orders as the first submenu item on the WooCommerce WP-Admin menu
<?php
add_filter( 'custom_menu_order', 'woocommerce_nav_admin_orders_first' );
function woocommerce_nav_admin_orders_first( $menu_order ) {
if ( is_admin() ) {
global $submenu;
if ( isset( $submenu['woocommerce'] ) && is_array( $submenu['woocommerce'] ) ) {
$temp = array();
//Add orders as first
foreach ( $submenu['woocommerce'] as $submenu_item ) {
if ( isset( $submenu_item[2] ) && $submenu_item[2] == 'edit.php?post_type=shop_order' ) {
$temp[] = $submenu_item;
break;
}
}
//Add the remaining items
foreach ( $submenu['woocommerce'] as $submenu_item ) {
if ( isset( $submenu_item[2] ) && $submenu_item[2] != 'edit.php?post_type=shop_order' ) {
$temp[] = $submenu_item;
}
}
$submenu['woocommerce'] = $temp;
}
}
//We didn't touch the $menu_order variable at all, we just needed to have somewhere to hook into and then
return $menu_order;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment