Skip Navigation

[Resolved] name order in woocommerce customer dashboard.

This thread is resolved. Here is a description of the problem and solution.

Problem:
Want to change name order when customer login to customer dashboard.
Like this: Family name (Last Name) comes first and First name comes second.

Solution:
Please add this code in your theme’s or child theme’s functions.php file:

function wp_update_display_name ( $user_login, $user ) {
      $user_info = get_userdata($user->ID);
      $first_name = $user_info->first_name;
      $last_name = $user_info->last_name;
 
      wp_update_user(array('ID' => $user->ID, 'display_name' => $last_name . ' '. $first_name));
}
 
add_action('wp_login', 'wp_update_display_name', PHP_INT_MAX, 2);

Relevant Documentation:
More info: https://wordpress.stackexchange.com/a/214214

This support ticket is created 7 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by Junichiro Taira 7 years, 5 months ago.

Assisted by: Noman.

Author
Posts
#530095
img.jpg

I install woocommerce into toolset starter theme.
I want to change name order when customer login to customer dashboard.

Currently: First name comes first and Family name comes second.
Change: Family name comes first and First name comes second.

I know admin user can change their display name order in admin dashboard.
But customer can not do that. Is there any way to control this issue ?
I want to keep display name order as "Family name - First name".

#530313

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Junichiro,

Thank you for contacting Toolset Support. This requirement is more related to WordPress default function, but I have tested this at my end and the following code I have written will make this change:

More info: https://wordpress.stackexchange.com/a/214214

Please add this code in your theme’s or child theme’s functions.php file:

function wp_update_display_name ( $user_login, $user ) {
      $user_info = get_userdata($user->ID);
      $first_name = $user_info->first_name;
      $last_name = $user_info->last_name;

      wp_update_user(array('ID' => $user->ID, 'display_name' => $last_name . ' '. $first_name));
}

add_action('wp_login', 'wp_update_display_name', PHP_INT_MAX, 2);

This code will be effective as soon as the user login.
Thank you

#530335

Wow great !!! Thank you so much. It will be much easier for me to use Toolset & Woocommerce !!!

It will be automatically login when customer made check-out.
So they need to logout in order to make your code work.
Is it possible to make customer log off when they check out ?

#530379

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Junichiro,

When user logged-in his display name will change as Last Name + First Name. This code will only perform this function. It is not related to checkout.

For checkout and logoff, I am not sure on this because WooCommerce will authenticate user after the payment. However, this question is related to WooCommerce and you can contact WooCommerce support to get some help on this: https://wordpress.org/support/plugin/woocommerce

So they need to logout in order to make your code work.
==> Yes, user has to logout because it cannot be changed for: already logged-in users.

Thank you

#530405

Thank you very much. I will do that !