WooCommerce: Change Display name publicly as to full name in My account Page
If you’re running a WooCommerce store, you might have noticed that the default display name of users on the “My Account” page is often just the username. Many store owners prefer to showcase the full name for a more professional and personable touch. Here’s a short code on how you can achieve this!
put this code on functions.php
add_action( 'wp_login', 'custom_set_display_name_publicly_as'); function custom_set_display_name_publicly_as( $username ) { $user = get_user_by( 'login', $username ); $first_name = get_user_meta( $user->ID, 'first_name', true ); $last_name = get_user_meta( $user->ID, 'last_name', true ); $full_name = trim( $first_name . ' ' . $last_name ); if ( ! empty( $full_name ) && ( $user->data->display_name != $full_name ) ) { $userdata = array( 'ID' => $user->ID, 'display_name' => $full_name, ); wp_update_user( $userdata ); } }