Automattic\WooCommerce\StoreApi\Schemas\V1\Agentic
CheckoutSessionSchema::format_buyer_from_order
Format buyer information from order.
Method of the class: CheckoutSessionSchema{}
No Hooks.
Returns
Array|null. Buyer data or null.
Usage
// protected - for code of main (parent) or child class $result = $this->format_buyer_from_order( $order );
- $order(WC_Order) (required)
- Order object.
CheckoutSessionSchema::format_buyer_from_order() CheckoutSessionSchema::format buyer from order code WC 10.7.0
protected function format_buyer_from_order( $order ) {
$first_name = $order->get_billing_first_name() ? $order->get_billing_first_name() : $order->get_shipping_first_name();
$last_name = $order->get_billing_last_name() ? $order->get_billing_last_name() : $order->get_shipping_last_name();
$email = $order->get_billing_email();
if ( ! $first_name && ! $last_name && ! $email ) {
return null;
}
return [
'first_name' => $first_name ? $first_name : '',
'last_name' => $last_name ? $last_name : '',
'email' => $email ? $email : '',
'phone_number' => $order->get_billing_phone() ? $order->get_billing_phone() : '',
];
}