WC_Customer_Data_Store::update_user_meta()privateWC 3.0.0

Helper method that updates all the meta for a customer. Used for update & create.

Method of the class: WC_Customer_Data_Store{}

Return

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->update_user_meta( $customer );
$customer(WC_Customer) (required)
Customer object.

Changelog

Since 3.0.0 Introduced.

WC_Customer_Data_Store::update_user_meta() code WC 9.4.2

private function update_user_meta( $customer ) {
	$updated_props = array();
	$changed_props = $customer->get_changes();

	$meta_key_to_props = array(
		'paying_customer' => 'is_paying_customer',
		'first_name'      => 'first_name',
		'last_name'       => 'last_name',
	);

	foreach ( $meta_key_to_props as $meta_key => $prop ) {
		if ( ! array_key_exists( $prop, $changed_props ) ) {
			continue;
		}

		if ( update_user_meta( $customer->get_id(), $meta_key, $customer->{"get_$prop"}( 'edit' ) ) ) {
			$updated_props[] = $prop;
		}
	}

	$billing_address_props = array(
		'billing_first_name' => 'billing_first_name',
		'billing_last_name'  => 'billing_last_name',
		'billing_company'    => 'billing_company',
		'billing_address_1'  => 'billing_address_1',
		'billing_address_2'  => 'billing_address_2',
		'billing_city'       => 'billing_city',
		'billing_state'      => 'billing_state',
		'billing_postcode'   => 'billing_postcode',
		'billing_country'    => 'billing_country',
		'billing_email'      => 'billing_email',
		'billing_phone'      => 'billing_phone',
	);

	foreach ( $billing_address_props as $meta_key => $prop ) {
		$prop_key = substr( $prop, 8 );

		if ( ! isset( $changed_props['billing'] ) || ! array_key_exists( $prop_key, $changed_props['billing'] ) ) {
			continue;
		}

		if ( update_user_meta( $customer->get_id(), $meta_key, $customer->{"get_$prop"}( 'edit' ) ) ) {
			$updated_props[] = $prop;
		}
	}

	$shipping_address_props = array(
		'shipping_first_name' => 'shipping_first_name',
		'shipping_last_name'  => 'shipping_last_name',
		'shipping_company'    => 'shipping_company',
		'shipping_address_1'  => 'shipping_address_1',
		'shipping_address_2'  => 'shipping_address_2',
		'shipping_city'       => 'shipping_city',
		'shipping_state'      => 'shipping_state',
		'shipping_postcode'   => 'shipping_postcode',
		'shipping_country'    => 'shipping_country',
		'shipping_phone'      => 'shipping_phone',
	);

	foreach ( $shipping_address_props as $meta_key => $prop ) {
		$prop_key = substr( $prop, 9 );

		if ( ! isset( $changed_props['shipping'] ) || ! array_key_exists( $prop_key, $changed_props['shipping'] ) ) {
			continue;
		}

		if ( update_user_meta( $customer->get_id(), $meta_key, $customer->{"get_$prop"}( 'edit' ) ) ) {
			$updated_props[] = $prop;
		}
	}

	do_action( 'woocommerce_customer_object_updated_props', $customer, $updated_props );
}