Website Building » WooCommerce » How Do I Show My Username in WooCommerce?

How Do I Show My Username in WooCommerce?

Last updated on January 17, 2023 @ 5:22 am

If you’re running a WooCommerce store, it’s likely that you’ll want to show your username somewhere on the frontend, whether that’s in the header, footer, or somewhere else on the page. There are a few different ways to do this, and we’ll cover them all in this article.

The first way to show your username in WooCommerce is to use the is_user_logged_in() function. This function will return true if the user is logged in, and false if they’re not. You can then use this function to output your username:

<?php 
if ( is_user_logged_in() ) {
    echo 'Welcome, ' . $current_user->user_login .'! ';
} 

else {
    echo 'Welcome, guest! ';
}
?>

If you want to take this a step further and output a link to the user's account page, you can use the get_permalink() function:

<?php 
if ( is_user_logged_in() ) {
    echo 'Welcome, <a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">' . 

'</a>! ';
} else {
    echo 'Welcome, guest! ';
} ?> 

Another way to show your username in WooCommerce is by using the WooCommerce Shortcodes. These are a set of predefined shortcodes that can be used to output content related to WooCommerce.

To output your username using a shortcode, you can use the [wc_loginout] shortcode. This shortcode will output a login link if the user isn't logged in, and a logout link if they are:

  <?php echo do_shortcode( '[wc_loginout]' ); ?>

If you want to take this a step further and output a link to the user's account page, you can use the [wc-my-account] shortcode:

  <?php echo do_shortcode( '[wc-my-account]' ); ?
Madison Geldart

Madison Geldart

Cloud infrastructure engineer and tech mess solver.