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0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / admin / class-wc-admin-profile.php
woocommerce / includes / admin Last commit date
helper 1 year ago importers 1 year ago list-tables 1 year ago marketplace-suggestions 1 year ago meta-boxes 1 year ago notes 1 year ago plugin-updates 1 year ago reports 1 year ago settings 1 year ago views 1 year ago class-wc-admin-addons.php 1 year ago class-wc-admin-api-keys-table-list.php 1 year ago class-wc-admin-api-keys.php 1 year ago class-wc-admin-assets.php 1 year ago class-wc-admin-attributes.php 1 year ago class-wc-admin-customize.php 1 year ago class-wc-admin-dashboard-setup.php 1 year ago class-wc-admin-dashboard.php 1 year ago class-wc-admin-duplicate-product.php 1 year ago class-wc-admin-exporters.php 1 year ago class-wc-admin-help.php 1 year ago class-wc-admin-importers.php 1 year ago class-wc-admin-log-table-list.php 1 year ago class-wc-admin-marketplace-promotions.php 1 year ago class-wc-admin-menus.php 1 year ago class-wc-admin-meta-boxes.php 1 year ago class-wc-admin-notices.php 1 year ago class-wc-admin-permalink-settings.php 1 year ago class-wc-admin-pointers.php 1 year ago class-wc-admin-post-types.php 1 year ago class-wc-admin-profile.php 1 year ago class-wc-admin-reports.php 1 year ago class-wc-admin-settings.php 1 year ago class-wc-admin-setup-wizard.php 1 year ago class-wc-admin-status.php 1 year ago class-wc-admin-taxonomies.php 1 year ago class-wc-admin-upload-downloadable-product.php 1 year ago class-wc-admin-webhooks-table-list.php 1 year ago class-wc-admin-webhooks.php 1 year ago class-wc-admin.php 1 year ago wc-admin-functions.php 1 year ago wc-meta-box-functions.php 1 year ago
class-wc-admin-profile.php
272 lines
1 <?php
2 /**
3 * Add extra profile fields for users in admin
4 *
5 * @author WooThemes
6 * @category Admin
7 * @package WooCommerce\Admin
8 * @version 2.4.0
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly
13 }
14
15 if ( ! class_exists( 'WC_Admin_Profile', false ) ) :
16
17 /**
18 * WC_Admin_Profile Class.
19 */
20 class WC_Admin_Profile {
21
22 /**
23 * Hook in tabs.
24 */
25 public function __construct() {
26 add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ) );
27 add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ) );
28
29 add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) );
30 add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) );
31 }
32
33 /**
34 * Get Address Fields for the edit user pages.
35 *
36 * @return array Fields to display which are filtered through woocommerce_customer_meta_fields before being returned
37 */
38 public function get_customer_meta_fields() {
39 $show_fields = apply_filters(
40 'woocommerce_customer_meta_fields',
41 array(
42 'billing' => array(
43 'title' => __( 'Customer billing address', 'woocommerce' ),
44 'fields' => array(
45 'billing_first_name' => array(
46 'label' => __( 'First name', 'woocommerce' ),
47 'description' => '',
48 ),
49 'billing_last_name' => array(
50 'label' => __( 'Last name', 'woocommerce' ),
51 'description' => '',
52 ),
53 'billing_company' => array(
54 'label' => __( 'Company', 'woocommerce' ),
55 'description' => '',
56 ),
57 'billing_address_1' => array(
58 'label' => __( 'Address line 1', 'woocommerce' ),
59 'description' => '',
60 ),
61 'billing_address_2' => array(
62 'label' => __( 'Address line 2', 'woocommerce' ),
63 'description' => '',
64 ),
65 'billing_city' => array(
66 'label' => __( 'City', 'woocommerce' ),
67 'description' => '',
68 ),
69 'billing_postcode' => array(
70 'label' => __( 'Postcode / ZIP', 'woocommerce' ),
71 'description' => '',
72 ),
73 'billing_country' => array(
74 'label' => __( 'Country / Region', 'woocommerce' ),
75 'description' => '',
76 'class' => 'js_field-country',
77 'type' => 'select',
78 'options' => array( '' => __( 'Select a country / region&hellip;', 'woocommerce' ) ) + WC()->countries->get_allowed_countries(),
79 ),
80 'billing_state' => array(
81 'label' => __( 'State / County', 'woocommerce' ),
82 'description' => __( 'State / County or state code', 'woocommerce' ),
83 'class' => 'js_field-state',
84 ),
85 'billing_phone' => array(
86 'label' => __( 'Phone', 'woocommerce' ),
87 'description' => '',
88 ),
89 'billing_email' => array(
90 'label' => __( 'Email address', 'woocommerce' ),
91 'description' => '',
92 ),
93 ),
94 ),
95 'shipping' => array(
96 'title' => __( 'Customer shipping address', 'woocommerce' ),
97 'fields' => array(
98 'copy_billing' => array(
99 'label' => __( 'Copy from billing address', 'woocommerce' ),
100 'description' => '',
101 'class' => 'js_copy-billing',
102 'type' => 'button',
103 'text' => __( 'Copy', 'woocommerce' ),
104 ),
105 'shipping_first_name' => array(
106 'label' => __( 'First name', 'woocommerce' ),
107 'description' => '',
108 ),
109 'shipping_last_name' => array(
110 'label' => __( 'Last name', 'woocommerce' ),
111 'description' => '',
112 ),
113 'shipping_company' => array(
114 'label' => __( 'Company', 'woocommerce' ),
115 'description' => '',
116 ),
117 'shipping_address_1' => array(
118 'label' => __( 'Address line 1', 'woocommerce' ),
119 'description' => '',
120 ),
121 'shipping_address_2' => array(
122 'label' => __( 'Address line 2', 'woocommerce' ),
123 'description' => '',
124 ),
125 'shipping_city' => array(
126 'label' => __( 'City', 'woocommerce' ),
127 'description' => '',
128 ),
129 'shipping_postcode' => array(
130 'label' => __( 'Postcode / ZIP', 'woocommerce' ),
131 'description' => '',
132 ),
133 'shipping_country' => array(
134 'label' => __( 'Country / Region', 'woocommerce' ),
135 'description' => '',
136 'class' => 'js_field-country',
137 'type' => 'select',
138 'options' => array( '' => __( 'Select a country / region&hellip;', 'woocommerce' ) ) + WC()->countries->get_allowed_countries(),
139 ),
140 'shipping_state' => array(
141 'label' => __( 'State / County', 'woocommerce' ),
142 'description' => __( 'State / County or state code', 'woocommerce' ),
143 'class' => 'js_field-state',
144 ),
145 'shipping_phone' => array(
146 'label' => __( 'Phone', 'woocommerce' ),
147 'description' => '',
148 ),
149 ),
150 ),
151 )
152 );
153 return $show_fields;
154 }
155
156 /**
157 * Show Address Fields on edit user pages.
158 *
159 * @param WP_User $user
160 */
161 public function add_customer_meta_fields( $user ) {
162 if ( ! apply_filters( 'woocommerce_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_woocommerce' ), $user->ID ) ) {
163 return;
164 }
165
166 $show_fields = $this->get_customer_meta_fields();
167
168 foreach ( $show_fields as $fieldset_key => $fieldset ) :
169 ?>
170 <h2><?php echo $fieldset['title']; ?></h2>
171 <table class="form-table" id="<?php echo esc_attr( 'fieldset-' . $fieldset_key ); ?>">
172 <?php foreach ( $fieldset['fields'] as $key => $field ) : ?>
173 <tr>
174 <th>
175 <label for="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $field['label'] ); ?></label>
176 </th>
177 <td>
178 <?php if ( ! empty( $field['type'] ) && 'select' === $field['type'] ) : ?>
179 <select name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" class="<?php echo esc_attr( $field['class'] ); ?>" style="width: 25em;">
180 <?php
181 $selected = esc_attr( get_user_meta( $user->ID, $key, true ) );
182 foreach ( $field['options'] as $option_key => $option_value ) :
183 ?>
184 <option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( $selected, $option_key, true ); ?>><?php echo esc_html( $option_value ); ?></option>
185 <?php endforeach; ?>
186 </select>
187 <?php elseif ( ! empty( $field['type'] ) && 'checkbox' === $field['type'] ) : ?>
188 <input type="checkbox" name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" value="1" class="<?php echo esc_attr( $field['class'] ); ?>" <?php checked( (int) get_user_meta( $user->ID, $key, true ), 1, true ); ?> />
189 <?php elseif ( ! empty( $field['type'] ) && 'button' === $field['type'] ) : ?>
190 <button type="button" id="<?php echo esc_attr( $key ); ?>" class="button <?php echo esc_attr( $field['class'] ); ?>"><?php echo esc_html( $field['text'] ); ?></button>
191 <?php else : ?>
192 <input type="text" name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $this->get_user_meta( $user->ID, $key ) ); ?>" class="<?php echo ( ! empty( $field['class'] ) ? esc_attr( $field['class'] ) : 'regular-text' ); ?>" />
193 <?php endif; ?>
194 <p class="description"><?php echo wp_kses_post( $field['description'] ); ?></p>
195 </td>
196 </tr>
197 <?php endforeach; ?>
198 </table>
199 <?php
200 endforeach;
201 }
202
203 /**
204 * Save Address Fields on edit user pages.
205 *
206 * @param int $user_id User ID of the user being saved
207 */
208 public function save_customer_meta_fields( $user_id ) {
209 if ( ! apply_filters( 'woocommerce_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_woocommerce' ), $user_id ) ) {
210 return;
211 }
212
213 $save_fields = $this->get_customer_meta_fields();
214
215 foreach ( $save_fields as $fieldset_type => $fieldset ) {
216
217 foreach ( $fieldset['fields'] as $key => $field ) {
218
219 if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) {
220 update_user_meta( $user_id, $key, isset( $_POST[ $key ] ) );
221 } elseif ( isset( $_POST[ $key ] ) ) {
222 update_user_meta( $user_id, $key, wc_clean( $_POST[ $key ] ) );
223 }
224 }
225
226 // Skip firing the action for any non-internal fieldset types.
227 if ( ! in_array( $fieldset_type, array( 'billing', 'shipping' ), true ) ) {
228 continue;
229 }
230
231 // Fieldset type is an internal address type.
232 $address_type = $fieldset_type;
233
234 /**
235 * Hook: woocommerce_customer_save_address.
236 *
237 * Fires after a customer address has been saved on the user profile admin screen.
238 *
239 * @since 8.5.0
240 * @param int $user_id User ID being saved.
241 * @param string $address_type Type of address; 'billing' or 'shipping'.
242 */
243 do_action( 'woocommerce_customer_save_address', $user_id, $address_type );
244 }
245 }
246
247 /**
248 * Get user meta for a given key, with fallbacks to core user info for pre-existing fields.
249 *
250 * @since 3.1.0
251 * @param int $user_id User ID of the user being edited
252 * @param string $key Key for user meta field
253 * @return string
254 */
255 protected function get_user_meta( $user_id, $key ) {
256 $value = get_user_meta( $user_id, $key, true );
257 $existing_fields = array( 'billing_first_name', 'billing_last_name' );
258 if ( ! $value && in_array( $key, $existing_fields ) ) {
259 $value = get_user_meta( $user_id, str_replace( 'billing_', '', $key ), true );
260 } elseif ( ! $value && ( 'billing_email' === $key ) ) {
261 $user = get_userdata( $user_id );
262 $value = $user->user_email;
263 }
264
265 return $value;
266 }
267 }
268
269 endif;
270
271 return new WC_Admin_Profile();
272