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 )
WHERE
orden.post_type='shop_order'
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) {
$OrderId=$result->order_number;
$user_email=$result->user_email;
$user_id=$result->user_id;
$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.
Thanks!