Automattic\WooCommerce\Admin\API\Reports\Customers
DataStore::get_customer_order_data_and_format()
Returns a data object and format object of the customers data coming from the order.
Method of the class: DataStore{}
No Hooks.
Return
Array
. ($data, $format)
Usage
$result = DataStore::get_customer_order_data_and_format( $order, $customer_user );
- $order(object) (required)
- WC_Order where we get customer info from.
- $customer_user(object|null)
- WC_Customer registered customer WP user.
Default: null
DataStore::get_customer_order_data_and_format() DataStore::get customer order data and format code WC 9.3.3
public static function get_customer_order_data_and_format( $order, $customer_user = null ) { $data = array( 'first_name' => $order->get_customer_first_name(), 'last_name' => $order->get_customer_last_name(), 'email' => $order->get_billing_email( 'edit' ), 'city' => $order->get_billing_city( 'edit' ), 'state' => $order->get_billing_state( 'edit' ), 'postcode' => $order->get_billing_postcode( 'edit' ), 'country' => $order->get_billing_country( 'edit' ), 'date_last_active' => gmdate( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getTimestamp() ), ); $format = array( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', ); // Add registered customer data. if ( 0 !== $order->get_user_id() ) { $user_id = $order->get_user_id(); if ( is_null( $customer_user ) ) { $customer_user = new \WC_Customer( $user_id ); } $data['user_id'] = $user_id; $data['username'] = $customer_user->get_username( 'edit' ); $data['date_registered'] = $customer_user->get_date_created( 'edit' ) ? $customer_user->get_date_created( 'edit' )->date( TimeInterval::$sql_datetime_format ) : null; $format[] = '%d'; $format[] = '%s'; $format[] = '%s'; } return array( $data, $format ); }