You could use remove_submenu_page
function action_admin_menu() {
// Contains the URI of the current page.
$current_url = $_SERVER['REQUEST_URI'];
// Make sure wc-admin / customers page will still work
if ( strpos( $current_url, 'customers' ) == false) {
remove_submenu_page( 'woocommerce', 'wc-admin' );
}
}
add_action( 'admin_menu', 'action_admin_menu', 99, 0 );
EDIT: after newer versions of WooCommerce has been released in the meantime, there appeared to be an issue with the above answer when accessing certain pages, this can be solved by using:
function strposa( string $haystack, array $needles, int $offset = 0 ) : bool {
foreach ( $needles as $needle ) {
if ( strpos( $haystack, $needle, $offset ) !== false ) {
return false; // stop on first true result
}
}
return true;
}
function action_admin_menu() {
// Contains the URI of the current page.
$current_url = $_SERVER['REQUEST_URI'];
// Pages that must remain accessible
$should_still_work = array( 'customers', 'analytics', 'marketing' );
// Make sure some wc-admin pages will still work
if ( strposa( $current_url, $should_still_work ) ) {
remove_submenu_page( 'woocommerce', 'wc-admin' );
}
}
add_action( 'admin_menu', 'action_admin_menu', 99, 0 );
Used in this updated answer: Using an array as needles in strpos
Related: