How to Hide Dashboard on the My Account Page WooCommerce

Hide Dashboard on the My Account Page WooCommerce

Do you want to hide the Dashboard section on the WooCommerce ‘My Account’ page? If yes, then you are in the right place.

In this tutorial, you will see how it is very easy to hide this section using a custom PHP code snippet.

 WooCommerce My Account Page

The ‘My Account’ page is really important because it’s where the important information of your users and customers will be stored.

Moreover, it is where your customers can manage their accounts, and add billing details, addresses, etc., for your use.

However, I highly recommend that you customize this section so that you can impress your registered users and let go of more business possibilities with them.

Hide Dashboard on the My Account Page WooCommerce

WooCommerce is a very powerful eCommerce plugin, and this platform is very flexible for customization.

However, it offers a basic account page for your users and customers.

The features and options provided by the default ‘My Account’ page from WooCommerce are very limited.

This means that there are times when you may want to remove a section from this page.

Here is how the default WooCommerce My Account Page is displayed:

WooCommerce My Account page

With all that said, let us look at how you can hide the Dashboard on the ‘My Account page

Steps to Hide Dashboard on the My Account Page

Here are the steps that you need to follow:

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file to hide the Dashboard from the My Account Page
  3. Add the following code in the functions.php file:
/**

 * @snippet       Hide Dashboard on the My Account Page

  */

add_filter( 'woocommerce_account_menu_items', 'njengah_remove_my_account_dashboard' );

function njengah_remove_my_account_dashboard( $menu_links ){

            unset( $menu_links['dashboard'] );

            return $menu_links;

 }

Steps to Detect the Dashboard Page and Redirect to the Orders

The next step is to detect the dashboard page and redirect to the orders. The code above only removes the Dashboard menu link from the account menu.

However, when a customer signs in to the website, he will land on the Dashboard page!

The wp_get_page_permalink( 'myaccount' ) the function used in your theme files also sends users to the Dashboard page.

Therefore, it is not enough to redirect users after login, and we should redirect customers every time they are trying to access the Dashboard.

Here are the steps that you need to follow:

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on Appearance Menu > Theme Editor Menu.
  3. When the Theme Editor page is opened, look for the theme functions file to detect the dashboard page and redirect to the orders.
  4. Add the following code in the functions.php file:
/**

* @snippet       Detect the Dashboard Page and Redirect to the Orders

*/

add_action('template_redirect', 'njengah_redirect_to_orders_from_dashboard' );

function njengah_redirect_to_orders_from_dashboard(){

if( is_account_page() && empty( WC()->query->get_current_endpoint() ) ){

wp_safe_redirect( wc_get_account_endpoint_url( 'orders' ) );

exit;

}

}
  1. This will be the outcome:WooCommerce hide the dashboard on the My Account page

How the Code Works

In the code snippet above, I have used the wc_get_account_endpoint_url() function to get the URL of the Orders page.

It is not enough to use the is_account_page() function because it returns true on every account page, so it is easy to end up with an endless redirect.

Additionally, you should note that the Dashboard page is the only page among the account pages, which does not have an endpoint.

Conclusion

In this post, you have seen how it is very easy to hide the Dashboard on the My Account page. However, the first code snippet only removes the Dashboard menu link from the account menu. Therefore, you need to add the second code snippet to detect the dashboard page and redirect to the orders. This is because when a customer signs in to the website, he will land on the Dashboard page if you do not redirect them. To customize this page further, I recommend using a plugin or hiring a WordPress developer.

Similar Articles