WC_Admin_Profile::save_customer_meta_fields()publicWC 1.0

Save Address Fields on edit user pages.

Method of the class: WC_Admin_Profile{}

Return

null. Nothing (null).

Usage

$WC_Admin_Profile = new WC_Admin_Profile();
$WC_Admin_Profile->save_customer_meta_fields( $user_id );
$user_id(int) (required)
User ID of the user being saved

WC_Admin_Profile::save_customer_meta_fields() code WC 8.7.0

public function save_customer_meta_fields( $user_id ) {
	if ( ! apply_filters( 'woocommerce_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_woocommerce' ), $user_id ) ) {
		return;
	}

	$save_fields = $this->get_customer_meta_fields();

	foreach ( $save_fields as $fieldset_type => $fieldset ) {

		foreach ( $fieldset['fields'] as $key => $field ) {

			if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) {
				update_user_meta( $user_id, $key, isset( $_POST[ $key ] ) );
			} elseif ( isset( $_POST[ $key ] ) ) {
				update_user_meta( $user_id, $key, wc_clean( $_POST[ $key ] ) );
			}
		}

		// Skip firing the action for any non-internal fieldset types.
		if ( ! in_array( $fieldset_type, array( 'billing', 'shipping' ), true ) ) {
			continue;
		}

		// Fieldset type is an internal address type.
		$address_type = $fieldset_type;

		/**
		 * Hook: woocommerce_customer_save_address.
		 *
		 * Fires after a customer address has been saved on the user profile admin screen.
		 *
		 * @since 8.5.0
		 * @param int    $user_id User ID being saved.
		 * @param string $address_type Type of address; 'billing' or 'shipping'.
		 */
		do_action( 'woocommerce_customer_save_address', $user_id, $address_type );
	}
}