WC_API_Customers::update_customer_data()protectedWC 2.2

Add/Update customer data.

Method of the class: WC_API_Customers{}

Hooks from the method

Return

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->update_customer_data( $id, $data, $customer );
$id(int) (required)
the customer ID
$data(array) (required)
-
$customer(WC_Customer) (required)
-

Changelog

Since 2.2 Introduced.

WC_API_Customers::update_customer_data() code WC 8.7.0

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 ] ) );
				}
			}
		}
	}

	// 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 ] ) );
				}
			}
		}
	}

	do_action( 'woocommerce_api_update_customer_data', $id, $data, $customer );
}