Automattic\WooCommerce\StoreApi\Utilities

AgenticCheckoutUtils::set_billing_addresspublic staticWC 1.0

Set billing address on customer.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

$result = AgenticCheckoutUtils::set_billing_address( $address, $customer );
$address(массив) (обязательный)
Address data.
$customer(WC_Customer) (обязательный)
Customer instance.

Код AgenticCheckoutUtils::set_billing_address() WC 10.5.0

public static function set_billing_address( $address, $customer ) {
	// Only parse and set name if provided and non-empty.
	if ( ! empty( $address['name'] ) ) {
		$name       = wc_clean( wp_unslash( $address['name'] ) );
		$name_parts = explode( ' ', $name, 2 );
		$first_name = $name_parts[0];
		$last_name  = isset( $name_parts[1] ) ? $name_parts[1] : '';

		// Set billing names.
		$customer->set_billing_first_name( $first_name );
		$customer->set_billing_last_name( $last_name );
	}

	// Sanitize all address fields.
	$line_one    = wc_clean( wp_unslash( $address['line_one'] ?? '' ) );
	$line_two    = wc_clean( wp_unslash( $address['line_two'] ?? '' ) );
	$city        = wc_clean( wp_unslash( $address['city'] ?? '' ) );
	$state       = wc_clean( wp_unslash( $address['state'] ?? '' ) );
	$postal_code = wc_clean( wp_unslash( $address['postal_code'] ?? '' ) );
	$country     = wc_clean( wp_unslash( $address['country'] ?? '' ) );

	// Set billing address fields.
	$customer->set_billing_address_1( $line_one );
	$customer->set_billing_address_2( $line_two );
	$customer->set_billing_city( $city );
	$customer->set_billing_state( $state );
	$customer->set_billing_postcode( $postal_code );
	$customer->set_billing_country( $country );

	$customer->save();
}