Automattic\WooCommerce\StoreApi\Schemas\V1\Agentic

CheckoutSessionSchema::format_buyerprotectedWC 1.0

Format buyer information.

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();

CheckoutSessionSchema::format_buyer() code WC 10.7.0

protected function format_buyer() {
	$customer = WC()->customer;

	if ( ! $customer ) {
		return null;
	}

	$first_name = $customer->get_billing_first_name() ? $customer->get_billing_first_name() : $customer->get_shipping_first_name();
	$last_name  = $customer->get_billing_last_name() ? $customer->get_billing_last_name() : $customer->get_shipping_last_name();
	$email      = $customer->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' => $customer->get_billing_phone() ? $customer->get_billing_phone() : '',
	];
}