Skip to content

Instantly share code, notes, and snippets.

@zeshanshani
Created December 7, 2017 09:33
Show Gist options
  • Save zeshanshani/69416af6d965c9ca6a41e87ebe185143 to your computer and use it in GitHub Desktop.
Save zeshanshani/69416af6d965c9ca6a41e87ebe185143 to your computer and use it in GitHub Desktop.
<?php
/**
* Get Full Customer Name from Order ID
*
* Author: Zeshan Ahmed
* Author URI: https://zeshanahmed.com/
*/
function za_full_customer_name( $order_id ) {
$order = new WC_Order( $order_id );
$user_id = $order->get_user_id();
// Check if the user id is not false.
if ( $user_id ) {
$fname = get_user_meta( $user_id, 'billing_first_name', true );
$lname = get_user_meta( $user_id, 'billing_last_name', true );
// In case customer info does not have 'first name'
// get the name from the order billing info.
if ( ! $fname ) {
$fname = $order->get_billing_first_name();
}
// In case customer info does not have 'last name'
// get the name from the order billing info.
if ( ! $lname ) {
$lname = $order->get_billing_last_name();
}
} else {
// Get the billing first name
$fname = $order->get_billing_first_name();
// Get the billing last name
$lname = $order->get_billing_last_name();
}
$name = $fname . " " . $lname;
return $name;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment