Business Bloomer
  • WooCommerce Tips
  • WooCommerce Plugins
  • WooCommerce Courses
  • Login
  • 0
  • WooCommerce Tips
  • WooCommerce Plugins
  • WooCommerce Courses
  • Login
  • 0

WooCommerce: Change Default My Account Tab

> Published: Aug 2022
> Blog Category: WooCommerce Tips
> Blog Tags: My Account
> Blog Comments: Leave a comment
Tweet

Join 17,000+ WooWeekly subscribers

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 Rodolfo Melogli (not Rodolfo Melogli? 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 CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_action( 'template_redirect', 'bbloomer_my_account_redirect_to_downloads' );

function bbloomer_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 CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

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

function bbloomer_myaccount_replace_dashboard_content() {
	remove_action( 'woocommerce_account_content', 'woocommerce_account_content', 10 );
	add_action( 'woocommerce_account_content', 'bbloomer_account_content' );
}

function bbloomer_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 CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_filter( 'woocommerce_account_menu_items', 'bbloomer_myaccount_rename_dashboard_tab_title', 9999 );
 
function bbloomer_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 CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_filter( 'woocommerce_account_menu_items', 'bbloomer_myaccount_remove_orders_tab', 9999 );
 
function bbloomer_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 CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

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

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

Related posts:

  1. WooCommerce: Add Content @ My Account Register / Login Page
  2. WooCommerce: Change User Role for New Customers
  3. WooCommerce: File Upload @ My Account Registration Form
  4. WooCommerce: Login Redirect by User Role @ My Account
  5. WooCommerce: Horizontal My Account Navigation Menu
  6. WooCommerce: Let Customers Complete a Processing Order
  7. WooCommerce: Reorder My Account Tabs
  8. WooCommerce: Order Again Button @ My Account > Orders
  9. WooCommerce: Rename “Completed” Order Status
  10. WooCommerce: Rename Downloads Table Column Title @ My Account
Was this article helpful?
YesNo

Where to add custom code?

You should place PHP snippets at the bottom of your child theme functions.php file and CSS at the bottom of its style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my guide "Should I Add Custom Code Via WP Editor, FTP or Code Snippets?" and my video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything went as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting.

If you think this code saved you time & money, feel free to join 17,000+ WooCommerce Weekly subscribers for blog post updates and 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance!

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

Follow @rmelogli
Category: WooCommerce Tips
Tag: My Account

Post navigation

Previous post: WooCommerce + Elementor: Let’s Build Cool Stuff
Next post: WooCommerce: Purchasing Power Parity (PPP) Discounts
Questions? Feedback? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)

Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts
  • WooCommerce: 11 Performance, Security, and Scalability Tips
  • WooCommerce: How to Level Up Your Email Marketing
  • WooCommerce: Disable Checkout Field Autocomplete
  • WooCommerce: Get EU, EU VAT, EEA, SCA Countries
  • WooCommerce: Add Product To Order After Purchase
About Business Bloomer

With 100,000 (and growing) monthly organic sessions, Business Bloomer is the most consistent, most active and most complete WooCommerce development/customization blog.

Of course this website itself uses the WooCommerce plugin, the Storefront theme and runs on a WooCommerce-friendly hosting.

Join 75,000+ Monthly Readers & 17,000+ Subscribers.

Become a Business Bloomer Supporter.

Join BloomerArmada and become an Official Business Bloomer Supporter:
easy-peasy, and lots of perks for you.
See your Benefits →
Popular Searches: Visual Hook Guides - Checkout Page - Cart Page - Single Product Page - Add to Cart - Emails - Shipping - Prices - Hosting
Latest Articles
  • WooCommerce: 11 Performance, Security, and Scalability Tips
  • WooCommerce: How to Level Up Your Email Marketing
  • WooCommerce: Disable Checkout Field Autocomplete
  • WooCommerce: Get EU, EU VAT, EEA, SCA Countries
  • WooCommerce: Add Product To Order After Purchase
Latest Comments
  • Rodolfo Melogli on WooCommerce: How to Translate / Rename Any String
  • Rodolfo Melogli on WooCommerce: Disable Payment Gateway For Specific Shipping Method
  • Rodolfo Melogli on WooCommerce: Add Second Description @ Product Category Pages
  • Rodolfo Melogli on Shoptimizer Theme Visual Hook Guide
Find Out More
  • Become a WooCommerce Expert
  • WooCommerce Blog
  • WooCommerce Online Courses
  • WooCommerce Weekly
  • Bloomer Armada
  • Affiliate Program
  • Contact
Contact Info

Ciao! I’m Rodolfo Melogli, an Italian Civil Engineer who has turned into an international WooCommerce expert. You can contact me here:

Email: [email protected]

Twitter: @rmelogli

Hire me by the hour: Get Quote ยป

VisaMastercardAmexPayPal Acceptance Mark
Business Bloomer © 2011-2023 - Terms of Use - Privacy Policy