Automattic\WooCommerce\StoreApi\Utilities

AgenticCheckoutUtils::set_buyer_datapublic staticWC 1.0

Set buyer data on customer.

Method of the class: AgenticCheckoutUtils{}

No Hooks.

Returns

null. Nothing (null).

Usage

$result = AgenticCheckoutUtils::set_buyer_data( $buyer, $customer );
$buyer(array) (required)
Buyer data.
$customer(WC_Customer) (required)
Customer instance.

AgenticCheckoutUtils::set_buyer_data() code WC 10.4.3

public static function set_buyer_data( $buyer, $customer ) {
	if ( isset( $buyer['first_name'] ) ) {
		$first_name = wc_clean( wp_unslash( $buyer['first_name'] ) );
		$customer->set_billing_first_name( $first_name );
		$customer->set_shipping_first_name( $first_name );
	}

	if ( isset( $buyer['last_name'] ) ) {
		$last_name = wc_clean( wp_unslash( $buyer['last_name'] ) );
		$customer->set_billing_last_name( $last_name );
		$customer->set_shipping_last_name( $last_name );
	}

	if ( isset( $buyer['email'] ) ) {
		$email = sanitize_email( wp_unslash( $buyer['email'] ) );
		if ( is_email( $email ) ) {
			$customer->set_billing_email( $email );
		}
	}

	if ( isset( $buyer['phone_number'] ) ) {
		$phone = wc_clean( wp_unslash( $buyer['phone_number'] ) );
		$customer->set_billing_phone( $phone );
	}

	$customer->save();
}