WC_REST_Customers_V1_Controller::update_customer_meta_fields()protectedWC 1.0

Update customer meta fields.

Method of the class: WC_REST_Customers_V1_Controller{}

No Hooks.

Return

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->update_customer_meta_fields( $customer, $request );
$customer(WC_Customer) (required)
-
$request(WP_REST_Request) (required)
-

WC_REST_Customers_V1_Controller::update_customer_meta_fields() code 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 ] );
			}
		}
	}
}