WC_REST_Customers_V1_Controller::update_customer_meta_fields() protected WC 1.0
Update customer meta fields.
{} It's a method of the class: WC_REST_Customers_V1_Controller{}
No Hooks.
Return
Null. Nothing.
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)
- -
Code of WC_REST_Customers_V1_Controller::update_customer_meta_fields() WC REST Customers V1 Controller::update customer meta fields WC 5.0.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 ] );
}
}
}
}