2

Using the most recent version of WooCommerce, there's a "Home" section that I cannot remove using any built in setting.

I have managed to remove the analytics and marketing option, but how do I remove the "Home" option and that way, make it like it always was before -- an overview of all orders?

add_filter( 'woocommerce_admin_get_feature_config', 'remove_wc_marketing_menu_option', 10, 1 );
function remove_wc_marketing_menu_option($feature_config){   
$feature_config['marketing'] = false;
$feature_config['analytics'] = false;
return $feature_config;
}
7uc1f3r
  • 28,449
  • 17
  • 32
  • 50
Tina York
  • 63
  • 4

1 Answers1

5

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:

7uc1f3r
  • 28,449
  • 17
  • 32
  • 50