Archived topic
Add User Name in Header Element
3 replies · Started by Kim on October 23, 2019
Viewing posts 1–4 of 4
Hi there, I would like to create a header element for the woocommerce my account page displaying the customer/user name. Is this possible and how can I achieve this?
Many thanks in advance!
Hi there,
add this PHP snippet:
function db_display_current_user() {
ob_start();
$current_user = wp_get_current_user();
if ( is_user_logged_in() ) {
echo '<span class="current-user">' . $current_user->display_name . '</span>';
} else {
echo '<span class="current-user">Message for not logged in user</span>';
}
return ob_get_clean();
}
add_shortcode( 'current_user_name', 'db_display_current_user' );
Then you can use the [current_user_name] shortcode in the Header Element
Awesome! Many thanks :)
You're welcome
This archived topic is closed to new replies.