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

WooCommerce: Rename “My Account” If Logged Out @ Nav Menu

> Published: Nov 2019 - Revised: Nov 2020
> Blog Category: WooCommerce Tips
> Blog Tags: Logged in, My Account
> Blog Comments: 35 Comments
Tweet

Join 17,000+ WooWeekly subscribers

You could install a free WordPress plugin to enable “LOGIN / LOGOUT” menu links – or you could use a super simple snippet. Once again, the less plugins you use the better, especially if you can replace them with a few lines of code.

In this case study, I have added the “My Account” page to the navigation menu and I want that label to change to “Login” if the user is logged out. Enjoy!

When logged out, my own website navigation menu shows a “LOGIN” button. If logged in, the same menu link label changes to “MY ACCOUNT”.

PHP Snippet: Conditionally Rename “My Account” Menu Label If User Is Logged Out

/**
 * @snippet       Rename "My Account" Link @ WooCommerce/WP Nav Menu
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 4.5
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_filter( 'wp_nav_menu_items', 'bbloomer_dynamic_menu_item_label', 9999, 2 ); 

function bbloomer_dynamic_menu_item_label( $items, $args ) { 
	if ( ! is_user_logged_in() ) { 
		$items = str_replace( "My Account", "Login", $items ); 
	} 
	return $items; 
} 

Please note that if you rename the “navigation label” you must change the code accordingly:

Pay attention if the navigation label is customized – you’d need to adapt the snippet!

PHP Snippet: Conditionally Rename Custom Menu Label If User Is Logged Out

/**
 * @snippet       Rename Custom Link Label @ WooCommerce/WP Nav Menu
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 4.5
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_filter( 'wp_nav_menu_items', 'bbloomer_dynamic_menu_item_label', 9999, 2 ); 

function bbloomer_dynamic_menu_item_label( $items, $args ) { 
	if ( ! is_user_logged_in() ) { 
		$items = str_replace( "Account", "Login", $items ); 
	} 
	return $items; 
} 

Related posts:

  1. WooCommerce: Add Content @ My Account Register / Login Page
  2. WooCommerce: Change User Role for New Customers
  3. WooCommerce: Single Product Page Redirect for Logged In Customers
  4. WooCommerce: File Upload @ My Account Registration Form
  5. WooCommerce: Login Redirect by User Role @ My Account
  6. WooCommerce: Login Redirect to Previous URL @ My Account
  7. WooCommerce: Horizontal My Account Navigation Menu
  8. WooCommerce: Only Allow to Buy a Product Once
  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
Tags: Logged in, My Account

Post navigation

Previous post: WooCommerce: How to Customize your Store Without Coding
Next post: WordPress: Fix “No Update Required” @ WP Admin

35 thoughts on “WooCommerce: Rename “My Account” If Logged Out @ Nav Menu”

  1. Scott Kindley
    January 11, 2023

    How would you do this if you wanted it to say login is logged out ANS logout if logged in?

    Reply
    1. Rodolfo Melogli
      January 13, 2023

      Not sure I follow?

      Reply
  2. Chris
    February 11, 2022

    Works great with woocommerce 6.2.0. Thanks for your enormous work Rodolfo!

    Reply
    1. Rodolfo Melogli
      March 5, 2022

      Great!

      Reply
  3. Chris
    November 29, 2021

    Thanks for this, how would this need to be modified to work on a secondary menu (I’m using Divi).

    Reply
    1. Rodolfo Melogli
      December 6, 2021

      Hi Chris! This should work on any WP menu, secondary included

      Reply
  4. mathias
    May 5, 2021

    Dear,

    I used the exact same snippet as you suggested, but it seem to only work on the /my-account/ page and not on other pages such as the home page. Any idea on how I can resolve this?

    Thank you in advance.

    Regards,

    Mathias

    Reply
    1. Rodolfo Melogli
      June 2, 2021

      Hi Mathias, I use this on my own website. This is meant to work in your Navigation Menu

      Reply
  5. Carlos Martinez
    March 13, 2021

    Hey, as of March 13 2021 this code, and actually all of the code I used from you doesnt work. The main reason is because of woocommerce’s 5.0.0 (or it could be 5.1.0, I’m no really sure which one is) update. Can you help everyone fixing this issue please?

    Reply
    1. Rodolfo Melogli
      March 22, 2021

      ALL of my snippets don’t work? LOL, that’s pretty bad. Woo 5.0 wasn’t that big deal, so I’d be surprised. To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentytwenty” theme (load the snippet there in functions.php) as explained here: https://www.businessbloomer.com/lesson/trwm4l01/

      Once you do that, does it work? If yes, you have a problem with your current theme or one of the plugins.

      Hope this helps!

      Reply
  6. Agapi Karageorgou
    March 11, 2021

    Hi! Works fine on my website. Thank you for the tutorial. I just wanted to ask: how can I change the link of the login page? I have my own customized login page and I want to change it from the wordpress default page.

    Reply
    1. Rodolfo Melogli
      March 22, 2021

      Hi, maybe from the WordPress menu?

      Reply
  7. Earth
    November 13, 2020

    Hi, the snippet works great. But does it also work on the My Account on the right side of the menu? The one that comes with the plugin?

    Reply
    1. Rodolfo Melogli
      November 25, 2020

      No sorry this is for WordPress menus

      Reply
  8. Tom Buchanan
    October 12, 2020

    Worked a treat for me (using PHP 7.4) .

    Thank you!

    Reply
    1. Rodolfo Melogli
      October 16, 2020

      Cool

      Reply
  9. Camille
    September 19, 2020

    I tried this on two different websites, they’re identical clones of one another, the only difference is that the one is on a higher version of php 7.4… and it’s not working

    Reply
    1. Camille
      September 19, 2020

      This is the error I get:

      “The snippet has been deactivated due to an error on line 4:

      Cannot redeclare function dynamic_label_change. “

      Reply
      1. Rodolfo Melogli
        September 21, 2020

        Not sure, that’s not my function

        Reply
  10. Jimmy
    September 16, 2020

    Just tried it and it works great! No need for a plugin. Thank you very much!

    Reply
    1. Rodolfo Melogli
      September 21, 2020

      Way to go!

      Reply
  11. Morgan
    September 15, 2020

    Hello,
    your code still work smoothly

    do you have a tutorial ifsomeone login then the teks link will change to the name of the user instead of my-account

    thank you

    Reply
    1. Rodolfo Melogli
      September 21, 2020

      Hi Morgan, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

      Reply
  12. Manon
    May 2, 2020

    I just tried this, the exact snippet, but it’s not working for me.
    Other snippets I found here are working perfectly. Any idea what the problem could be?

    Reply
    1. Rodolfo Melogli
      May 13, 2020

      Read through the comments. This is case-sensitive, maybe https://businessbloomer.com/woocommerce-rename-my-account-menu-label-if-logged-out/#comment-355148 might help

      Reply
  13. Anant Mantri
    March 27, 2020

    It works flawlessly. Check the labels, if it is “My Account” or not. Those who are confused about label, it is the Page name or rather the Menu item name. It is case sensitive, if your account page is named something else, try using that instead of “My Account” in the snippet code. Stop blind copy paste, use your head guys.

    Reply
    1. Rodolfo Melogli
      March 27, 2020

      TOP!

      Reply
  14. Ayeh
    December 29, 2019

    it didn’t work 🙁 . i follow every step on your tutorial.

    Reply
    1. Rodolfo Melogli
      January 6, 2020

      This is case sensitive – try again?

      Reply
  15. Emma Hannay
    December 17, 2019

    Awesome snippet – worked perfectly (once I’d changed it from ‘My account’ to ‘My Account’ 😉 )
    Thank you!

    Reply
    1. Rodolfo Melogli
      December 17, 2019

      Great!

      Reply
  16. Sagi
    November 17, 2019

    Hi Rodolfo,
    I have the same problem. Did exactly as you teaching in your explanation video and used your exact snippet.
    I use current version of WooCommerce: 3.8.0, and WP version is 5.3

    Reply
    1. Rodolfo Melogli
      November 19, 2019

      Hi Sagi. Do you have a “My Account” navigation menu link (because I do and the snippet works on this same website)?

      Reply
  17. Van
    November 13, 2019

    Hi, just tried it out and nope, it didn’t work.

    Reply
    1. Rodolfo Melogli
      November 14, 2019

      Did you use my exact snippet?

      Reply
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