Automattic\WooCommerce\Internal\RestApi\Routes\V4\Customers

UpdateUtils::update_customer_addressprivateWC 1.0

Update customer address fields.

Method of the class: UpdateUtils{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->update_customer_address( $customer, $address, $type ): void;
$customer(WC_Customer) (required)
Customer object.
$address(array) (required)
Address data.
$type(string) (required)
Address type (billing or shipping).

UpdateUtils::update_customer_address() code WC 10.4.3

private function update_customer_address( WC_Customer $customer, array $address, string $type ): void {
	$address = wc_clean( $address );

	$address_fields = array(
		'first_name',
		'last_name',
		'company',
		'address_1',
		'address_2',
		'city',
		'state',
		'postcode',
		'country',
		'email',
		'phone',
	);

	foreach ( $address_fields as $field ) {
		if ( isset( $address[ $field ] ) && is_callable( array( $customer, "set_{$type}_{$field}" ) ) ) {
			$value = ( 'email' === $field ) ? sanitize_email( $address[ $field ] ) : $address[ $field ];
			$customer->{"set_{$type}_{$field}"}( $value );
		}
	}
}