Home > database >  How to hide my-account menu on certain pages in Woocommerce?
How to hide my-account menu on certain pages in Woocommerce?

Time:10-19

When logged in with Woocommerce, is there a way to only render the dashboard menu when on the index page of the logged in "mode"?

I only want to display it on "dashboard". Not on "orders", "downloads", "addresses" or the other pages.

I don't want to do it with CSS.

I have copied the template files, so i'll post the dashboard and orders templates.

dashboard.php

https://github.com/woocommerce/woocommerce/blob/master/templates/myaccount/dashboard.php

orders.php

https://github.com/woocommerce/woocommerce/blob/master/templates/myaccount/downloads.php

CodePudding user response:

Instead of making changes to template files, you can use the woocommerce_account_navigation action hook

So you get:

function action_woocommerce_account_navigation () {
    // Detect the WC Dashboard page, and if NOT
    if ( is_user_logged_in() && is_account_page() && is_wc_endpoint_url() ) {
        // Remove navigation
        remove_action( 'woocommerce_account_navigation', 'woocommerce_account_navigation' );
    }
}
add_action( 'woocommerce_account_navigation', 'action_woocommerce_account_navigation', 1, 0 );
  • Related