array( 'title' => __( 'Customer billing address', 'woocommerce' ), 'fields' => array( 'billing_first_name' => array( 'label' => __( 'First name', 'woocommerce' ), 'description' => '', ), 'billing_last_name' => array( 'label' => __( 'Last name', 'woocommerce' ), 'description' => '', ), 'billing_company' => array( 'label' => __( 'Company', 'woocommerce' ), 'description' => '', ), 'billing_address_1' => array( 'label' => __( 'Address line 1', 'woocommerce' ), 'description' => '', ), 'billing_address_2' => array( 'label' => __( 'Address line 2', 'woocommerce' ), 'description' => '', ), 'billing_city' => array( 'label' => __( 'City', 'woocommerce' ), 'description' => '', ), 'billing_postcode' => array( 'label' => __( 'Postcode / ZIP', 'woocommerce' ), 'description' => '', ), 'billing_country' => array( 'label' => __( 'Country / Region', 'woocommerce' ), 'description' => '', 'class' => 'js_field-country', 'type' => 'select', 'options' => array( '' => __( 'Select a country / region…', 'woocommerce' ) ) + WC()->countries->get_allowed_countries(), ), 'billing_state' => array( 'label' => __( 'State / County', 'woocommerce' ), 'description' => __( 'State / County or state code', 'woocommerce' ), 'class' => 'js_field-state', ), 'billing_phone' => array( 'label' => __( 'Phone', 'woocommerce' ), 'description' => '', ), 'billing_email' => array( 'label' => __( 'Email address', 'woocommerce' ), 'description' => '', ), ), ), 'shipping' => array( 'title' => __( 'Customer shipping address', 'woocommerce' ), 'fields' => array( 'copy_billing' => array( 'label' => __( 'Copy from billing address', 'woocommerce' ), 'description' => '', 'class' => 'js_copy-billing', 'type' => 'button', 'text' => __( 'Copy', 'woocommerce' ), ), 'shipping_first_name' => array( 'label' => __( 'First name', 'woocommerce' ), 'description' => '', ), 'shipping_last_name' => array( 'label' => __( 'Last name', 'woocommerce' ), 'description' => '', ), 'shipping_company' => array( 'label' => __( 'Company', 'woocommerce' ), 'description' => '', ), 'shipping_address_1' => array( 'label' => __( 'Address line 1', 'woocommerce' ), 'description' => '', ), 'shipping_address_2' => array( 'label' => __( 'Address line 2', 'woocommerce' ), 'description' => '', ), 'shipping_city' => array( 'label' => __( 'City', 'woocommerce' ), 'description' => '', ), 'shipping_postcode' => array( 'label' => __( 'Postcode / ZIP', 'woocommerce' ), 'description' => '', ), 'shipping_country' => array( 'label' => __( 'Country / Region', 'woocommerce' ), 'description' => '', 'class' => 'js_field-country', 'type' => 'select', 'options' => array( '' => __( 'Select a country / region…', 'woocommerce' ) ) + WC()->countries->get_allowed_countries(), ), 'shipping_state' => array( 'label' => __( 'State / County', 'woocommerce' ), 'description' => __( 'State / County or state code', 'woocommerce' ), 'class' => 'js_field-state', ), 'shipping_phone' => array( 'label' => __( 'Phone', 'woocommerce' ), 'description' => '', ), ), ), ) ); return $show_fields; } /** * Show Address Fields on edit user pages. * * @param WP_User $user */ public function add_customer_meta_fields( $user ) { if ( ! apply_filters( 'woocommerce_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_woocommerce' ), $user->ID ) ) { return; } $show_fields = $this->get_customer_meta_fields(); foreach ( $show_fields as $fieldset_key => $fieldset ) : ?>

$field ) : ?>
ID, $key, true ), 1, true ); ?> />

get_customer_meta_fields(); foreach ( $save_fields as $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 ] ) ); } } } } /** * Get user meta for a given key, with fallbacks to core user info for pre-existing fields. * * @since 3.1.0 * @param int $user_id User ID of the user being edited * @param string $key Key for user meta field * @return string */ protected function get_user_meta( $user_id, $key ) { $value = get_user_meta( $user_id, $key, true ); $existing_fields = array( 'billing_first_name', 'billing_last_name' ); if ( ! $value && in_array( $key, $existing_fields ) ) { $value = get_user_meta( $user_id, str_replace( 'billing_', '', $key ), true ); } elseif ( ! $value && ( 'billing_email' === $key ) ) { $user = get_userdata( $user_id ); $value = $user->user_email; } return $value; } } endif; return new WC_Admin_Profile();