/**
  * Add/Update customer data.
  *
  * @since 2.2
  * @param int $id the customer ID
  * @param array $data
  * @param WC_Customer $customer
  */
 protected function update_customer_data($id, $data, $customer)
 {
     // Customer first name.
     if (isset($data['first_name'])) {
         $customer->set_first_name(wc_clean($data['first_name']));
     }
     // Customer last name.
     if (isset($data['last_name'])) {
         $customer->set_last_name(wc_clean($data['last_name']));
     }
     // Customer billing address.
     if (isset($data['billing_address'])) {
         foreach ($this->get_customer_billing_address() as $field) {
             if (isset($data['billing_address'][$field])) {
                 if (is_callable(array($customer, "set_billing_{$field}"))) {
                     $customer->{"set_billing_{$field}"}($data['billing_address'][$field]);
                 } else {
                     $customer->update_meta_data('billing_' . $field, wc_clean($data['billing_address'][$field]), $meta['id']);
                 }
             }
         }
     }
     // Customer shipping address.
     if (isset($data['shipping_address'])) {
         foreach ($this->get_customer_shipping_address() as $field) {
             if (isset($data['shipping_address'][$field])) {
                 if (is_callable(array($customer, "set_shipping_{$field}"))) {
                     $customer->{"set_shipping_{$field}"}($data['shipping_address'][$field]);
                 } else {
                     $customer->update_meta_data('shipping_' . $field, wc_clean($data['shipping_address'][$field]), $meta['id']);
                 }
             }
         }
     }
     do_action('woocommerce_api_update_customer_data', $id, $data, $customer);
 }
 /**
  * Update customer meta fields.
  *
  * @param WC_Customer $customer
  * @param WP_REST_Request $request
  */
 protected function update_customer_meta_fields($customer, $request)
 {
     $schema = $this->get_item_schema();
     // Meta data
     if (isset($request['meta_data'])) {
         if (is_array($request['meta_data'])) {
             foreach ($request['meta_data'] as $meta) {
                 $customer->update_meta_data($meta['key'], $meta['value'], $meta['id']);
             }
         }
     }
     // 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]);
             }
         }
     }
 }