Automattic\WooCommerce\StoreApi\Schemas\V1\Agentic

CheckoutSessionSchema::format_buyer_from_orderprotectedWC 1.0

Format buyer information from order.

Метод класса: CheckoutSessionSchema{}

Хуков нет.

Возвращает

Массив|null. Buyer data or null.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->format_buyer_from_order( $order );
$order(WC_Order) (обязательный)
Order object.

Код CheckoutSessionSchema::format_buyer_from_order() WC 10.5.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() : '',
	];
}