WC_REST_Customers_V1_Controller::update_customer_meta_fields()protectedWC 1.0

Update customer meta fields.

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

Хуков нет.

Возвращает

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

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->update_customer_meta_fields( $customer, $request );
$customer(WC_Customer) (обязательный)
-
$request(WP_REST_Request) (обязательный)
-

Код WC_REST_Customers_V1_Controller::update_customer_meta_fields() WC 8.7.0

protected function update_customer_meta_fields( $customer, $request ) {
	$schema = $this->get_item_schema();

	// Customer first name.
	if ( isset( $request['first_name'] ) ) {
		$customer->set_first_name( wc_clean( $request['first_name'] ) );
	}

	// Customer last name.
	if ( isset( $request['last_name'] ) ) {
		$customer->set_last_name( wc_clean( $request['last_name'] ) );
	}

	// Customer billing address.
	if ( isset( $request['billing'] ) ) {
		foreach ( array_keys( $schema['properties']['billing']['properties'] ) as $field ) {
			if ( isset( $request['billing'][ $field ] ) && is_callable( array( $customer, "set_billing_{$field}" ) ) ) {
				$customer->{"set_billing_{$field}"}( $request['billing'][ $field ] );
			}
		}
	}

	// Customer shipping address.
	if ( isset( $request['shipping'] ) ) {
		foreach ( array_keys( $schema['properties']['shipping']['properties'] ) as $field ) {
			if ( isset( $request['shipping'][ $field ] ) && is_callable( array( $customer, "set_shipping_{$field}" ) ) ) {
				$customer->{"set_shipping_{$field}"}( $request['shipping'][ $field ] );
			}
		}
	}
}