I've been working on a custom plugin for a client of mine that outputs order information into a text file for them from Woocommerce. Everything's been working great until recently, when for some unexplainable reason, every time someone logs in, their display name changes from the nickname to the "FirstName LastName" option....which breaks my output.

I need to display their nickname or their login (which are the same) instead of the display name...which has been used up until now.

Here is what I believe is the relevant part of the query:

            $query = $wpdb->prepare( "SELECT orden.ID AS order_number,
                orden.post_modified AS last_date,
                orden.post_excerpt AS deliverynotes,
                orden.post_modified AS formatteddate,
                user.ID AS user_id,
                user.user_email AS user_email,
                user.display_name AS user_name,
                user.user_login AS user_login
                FROM {$wpdb->posts} AS orden
                LEFT JOIN {$wpdb->postmeta} AS meta
                ON (meta.post_id = orden.ID)
                LEFT JOIN {$wpdb->users} AS user
                ON (user.ID=meta.meta_value )
                AND orden.post_status not in ('trash',  'auto-draft')
                AND meta.meta_key='_customer_user'
                AND orden.ID IN ({$orderIdsArrStr})" , '');

            $results = $wpdb->get_results($query);

            if ( !empty( $results ) ) {
                $OrderTXT = '';

                foreach($results as $result) {

                    $user_displayname = $result->user_name;

Then this is the part where it's displaying the order for me:

$OrderTXT .= "*,".$user_displayname.",".$OrderId.",".$shippingCustomer['client_firstname']." ".$shippingCustomer['client_lastname'].",".$shippingCustomer['$order_company'].",".$shippingCustomer['client_firstname'].",".$shippingCustomer['client_lastname'].",".$shippingCustomer['$order_address1'].",".$shippingCustomer['$order_address2'].$shippingCustomer['$order_address3'].",".$shippingCustomer['$order_city'].",".$shippingCustomer['$order_state'].",".$shippingCustomer['$order_postcode'].",".$shippingCustomer['$order_country'].",".$shippingCustomer['client_phone'].",,".$user_email.",".$shippingCustomer['client_firstname']." ".$shippingCustomer['client_lastname'].",".$shippingCustomer['$order_company'].",".$shippingCustomer['client_firstname']." ".$shippingCustomer['client_lastname'].",".$shippingCustomer['$order_address1'].",".$shippingCustomer['$order_address2'].$shippingCustomer['$order_address3'].",".$shippingCustomer['$order_city'].",".$shippingCustomer['$order_state'].",".$shippingCustomer['$order_postcode'].",".$shippingCustomer['$order_country'].",".$shippingCustomer['client_phone'].",UPS,00".$OrderId.",Internet,N45,\n";

It's that very first bit "$user_displayname" that is changing and showing the wrong thing. How can I change this to something to the effect of $user_nickname ??

I've already tried $user_login $user_nickName....but to no avail. I'm guessing it's because it's not in the original query?

Sorry for the longwinded question. I'm sure this is a very simple fix.



I had a similar problem and solved it similar to this:

function default_display_name($display_name) {
    if ( isset( $_POST['billing_first_name'] ) ) {
        $display_name = sanitize_text_field( $_POST['billing_first_name'] );
    return $name;

I think, the new woocommerce changes the disyplay_name on every checkout to First_Name Last_Name. With the 'pre_user_display_name' you can change your own way.

  • Many thanks for the reply!! Let me just make sure...this is something that would go in functions.php as a precursor to Woocommerce ever changing the display name? Looks like it'll check to see if it's been changed and change it back. Apr 19 '17 at 18:53
  • I added it to the functions.php file and now it's just displaying a blank display name if it's changed at all. So no dice for me yet. Apr 19 '17 at 21:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.