Home » WooCommerce: Change Default My Account Tab

WooCommerce: Change Default My Account Tab

by Tutor Aspire

As you know, once you log in and go to My Account, WooCommerce displays the “Dashboard” tab content (also called the Dashboard “endpoint”). The Dashboard tab features the default “Hello Tutor Aspire (not Tutor Aspire? Log out) From your account dashboard you can view your recent orders, manage your shipping and billing addresses, and edit your password and account details.” message.

Now, what if we want to set another My Account tab as the default one upon login, for example the “Orders” one, or the “Downloads” one for a digital downloads WooCommerce business? Well, there are a couple of quick and not-so-quick solutions, enjoy!

With Snippet 2 you find below, I was able to set the “Downloads” tab as the default one when a user lands on the My Account page. Also, the “Dashboard” tab is preserved, unlike the solution offered by Snippet 1.

PHP Snippet 1: Redirect Users to Another My Account Tab

By redirecting to another tab when people visit the “Dashboard” one, we’re simply saying that we wish to hide the whole Dashboard tab content. You will also need to remove the Dashboard tab from the My Account menu.

/**
 * @snippet       Redirect to new default tab @ WooCommerce My Account
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */

add_action( 'template_redirect', 'tutoraspire_my_account_redirect_to_downloads' );

function tutoraspire_my_account_redirect_to_downloads(){
if ( is_account_page() && empty( WC()->query->get_current_endpoint() ) ) {
wp_safe_redirect( wc_get_account_endpoint_url( 'orders' ) );
exit;
}
}

In this case we’ve picked the “orders” tab. You can find other WooCommerce My Account tab IDs by looking at this other post.

PHP Snippet 2: Set Another My Account Tab as Default (But Keep The Dashboard)

You may not want to hide the Dashboard tab at all, and simply set another as the default tab. In this case, we can’t use the redirect snippet, as otherwise the Dashboard will never show.

Unfortunately, as of today, there is no clean solution (even if you reorder My Account tabs, the Dashboard tab content will show on load) – we need to find a workaround.

This workaround:

  1. replaces the “Dashboard” tab content to the tab content of your choice (e.g. “Downloads” tab content)
  2. renames the “Dashboard” tab title to whatever you want (“Downloads” in our example)
  3. hides the original “Downloads” tab as we already have it now
  4. readds the “Dashboard” tab as first tab together with its content

Part 1 – Replace Dashboard tab content with Downloads tab content

Please note woocommerce_account_downloads() is the function responsible to output the Downloads tab. You can find the other tabs’ content in this other tutorial.

/**
 * @snippet       Replace tab content @ WooCommerce My Account
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */

add_action( 'woocommerce_account_content', 'tutoraspire_myaccount_replace_dashboard_content', 1 );

function tutoraspire_myaccount_replace_dashboard_content() {
remove_action( 'woocommerce_account_content', 'woocommerce_account_content', 10 );
add_action( 'woocommerce_account_content', 'tutoraspire_account_content' );
}

function tutoraspire_account_content() {
global $wp;
if ( empty( $query_vars = $wp->query_vars ) || ( ! empty( $query_vars ) && ! empty( $query_vars['pagename'] ) ) ) {
woocommerce_account_downloads();
} else {
foreach ( $wp->query_vars as $key => $value ) {
if ( 'pagename' === $key ) {
continue;
}
if ( has_action( 'woocommerce_account_' . $key . '_endpoint' ) ) {
do_action( 'woocommerce_account_' . $key . '_endpoint', $value );
return;
}
}
}
}

Part 2 – Rename Dashboard tab title to Downloads

/**
 * @snippet       Rename tab @ WooCommerce My Account
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */

add_filter( 'woocommerce_account_menu_items', 'tutoraspire_myaccount_rename_dashboard_tab_title', 9999 );
 
function tutoraspire_myaccount_rename_dashboard_tab_title( $items ) {
   $items['dashboard'] = 'Downloads';
   return $items;
}

Part 3 – Remove original Downloads tab

/**
 * @snippet       Remove tab @ WooCommerce My Account
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */

add_filter( 'woocommerce_account_menu_items', 'tutoraspire_myaccount_remove_orders_tab', 9999 );
 
function tutoraspire_myaccount_remove_orders_tab( $items ) {
   unset( $items['downloads'] );
   return $items;
}

Part 4 – Readd Dashboard tab

Note: you must resave the WordPress permalinks once the snippet is active.

/**
 * @snippet       Readd Dashboard tab @ WooCommerce My Account
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */

add_action( 'init', 'tutoraspire_myaccount_add_dashboard_endpoint' );
  
function tutoraspire_myaccount_add_dashboard_endpoint() {
    add_rewrite_endpoint( 'mydashboard', EP_ROOT | EP_PAGES );
}

add_filter( 'query_vars', 'tutoraspire_query_vars', 0 );
  
function tutoraspire_query_vars( $vars ) {
    $vars[] = 'mydashboard';
    return $vars;
}
  
add_filter( 'woocommerce_account_menu_items', 'tutoraspire_add_new_dashboard_to_my_account' );
  
function tutoraspire_add_new_dashboard_to_my_account( $items ) {
$items = array( 'mydashboard' => 'Dashboard' ) + $items;
    return $items;
}

You may also like