Ever wanted to display a my account page link in your WooCommerce theme files, and to have this changed to “Login / Register” in case your user is not logged in, dynamically?

Well the snippet below, when added into the relevant location in your theme template files will do just that!

We tend to wrap it in other controls, or include button links, but this makes a nice addition to header / footer links in a theme which is for WooCommerce to help users navigate to their My Account page(s).

The Code – Show “My Account” to logged in users and “Register / Login” to Guests

[gist id=”c8309fdab9fac537f4edc13ad3b7779f”]

Note: Gist (above) updated 23 Nov 2018.

What it does

The code above will insert a “My Account” link for logged in users, or a “Register / Login” link to guests. As simple as that. It can even be used in menus.

Leave a comment

If you have questions or comments about this snippet, please leave them below. The aim, here, is to build a useful resource for WooCommerce developers around the globe.