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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 / class-wc-countries.php
woocommerce / includes Last commit date
abstracts 6 years ago admin 6 years ago api 6 years ago blocks 7 years ago cli 7 years ago customizer 8 years ago data-stores 6 years ago emails 7 years ago export 7 years ago gateways 7 years ago import 7 years ago interfaces 7 years ago legacy 7 years ago libraries 6 years ago log-handlers 7 years ago payment-tokens 8 years ago queue 7 years ago shipping 7 years ago shortcodes 6 years ago theme-support 7 years ago tracks 6 years ago walkers 8 years ago widgets 6 years ago class-wc-ajax.php 6 years ago class-wc-api.php 7 years ago class-wc-auth.php 7 years ago class-wc-autoloader.php 6 years ago class-wc-background-emailer.php 8 years ago class-wc-background-updater.php 7 years ago class-wc-breadcrumb.php 7 years ago class-wc-cache-helper.php 7 years ago class-wc-cart-fees.php 8 years ago class-wc-cart-session.php 7 years ago class-wc-cart-totals.php 7 years ago class-wc-cart.php 7 years ago class-wc-checkout.php 7 years ago class-wc-cli.php 8 years ago class-wc-comments.php 7 years ago class-wc-countries.php 6 years ago class-wc-coupon.php 7 years ago class-wc-customer-download-log.php 8 years ago class-wc-customer-download.php 8 years ago class-wc-customer.php 7 years ago class-wc-data-exception.php 8 years ago class-wc-data-store.php 7 years ago class-wc-datetime.php 7 years ago class-wc-deprecated-action-hooks.php 8 years ago class-wc-deprecated-filter-hooks.php 7 years ago class-wc-discounts.php 7 years ago class-wc-download-handler.php 6 years ago class-wc-emails.php 7 years ago class-wc-embed.php 8 years ago class-wc-form-handler.php 6 years ago class-wc-frontend-scripts.php 7 years ago class-wc-geo-ip.php 8 years ago class-wc-geolite-integration.php 7 years ago class-wc-geolocation.php 7 years ago class-wc-https.php 8 years ago class-wc-install.php 6 years ago class-wc-integrations.php 8 years ago class-wc-log-levels.php 7 years ago class-wc-logger.php 7 years ago class-wc-meta-data.php 7 years ago class-wc-order-factory.php 8 years ago class-wc-order-item-coupon.php 7 years ago class-wc-order-item-fee.php 7 years ago class-wc-order-item-meta.php 7 years ago class-wc-order-item-product.php 7 years ago class-wc-order-item-shipping.php 7 years ago class-wc-order-item-tax.php 8 years ago class-wc-order-item.php 6 years ago class-wc-order-query.php 7 years ago class-wc-order-refund.php 8 years ago class-wc-order.php 7 years ago class-wc-payment-gateways.php 7 years ago class-wc-payment-tokens.php 7 years ago class-wc-post-data.php 7 years ago class-wc-post-types.php 7 years ago class-wc-privacy-background-process.php 8 years ago class-wc-privacy-erasers.php 8 years ago class-wc-privacy-exporters.php 7 years ago class-wc-privacy.php 7 years ago class-wc-product-attribute.php 7 years ago class-wc-product-download.php 7 years ago class-wc-product-external.php 8 years ago class-wc-product-factory.php 7 years ago class-wc-product-grouped.php 8 years ago class-wc-product-query.php 7 years ago class-wc-product-simple.php 8 years ago class-wc-product-variable.php 7 years ago class-wc-product-variation.php 7 years ago class-wc-query.php 7 years ago class-wc-regenerate-images-request.php 7 years ago class-wc-regenerate-images.php 7 years ago class-wc-register-wp-admin-settings.php 8 years ago class-wc-session-handler.php 7 years ago class-wc-shipping-rate.php 8 years ago class-wc-shipping-zone.php 7 years ago class-wc-shipping-zones.php 8 years ago class-wc-shipping.php 7 years ago class-wc-shortcodes.php 7 years ago class-wc-structured-data.php 6 years ago class-wc-tax.php 7 years ago class-wc-template-loader.php 7 years ago class-wc-tracker.php 6 years ago class-wc-validation.php 6 years ago class-wc-webhook.php 7 years ago class-woocommerce.php 6 years ago wc-account-functions.php 7 years ago wc-attribute-functions.php 7 years ago wc-cart-functions.php 7 years ago wc-conditional-functions.php 6 years ago wc-core-functions.php 7 years ago wc-coupon-functions.php 7 years ago wc-deprecated-functions.php 7 years ago wc-formatting-functions.php 6 years ago wc-notice-functions.php 7 years ago wc-order-functions.php 7 years ago wc-order-item-functions.php 7 years ago wc-page-functions.php 7 years ago wc-product-functions.php 7 years ago wc-rest-functions.php 7 years ago wc-stock-functions.php 7 years ago wc-template-functions.php 7 years ago wc-template-hooks.php 7 years ago wc-term-functions.php 7 years ago wc-update-functions.php 7 years ago wc-user-functions.php 7 years ago wc-webhook-functions.php 7 years ago wc-widget-functions.php 8 years ago
class-wc-countries.php
1340 lines
1 <?php
2 /**
3 * WooCommerce countries
4 *
5 * @package WooCommerce\l10n
6 * @version 3.3.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * The WooCommerce countries class stores country/state data.
13 */
14 class WC_Countries {
15
16 /**
17 * Locales list.
18 *
19 * @var array
20 */
21 public $locale = array();
22
23 /**
24 * List of address formats for locales.
25 *
26 * @var array
27 */
28 public $address_formats = array();
29
30 /**
31 * Auto-load in-accessible properties on demand.
32 *
33 * @param mixed $key Key.
34 * @return mixed
35 */
36 public function __get( $key ) {
37 if ( 'countries' === $key ) {
38 return $this->get_countries();
39 } elseif ( 'states' === $key ) {
40 return $this->get_states();
41 }
42 }
43
44 /**
45 * Get all countries.
46 *
47 * @return array
48 */
49 public function get_countries() {
50 if ( empty( $this->countries ) ) {
51 $this->countries = apply_filters( 'woocommerce_countries', include WC()->plugin_path() . '/i18n/countries.php' );
52 if ( apply_filters( 'woocommerce_sort_countries', true ) ) {
53 uasort( $this->countries, 'wc_ascii_uasort_comparison' );
54 }
55 }
56
57 return $this->countries;
58 }
59
60 /**
61 * Get all continents.
62 *
63 * @return array
64 */
65 public function get_continents() {
66 if ( empty( $this->continents ) ) {
67 $this->continents = apply_filters( 'woocommerce_continents', include WC()->plugin_path() . '/i18n/continents.php' );
68 }
69
70 return $this->continents;
71 }
72
73 /**
74 * Get continent code for a country code.
75 *
76 * @since 2.6.0
77 * @param string $cc Country code.
78 * @return string
79 */
80 public function get_continent_code_for_country( $cc ) {
81 $cc = trim( strtoupper( $cc ) );
82 $continents = $this->get_continents();
83 $continents_and_ccs = wp_list_pluck( $continents, 'countries' );
84 foreach ( $continents_and_ccs as $continent_code => $countries ) {
85 if ( false !== array_search( $cc, $countries, true ) ) {
86 return $continent_code;
87 }
88 }
89
90 return '';
91 }
92
93 /**
94 * Get calling code for a country code.
95 *
96 * @since 3.6.0
97 * @param string $cc Country code.
98 * @return string|array Some countries have multiple. The code will be stripped of - and spaces and always be prefixed with +.
99 */
100 public function get_country_calling_code( $cc ) {
101 $codes = wp_cache_get( 'calling-codes', 'countries' );
102
103 if ( ! $codes ) {
104 $codes = include WC()->plugin_path() . '/i18n/phone.php';
105 wp_cache_set( 'calling-codes', $codes, 'countries' );
106 }
107
108 $calling_code = isset( $codes[ $cc ] ) ? $codes[ $cc ] : '';
109
110 if ( is_array( $calling_code ) ) {
111 $calling_code = $calling_code[0];
112 }
113
114 return $calling_code;
115 }
116
117 /**
118 * Get continents that the store ships to.
119 *
120 * @since 3.6.0
121 * @return array
122 */
123 public function get_shipping_continents() {
124 $continents = $this->get_continents();
125 $shipping_countries = $this->get_shipping_countries();
126 $shipping_country_codes = array_keys( $shipping_countries );
127 $shipping_continents = array();
128
129 foreach ( $continents as $continent_code => $continent ) {
130 if ( count( array_intersect( $continent['countries'], $shipping_country_codes ) ) ) {
131 $shipping_continents[ $continent_code ] = $continent;
132 }
133 }
134
135 return $shipping_continents;
136 }
137
138 /**
139 * Load the states.
140 *
141 * @deprecated 3.6.0 This method was used to load state files, but is no longer needed. @see get_states().
142 */
143 public function load_country_states() {
144 global $states;
145
146 $states = include WC()->plugin_path() . '/i18n/states.php';
147 $this->states = apply_filters( 'woocommerce_states', $states );
148 }
149
150 /**
151 * Get the states for a country.
152 *
153 * @param string $cc Country code.
154 * @return false|array of states
155 */
156 public function get_states( $cc = null ) {
157 if ( ! isset( $this->states ) ) {
158 $this->states = apply_filters( 'woocommerce_states', include WC()->plugin_path() . '/i18n/states.php' );
159 }
160
161 if ( ! is_null( $cc ) ) {
162 return isset( $this->states[ $cc ] ) ? $this->states[ $cc ] : false;
163 } else {
164 return $this->states;
165 }
166 }
167
168 /**
169 * Get the base address (first line) for the store.
170 *
171 * @since 3.1.1
172 * @return string
173 */
174 public function get_base_address() {
175 $base_address = get_option( 'woocommerce_store_address', '' );
176 return apply_filters( 'woocommerce_countries_base_address', $base_address );
177 }
178
179 /**
180 * Get the base address (second line) for the store.
181 *
182 * @since 3.1.1
183 * @return string
184 */
185 public function get_base_address_2() {
186 $base_address_2 = get_option( 'woocommerce_store_address_2', '' );
187 return apply_filters( 'woocommerce_countries_base_address_2', $base_address_2 );
188 }
189
190 /**
191 * Get the base country for the store.
192 *
193 * @return string
194 */
195 public function get_base_country() {
196 $default = wc_get_base_location();
197 return apply_filters( 'woocommerce_countries_base_country', $default['country'] );
198 }
199
200 /**
201 * Get the base state for the store.
202 *
203 * @return string
204 */
205 public function get_base_state() {
206 $default = wc_get_base_location();
207 return apply_filters( 'woocommerce_countries_base_state', $default['state'] );
208 }
209
210 /**
211 * Get the base city for the store.
212 *
213 * @version 3.1.1
214 * @return string
215 */
216 public function get_base_city() {
217 $base_city = get_option( 'woocommerce_store_city', '' );
218 return apply_filters( 'woocommerce_countries_base_city', $base_city );
219 }
220
221 /**
222 * Get the base postcode for the store.
223 *
224 * @since 3.1.1
225 * @return string
226 */
227 public function get_base_postcode() {
228 $base_postcode = get_option( 'woocommerce_store_postcode', '' );
229 return apply_filters( 'woocommerce_countries_base_postcode', $base_postcode );
230 }
231
232 /**
233 * Get countries that the store sells to.
234 *
235 * @return array
236 */
237 public function get_allowed_countries() {
238 if ( 'all' === get_option( 'woocommerce_allowed_countries' ) ) {
239 return apply_filters( 'woocommerce_countries_allowed_countries', $this->countries );
240 }
241
242 if ( 'all_except' === get_option( 'woocommerce_allowed_countries' ) ) {
243 $except_countries = get_option( 'woocommerce_all_except_countries', array() );
244
245 if ( ! $except_countries ) {
246 return $this->countries;
247 } else {
248 $all_except_countries = $this->countries;
249 foreach ( $except_countries as $country ) {
250 unset( $all_except_countries[ $country ] );
251 }
252 return apply_filters( 'woocommerce_countries_allowed_countries', $all_except_countries );
253 }
254 }
255
256 $countries = array();
257
258 $raw_countries = get_option( 'woocommerce_specific_allowed_countries', array() );
259
260 if ( $raw_countries ) {
261 foreach ( $raw_countries as $country ) {
262 $countries[ $country ] = $this->countries[ $country ];
263 }
264 }
265
266 return apply_filters( 'woocommerce_countries_allowed_countries', $countries );
267 }
268
269 /**
270 * Get countries that the store ships to.
271 *
272 * @return array
273 */
274 public function get_shipping_countries() {
275 if ( '' === get_option( 'woocommerce_ship_to_countries' ) ) {
276 return $this->get_allowed_countries();
277 }
278
279 if ( 'all' === get_option( 'woocommerce_ship_to_countries' ) ) {
280 return $this->countries;
281 }
282
283 $countries = array();
284
285 $raw_countries = get_option( 'woocommerce_specific_ship_to_countries' );
286
287 if ( $raw_countries ) {
288 foreach ( $raw_countries as $country ) {
289 $countries[ $country ] = $this->countries[ $country ];
290 }
291 }
292
293 return apply_filters( 'woocommerce_countries_shipping_countries', $countries );
294 }
295
296 /**
297 * Get allowed country states.
298 *
299 * @return array
300 */
301 public function get_allowed_country_states() {
302 if ( get_option( 'woocommerce_allowed_countries' ) !== 'specific' ) {
303 return $this->states;
304 }
305
306 $states = array();
307
308 $raw_countries = get_option( 'woocommerce_specific_allowed_countries' );
309
310 if ( $raw_countries ) {
311 foreach ( $raw_countries as $country ) {
312 if ( isset( $this->states[ $country ] ) ) {
313 $states[ $country ] = $this->states[ $country ];
314 }
315 }
316 }
317
318 return apply_filters( 'woocommerce_countries_allowed_country_states', $states );
319 }
320
321 /**
322 * Get shipping country states.
323 *
324 * @return array
325 */
326 public function get_shipping_country_states() {
327 if ( get_option( 'woocommerce_ship_to_countries' ) === '' ) {
328 return $this->get_allowed_country_states();
329 }
330
331 if ( get_option( 'woocommerce_ship_to_countries' ) !== 'specific' ) {
332 return $this->states;
333 }
334
335 $states = array();
336
337 $raw_countries = get_option( 'woocommerce_specific_ship_to_countries' );
338
339 if ( $raw_countries ) {
340 foreach ( $raw_countries as $country ) {
341 if ( ! empty( $this->states[ $country ] ) ) {
342 $states[ $country ] = $this->states[ $country ];
343 }
344 }
345 }
346
347 return apply_filters( 'woocommerce_countries_shipping_country_states', $states );
348 }
349
350 /**
351 * Gets an array of countries in the EU.
352 *
353 * MC (monaco) and IM (isle of man, part of UK) also use VAT.
354 *
355 * @param string $type Type of countries to retrieve. Blank for EU member countries. eu_vat for EU VAT countries.
356 * @return string[]
357 */
358 public function get_european_union_countries( $type = '' ) {
359 $countries = array( 'AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HU', 'HR', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK' );
360
361 if ( 'eu_vat' === $type ) {
362 $countries[] = 'MC';
363 $countries[] = 'IM';
364 }
365
366 return $countries;
367 }
368
369 /**
370 * Gets the correct string for shipping - either 'to the' or 'to'.
371 *
372 * @param string $country_code Country code.
373 * @return string
374 */
375 public function shipping_to_prefix( $country_code = '' ) {
376 $country_code = $country_code ? $country_code : WC()->customer->get_shipping_country();
377 $countries = array( 'GB', 'US', 'AE', 'CZ', 'DO', 'NL', 'PH', 'USAF' );
378 $return = in_array( $country_code, $countries, true ) ? __( 'to the', 'woocommerce' ) : __( 'to', 'woocommerce' );
379
380 return apply_filters( 'woocommerce_countries_shipping_to_prefix', $return, $country_code );
381 }
382
383 /**
384 * Prefix certain countries with 'the'.
385 *
386 * @param string $country_code Country code.
387 * @return string
388 */
389 public function estimated_for_prefix( $country_code = '' ) {
390 $country_code = $country_code ? $country_code : $this->get_base_country();
391 $countries = array( 'GB', 'US', 'AE', 'CZ', 'DO', 'NL', 'PH', 'USAF' );
392 $return = in_array( $country_code, $countries, true ) ? __( 'the', 'woocommerce' ) . ' ' : '';
393
394 return apply_filters( 'woocommerce_countries_estimated_for_prefix', $return, $country_code );
395 }
396
397 /**
398 * Correctly name tax in some countries VAT on the frontend.
399 *
400 * @return string
401 */
402 public function tax_or_vat() {
403 $return = in_array( $this->get_base_country(), array_merge( $this->get_european_union_countries( 'eu_vat' ), array( 'NO' ) ), true ) ? __( 'VAT', 'woocommerce' ) : __( 'Tax', 'woocommerce' );
404
405 return apply_filters( 'woocommerce_countries_tax_or_vat', $return );
406 }
407
408 /**
409 * Include the Inc Tax label.
410 *
411 * @return string
412 */
413 public function inc_tax_or_vat() {
414 $return = in_array( $this->get_base_country(), array_merge( $this->get_european_union_countries( 'eu_vat' ), array( 'NO' ) ), true ) ? __( '(incl. VAT)', 'woocommerce' ) : __( '(incl. tax)', 'woocommerce' );
415
416 return apply_filters( 'woocommerce_countries_inc_tax_or_vat', $return );
417 }
418
419 /**
420 * Include the Ex Tax label.
421 *
422 * @return string
423 */
424 public function ex_tax_or_vat() {
425 $return = in_array( $this->get_base_country(), array_merge( $this->get_european_union_countries( 'eu_vat' ), array( 'NO' ) ), true ) ? __( '(ex. VAT)', 'woocommerce' ) : __( '(ex. tax)', 'woocommerce' );
426
427 return apply_filters( 'woocommerce_countries_ex_tax_or_vat', $return );
428 }
429
430 /**
431 * Outputs the list of countries and states for use in dropdown boxes.
432 *
433 * @param string $selected_country Selected country.
434 * @param string $selected_state Selected state.
435 * @param bool $escape If we should escape HTML.
436 */
437 public function country_dropdown_options( $selected_country = '', $selected_state = '', $escape = false ) {
438 if ( $this->countries ) {
439 foreach ( $this->countries as $key => $value ) {
440 $states = $this->get_states( $key );
441 if ( $states ) {
442 echo '<optgroup label="' . esc_attr( $value ) . '">';
443 foreach ( $states as $state_key => $state_value ) {
444 echo '<option value="' . esc_attr( $key ) . ':' . esc_attr( $state_key ) . '"';
445
446 if ( $selected_country === $key && $selected_state === $state_key ) {
447 echo ' selected="selected"';
448 }
449
450 echo '>' . esc_html( $value ) . ' &mdash; ' . ( $escape ? esc_js( $state_value ) : $state_value ) . '</option>'; // WPCS: XSS ok.
451 }
452 echo '</optgroup>';
453 } else {
454 echo '<option';
455 if ( $selected_country === $key && '*' === $selected_state ) {
456 echo ' selected="selected"';
457 }
458 echo ' value="' . esc_attr( $key ) . '">' . ( $escape ? esc_js( $value ) : $value ) . '</option>'; // WPCS: XSS ok.
459 }
460 }
461 }
462 }
463
464 /**
465 * Get country address formats.
466 *
467 * These define how addresses are formatted for display in various countries.
468 *
469 * @return array
470 */
471 public function get_address_formats() {
472 if ( empty( $this->address_formats ) ) {
473 $this->address_formats = apply_filters(
474 'woocommerce_localisation_address_formats',
475 array(
476 'default' => "{name}\n{company}\n{address_1}\n{address_2}\n{city}\n{state}\n{postcode}\n{country}",
477 'AU' => "{name}\n{company}\n{address_1}\n{address_2}\n{city} {state} {postcode}\n{country}",
478 'AT' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
479 'BE' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
480 'CA' => "{company}\n{name}\n{address_1}\n{address_2}\n{city} {state_code}&nbsp;&nbsp;{postcode}\n{country}",
481 'CH' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
482 'CL' => "{company}\n{name}\n{address_1}\n{address_2}\n{state}\n{postcode} {city}\n{country}",
483 'CN' => "{country} {postcode}\n{state}, {city}, {address_2}, {address_1}\n{company}\n{name}",
484 'CZ' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
485 'DE' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
486 'EE' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
487 'FI' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
488 'DK' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
489 'FR' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city_upper}\n{country}",
490 'HK' => "{company}\n{first_name} {last_name_upper}\n{address_1}\n{address_2}\n{city_upper}\n{state_upper}\n{country}",
491 'HU' => "{name}\n{company}\n{city}\n{address_1}\n{address_2}\n{postcode}\n{country}",
492 'IN' => "{company}\n{name}\n{address_1}\n{address_2}\n{city} {postcode}\n{state}, {country}",
493 'IS' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
494 'IT' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode}\n{city}\n{state_upper}\n{country}",
495 'JP' => "{postcode}\n{state} {city} {address_1}\n{address_2}\n{company}\n{last_name} {first_name}\n{country}",
496 'TW' => "{company}\n{last_name} {first_name}\n{address_1}\n{address_2}\n{state}, {city} {postcode}\n{country}",
497 'LI' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
498 'NL' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
499 'NZ' => "{name}\n{company}\n{address_1}\n{address_2}\n{city} {postcode}\n{country}",
500 'NO' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
501 'PL' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
502 'PT' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
503 'SK' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
504 'RS' => "{name}\n{company}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
505 'SI' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
506 'ES' => "{name}\n{company}\n{address_1}\n{address_2}\n{postcode} {city}\n{state}\n{country}",
507 'SE' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
508 'TR' => "{name}\n{company}\n{address_1}\n{address_2}\n{postcode} {city} {state}\n{country}",
509 'US' => "{name}\n{company}\n{address_1}\n{address_2}\n{city}, {state_code} {postcode}\n{country}",
510 'VN' => "{name}\n{company}\n{address_1}\n{city}\n{country}",
511 )
512 );
513 }
514 return $this->address_formats;
515 }
516
517 /**
518 * Get country address format.
519 *
520 * @param array $args Arguments.
521 * @param string $separator How to separate address lines. @since 3.5.0.
522 * @return string
523 */
524 public function get_formatted_address( $args = array(), $separator = '<br/>' ) {
525 $default_args = array(
526 'first_name' => '',
527 'last_name' => '',
528 'company' => '',
529 'address_1' => '',
530 'address_2' => '',
531 'city' => '',
532 'state' => '',
533 'postcode' => '',
534 'country' => '',
535 );
536
537 $args = array_map( 'trim', wp_parse_args( $args, $default_args ) );
538 $state = $args['state'];
539 $country = $args['country'];
540
541 // Get all formats.
542 $formats = $this->get_address_formats();
543
544 // Get format for the address' country.
545 $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
546
547 // Handle full country name.
548 $full_country = ( isset( $this->countries[ $country ] ) ) ? $this->countries[ $country ] : $country;
549
550 // Country is not needed if the same as base.
551 if ( $country === $this->get_base_country() && ! apply_filters( 'woocommerce_formatted_address_force_country_display', false ) ) {
552 $format = str_replace( '{country}', '', $format );
553 }
554
555 // Handle full state name.
556 $full_state = ( $country && $state && isset( $this->states[ $country ][ $state ] ) ) ? $this->states[ $country ][ $state ] : $state;
557
558 // Substitute address parts into the string.
559 $replace = array_map(
560 'esc_html',
561 apply_filters(
562 'woocommerce_formatted_address_replacements',
563 array(
564 '{first_name}' => $args['first_name'],
565 '{last_name}' => $args['last_name'],
566 '{name}' => $args['first_name'] . ' ' . $args['last_name'],
567 '{company}' => $args['company'],
568 '{address_1}' => $args['address_1'],
569 '{address_2}' => $args['address_2'],
570 '{city}' => $args['city'],
571 '{state}' => $full_state,
572 '{postcode}' => $args['postcode'],
573 '{country}' => $full_country,
574 '{first_name_upper}' => wc_strtoupper( $args['first_name'] ),
575 '{last_name_upper}' => wc_strtoupper( $args['last_name'] ),
576 '{name_upper}' => wc_strtoupper( $args['first_name'] . ' ' . $args['last_name'] ),
577 '{company_upper}' => wc_strtoupper( $args['company'] ),
578 '{address_1_upper}' => wc_strtoupper( $args['address_1'] ),
579 '{address_2_upper}' => wc_strtoupper( $args['address_2'] ),
580 '{city_upper}' => wc_strtoupper( $args['city'] ),
581 '{state_upper}' => wc_strtoupper( $full_state ),
582 '{state_code}' => wc_strtoupper( $state ),
583 '{postcode_upper}' => wc_strtoupper( $args['postcode'] ),
584 '{country_upper}' => wc_strtoupper( $full_country ),
585 ),
586 $args
587 )
588 );
589
590 $formatted_address = str_replace( array_keys( $replace ), $replace, $format );
591
592 // Clean up white space.
593 $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) );
594 $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
595
596 // Break newlines apart and remove empty lines/trim commas and white space.
597 $formatted_address = array_filter( array_map( array( $this, 'trim_formatted_address_line' ), explode( "\n", $formatted_address ) ) );
598
599 // Add html breaks.
600 $formatted_address = implode( $separator, $formatted_address );
601
602 // We're done!
603 return $formatted_address;
604 }
605
606 /**
607 * Trim white space and commas off a line.
608 *
609 * @param string $line Line.
610 * @return string
611 */
612 private function trim_formatted_address_line( $line ) {
613 return trim( $line, ', ' );
614 }
615
616 /**
617 * Returns the fields we show by default. This can be filtered later on.
618 *
619 * @return array
620 */
621 public function get_default_address_fields() {
622 if ( 'optional' === get_option( 'woocommerce_checkout_address_2_field', 'optional' ) ) {
623 $address_2_placeholder = __( 'Apartment, suite, unit etc. (optional)', 'woocommerce' );
624 } else {
625 $address_2_placeholder = __( 'Apartment, suite, unit etc.', 'woocommerce' );
626 }
627
628 $fields = array(
629 'first_name' => array(
630 'label' => __( 'First name', 'woocommerce' ),
631 'required' => true,
632 'class' => array( 'form-row-first' ),
633 'autocomplete' => 'given-name',
634 'priority' => 10,
635 ),
636 'last_name' => array(
637 'label' => __( 'Last name', 'woocommerce' ),
638 'required' => true,
639 'class' => array( 'form-row-last' ),
640 'autocomplete' => 'family-name',
641 'priority' => 20,
642 ),
643 'company' => array(
644 'label' => __( 'Company name', 'woocommerce' ),
645 'class' => array( 'form-row-wide' ),
646 'autocomplete' => 'organization',
647 'priority' => 30,
648 'required' => 'required' === get_option( 'woocommerce_checkout_company_field', 'optional' ),
649 ),
650 'country' => array(
651 'type' => 'country',
652 'label' => __( 'Country', 'woocommerce' ),
653 'required' => true,
654 'class' => array( 'form-row-wide', 'address-field', 'update_totals_on_change' ),
655 'autocomplete' => 'country',
656 'priority' => 40,
657 ),
658 'address_1' => array(
659 'label' => __( 'Street address', 'woocommerce' ),
660 /* translators: use local order of street name and house number. */
661 'placeholder' => esc_attr__( 'House number and street name', 'woocommerce' ),
662 'required' => true,
663 'class' => array( 'form-row-wide', 'address-field' ),
664 'autocomplete' => 'address-line1',
665 'priority' => 50,
666 ),
667 'address_2' => array(
668 'placeholder' => esc_attr( $address_2_placeholder ),
669 'class' => array( 'form-row-wide', 'address-field' ),
670 'autocomplete' => 'address-line2',
671 'priority' => 60,
672 'required' => 'required' === get_option( 'woocommerce_checkout_address_2_field', 'optional' ),
673 ),
674 'city' => array(
675 'label' => __( 'Town / City', 'woocommerce' ),
676 'required' => true,
677 'class' => array( 'form-row-wide', 'address-field' ),
678 'autocomplete' => 'address-level2',
679 'priority' => 70,
680 ),
681 'state' => array(
682 'type' => 'state',
683 'label' => __( 'State / County', 'woocommerce' ),
684 'required' => true,
685 'class' => array( 'form-row-wide', 'address-field' ),
686 'validate' => array( 'state' ),
687 'autocomplete' => 'address-level1',
688 'priority' => 80,
689 ),
690 'postcode' => array(
691 'label' => __( 'Postcode / ZIP', 'woocommerce' ),
692 'required' => true,
693 'class' => array( 'form-row-wide', 'address-field' ),
694 'validate' => array( 'postcode' ),
695 'autocomplete' => 'postal-code',
696 'priority' => 90,
697 ),
698 );
699
700 if ( 'hidden' === get_option( 'woocommerce_checkout_company_field', 'optional' ) ) {
701 unset( $fields['company'] );
702 }
703
704 if ( 'hidden' === get_option( 'woocommerce_checkout_address_2_field', 'optional' ) ) {
705 unset( $fields['address_2'] );
706 }
707
708 $default_address_fields = apply_filters( 'woocommerce_default_address_fields', $fields );
709 // Sort each of the fields based on priority.
710 uasort( $default_address_fields, 'wc_checkout_fields_uasort_comparison' );
711
712 return $default_address_fields;
713 }
714
715 /**
716 * Get JS selectors for fields which are shown/hidden depending on the locale.
717 *
718 * @return array
719 */
720 public function get_country_locale_field_selectors() {
721 $locale_fields = array(
722 'address_1' => '#billing_address_1_field, #shipping_address_1_field',
723 'address_2' => '#billing_address_2_field, #shipping_address_2_field',
724 'state' => '#billing_state_field, #shipping_state_field, #calc_shipping_state_field',
725 'postcode' => '#billing_postcode_field, #shipping_postcode_field, #calc_shipping_postcode_field',
726 'city' => '#billing_city_field, #shipping_city_field, #calc_shipping_city_field',
727 );
728 return apply_filters( 'woocommerce_country_locale_field_selectors', $locale_fields );
729 }
730
731 /**
732 * Get country locale settings.
733 *
734 * These locales override the default country selections after a country is chosen.
735 *
736 * @return array
737 */
738 public function get_country_locale() {
739 if ( empty( $this->locale ) ) {
740 $this->locale = apply_filters(
741 'woocommerce_get_country_locale',
742 array(
743 'AE' => array(
744 'postcode' => array(
745 'required' => false,
746 'hidden' => true,
747 ),
748 'state' => array(
749 'required' => false,
750 ),
751 ),
752 'AF' => array(
753 'state' => array(
754 'required' => false,
755 ),
756 ),
757 'AO' => array(
758 'postcode' => array(
759 'required' => false,
760 'hidden' => true,
761 ),
762 'state' => array(
763 'label' => __( 'Province', 'woocommerce' ),
764 ),
765 ),
766 'AT' => array(
767 'postcode' => array(
768 'priority' => 65,
769 ),
770 'state' => array(
771 'required' => false,
772 ),
773 ),
774 'AU' => array(
775 'city' => array(
776 'label' => __( 'Suburb', 'woocommerce' ),
777 ),
778 'postcode' => array(
779 'label' => __( 'Postcode', 'woocommerce' ),
780 ),
781 'state' => array(
782 'label' => __( 'State', 'woocommerce' ),
783 ),
784 ),
785 'AX' => array(
786 'postcode' => array(
787 'priority' => 65,
788 ),
789 'state' => array(
790 'required' => false,
791 ),
792 ),
793 'BD' => array(
794 'postcode' => array(
795 'required' => false,
796 ),
797 'state' => array(
798 'label' => __( 'District', 'woocommerce' ),
799 ),
800 ),
801 'BE' => array(
802 'postcode' => array(
803 'priority' => 65,
804 ),
805 'state' => array(
806 'required' => false,
807 'label' => __( 'Province', 'woocommerce' ),
808 ),
809 ),
810 'BH' => array(
811 'postcode' => array(
812 'required' => false,
813 ),
814 'state' => array(
815 'required' => false,
816 ),
817 ),
818 'BI' => array(
819 'state' => array(
820 'required' => false,
821 ),
822 ),
823 'BO' => array(
824 'postcode' => array(
825 'required' => false,
826 'hidden' => true,
827 ),
828 ),
829 'BS' => array(
830 'postcode' => array(
831 'required' => false,
832 'hidden' => true,
833 ),
834 ),
835 'CA' => array(
836 'state' => array(
837 'label' => __( 'Province', 'woocommerce' ),
838 ),
839 ),
840 'CH' => array(
841 'postcode' => array(
842 'priority' => 65,
843 ),
844 'state' => array(
845 'label' => __( 'Canton', 'woocommerce' ),
846 'required' => false,
847 ),
848 ),
849 'CL' => array(
850 'city' => array(
851 'required' => true,
852 ),
853 'postcode' => array(
854 'required' => false,
855 ),
856 'state' => array(
857 'label' => __( 'Region', 'woocommerce' ),
858 ),
859 ),
860 'CN' => array(
861 'state' => array(
862 'label' => __( 'Province', 'woocommerce' ),
863 ),
864 ),
865 'CO' => array(
866 'postcode' => array(
867 'required' => false,
868 ),
869 ),
870 'CZ' => array(
871 'state' => array(
872 'required' => false,
873 ),
874 ),
875 'DE' => array(
876 'postcode' => array(
877 'priority' => 65,
878 ),
879 'state' => array(
880 'required' => false,
881 ),
882 ),
883 'DK' => array(
884 'postcode' => array(
885 'priority' => 65,
886 ),
887 'state' => array(
888 'required' => false,
889 ),
890 ),
891 'EE' => array(
892 'postcode' => array(
893 'priority' => 65,
894 ),
895 'state' => array(
896 'required' => false,
897 ),
898 ),
899 'FI' => array(
900 'postcode' => array(
901 'priority' => 65,
902 ),
903 'state' => array(
904 'required' => false,
905 ),
906 ),
907 'FR' => array(
908 'postcode' => array(
909 'priority' => 65,
910 ),
911 'state' => array(
912 'required' => false,
913 ),
914 ),
915 'GP' => array(
916 'state' => array(
917 'required' => false,
918 ),
919 ),
920 'GF' => array(
921 'state' => array(
922 'required' => false,
923 ),
924 ),
925 'GR' => array(
926 'state' => array(
927 'required' => false,
928 ),
929 ),
930 'HK' => array(
931 'postcode' => array(
932 'required' => false,
933 ),
934 'city' => array(
935 'label' => __( 'Town / District', 'woocommerce' ),
936 ),
937 'state' => array(
938 'label' => __( 'Region', 'woocommerce' ),
939 ),
940 ),
941 'HU' => array(
942 'state' => array(
943 'label' => __( 'County', 'woocommerce' ),
944 ),
945 ),
946 'ID' => array(
947 'state' => array(
948 'label' => __( 'Province', 'woocommerce' ),
949 ),
950 ),
951 'IE' => array(
952 'postcode' => array(
953 'required' => false,
954 'label' => __( 'Eircode', 'woocommerce' ),
955 ),
956 'state' => array(
957 'label' => __( 'County', 'woocommerce' ),
958 ),
959 ),
960 'IS' => array(
961 'postcode' => array(
962 'priority' => 65,
963 ),
964 'state' => array(
965 'required' => false,
966 ),
967 ),
968 'IL' => array(
969 'postcode' => array(
970 'priority' => 65,
971 ),
972 'state' => array(
973 'required' => false,
974 ),
975 ),
976 'IM' => array(
977 'state' => array(
978 'required' => false,
979 ),
980 ),
981 'IT' => array(
982 'postcode' => array(
983 'priority' => 65,
984 ),
985 'state' => array(
986 'required' => true,
987 'label' => __( 'Province', 'woocommerce' ),
988 ),
989 ),
990 'JP' => array(
991 'postcode' => array(
992 'priority' => 65,
993 ),
994 'state' => array(
995 'label' => __( 'Prefecture', 'woocommerce' ),
996 'priority' => 66,
997 ),
998 'city' => array(
999 'priority' => 67,
1000 ),
1001 'address_1' => array(
1002 'priority' => 68,
1003 ),
1004 'address_2' => array(
1005 'priority' => 69,
1006 ),
1007 ),
1008 'KR' => array(
1009 'state' => array(
1010 'required' => false,
1011 ),
1012 ),
1013 'KW' => array(
1014 'state' => array(
1015 'required' => false,
1016 ),
1017 ),
1018 'LV' => array(
1019 'state' => array(
1020 'label' => __( 'Municipality', 'woocommerce' ),
1021 'required' => false,
1022 ),
1023 ),
1024 'LB' => array(
1025 'state' => array(
1026 'required' => false,
1027 ),
1028 ),
1029 'MQ' => array(
1030 'state' => array(
1031 'required' => false,
1032 ),
1033 ),
1034 'MT' => array(
1035 'state' => array(
1036 'required' => false,
1037 ),
1038 ),
1039 'NL' => array(
1040 'postcode' => array(
1041 'priority' => 65,
1042 ),
1043 'state' => array(
1044 'required' => false,
1045 'label' => __( 'Province', 'woocommerce' ),
1046 ),
1047 ),
1048 'NG' => array(
1049 'postcode' => array(
1050 'label' => __( 'Postcode', 'woocommerce' ),
1051 'required' => false,
1052 'hidden' => true,
1053 ),
1054 'state' => array(
1055 'label' => __( 'State', 'woocommerce' ),
1056 ),
1057 ),
1058 'NZ' => array(
1059 'postcode' => array(
1060 'label' => __( 'Postcode', 'woocommerce' ),
1061 ),
1062 'state' => array(
1063 'required' => false,
1064 'label' => __( 'Region', 'woocommerce' ),
1065 ),
1066 ),
1067 'NO' => array(
1068 'postcode' => array(
1069 'priority' => 65,
1070 ),
1071 'state' => array(
1072 'required' => false,
1073 ),
1074 ),
1075 'NP' => array(
1076 'state' => array(
1077 'label' => __( 'State / Zone', 'woocommerce' ),
1078 ),
1079 'postcode' => array(
1080 'required' => false,
1081 ),
1082 ),
1083 'PL' => array(
1084 'postcode' => array(
1085 'priority' => 65,
1086 ),
1087 'state' => array(
1088 'required' => false,
1089 ),
1090 ),
1091 'PT' => array(
1092 'state' => array(
1093 'required' => false,
1094 ),
1095 ),
1096 'RE' => array(
1097 'state' => array(
1098 'required' => false,
1099 ),
1100 ),
1101 'RO' => array(
1102 'state' => array(
1103 'label' => __( 'County', 'woocommerce' ),
1104 'required' => true,
1105 ),
1106 ),
1107 'RS' => array(
1108 'state' => array(
1109 'required' => false,
1110 'hidden' => true,
1111 ),
1112 ),
1113 'SG' => array(
1114 'state' => array(
1115 'required' => false,
1116 ),
1117 'city' => array(
1118 'required' => false,
1119 ),
1120 ),
1121 'SK' => array(
1122 'postcode' => array(
1123 'priority' => 65,
1124 ),
1125 'state' => array(
1126 'required' => false,
1127 ),
1128 ),
1129 'SI' => array(
1130 'postcode' => array(
1131 'priority' => 65,
1132 ),
1133 'state' => array(
1134 'required' => false,
1135 ),
1136 ),
1137 'SR' => array(
1138 'postcode' => array(
1139 'required' => false,
1140 'hidden' => true,
1141 ),
1142 ),
1143 'ES' => array(
1144 'postcode' => array(
1145 'priority' => 65,
1146 ),
1147 'state' => array(
1148 'label' => __( 'Province', 'woocommerce' ),
1149 ),
1150 ),
1151 'LI' => array(
1152 'postcode' => array(
1153 'priority' => 65,
1154 ),
1155 'state' => array(
1156 'label' => __( 'Municipality', 'woocommerce' ),
1157 'required' => false,
1158 ),
1159 ),
1160 'LK' => array(
1161 'state' => array(
1162 'required' => false,
1163 ),
1164 ),
1165 'LU' => array(
1166 'state' => array(
1167 'required' => false,
1168 ),
1169 ),
1170 'MD' => array(
1171 'state' => array(
1172 'label' => __( 'Municipality / District', 'woocommerce' ),
1173 ),
1174 ),
1175 'SE' => array(
1176 'postcode' => array(
1177 'priority' => 65,
1178 ),
1179 'state' => array(
1180 'required' => false,
1181 ),
1182 ),
1183 'TR' => array(
1184 'postcode' => array(
1185 'priority' => 65,
1186 ),
1187 'state' => array(
1188 'label' => __( 'Province', 'woocommerce' ),
1189 ),
1190 ),
1191 'US' => array(
1192 'postcode' => array(
1193 'label' => __( 'ZIP', 'woocommerce' ),
1194 ),
1195 'state' => array(
1196 'label' => __( 'State', 'woocommerce' ),
1197 ),
1198 ),
1199 'GB' => array(
1200 'postcode' => array(
1201 'label' => __( 'Postcode', 'woocommerce' ),
1202 ),
1203 'state' => array(
1204 'label' => __( 'County', 'woocommerce' ),
1205 'required' => false,
1206 ),
1207 ),
1208 'ST' => array(
1209 'postcode' => array(
1210 'required' => false,
1211 'hidden' => true,
1212 ),
1213 'state' => array(
1214 'label' => __( 'District', 'woocommerce' ),
1215 ),
1216 ),
1217 'VN' => array(
1218 'state' => array(
1219 'required' => false,
1220 ),
1221 'postcode' => array(
1222 'priority' => 65,
1223 'required' => false,
1224 'hidden' => false,
1225 ),
1226 'address_2' => array(
1227 'required' => false,
1228 'hidden' => true,
1229 ),
1230 ),
1231 'WS' => array(
1232 'postcode' => array(
1233 'required' => false,
1234 'hidden' => true,
1235 ),
1236 ),
1237 'YT' => array(
1238 'state' => array(
1239 'required' => false,
1240 ),
1241 ),
1242 'ZA' => array(
1243 'state' => array(
1244 'label' => __( 'Province', 'woocommerce' ),
1245 ),
1246 ),
1247 'ZW' => array(
1248 'postcode' => array(
1249 'required' => false,
1250 'hidden' => true,
1251 ),
1252 ),
1253 )
1254 );
1255
1256 $this->locale = array_intersect_key( $this->locale, array_merge( $this->get_allowed_countries(), $this->get_shipping_countries() ) );
1257
1258 // Default Locale Can be filtered to override fields in get_address_fields(). Countries with no specific locale will use default.
1259 $this->locale['default'] = apply_filters( 'woocommerce_get_country_locale_default', $this->get_default_address_fields() );
1260
1261 // Filter default AND shop base locales to allow overides via a single function. These will be used when changing countries on the checkout.
1262 if ( ! isset( $this->locale[ $this->get_base_country() ] ) ) {
1263 $this->locale[ $this->get_base_country() ] = $this->locale['default'];
1264 }
1265
1266 $this->locale['default'] = apply_filters( 'woocommerce_get_country_locale_base', $this->locale['default'] );
1267 $this->locale[ $this->get_base_country() ] = apply_filters( 'woocommerce_get_country_locale_base', $this->locale[ $this->get_base_country() ] );
1268 }
1269
1270 return $this->locale;
1271 }
1272
1273 /**
1274 * Apply locale and get address fields.
1275 *
1276 * @param mixed $country Country.
1277 * @param string $type Address type, defaults to 'billing_'.
1278 * @return array
1279 */
1280 public function get_address_fields( $country = '', $type = 'billing_' ) {
1281 if ( ! $country ) {
1282 $country = $this->get_base_country();
1283 }
1284
1285 $fields = $this->get_default_address_fields();
1286 $locale = $this->get_country_locale();
1287
1288 if ( isset( $locale[ $country ] ) ) {
1289 $fields = wc_array_overlay( $fields, $locale[ $country ] );
1290 }
1291
1292 // Prepend field keys.
1293 $address_fields = array();
1294
1295 foreach ( $fields as $key => $value ) {
1296 if ( 'state' === $key ) {
1297 $value['country_field'] = $type . 'country';
1298 $value['country'] = $country;
1299 }
1300 $address_fields[ $type . $key ] = $value;
1301 }
1302
1303 // Add email and phone fields.
1304 if ( 'billing_' === $type ) {
1305 if ( 'hidden' !== get_option( 'woocommerce_checkout_phone_field', 'required' ) ) {
1306 $address_fields['billing_phone'] = array(
1307 'label' => __( 'Phone', 'woocommerce' ),
1308 'required' => 'required' === get_option( 'woocommerce_checkout_phone_field', 'required' ),
1309 'type' => 'tel',
1310 'class' => array( 'form-row-wide' ),
1311 'validate' => array( 'phone' ),
1312 'autocomplete' => 'tel',
1313 'priority' => 100,
1314 );
1315 }
1316 $address_fields['billing_email'] = array(
1317 'label' => __( 'Email address', 'woocommerce' ),
1318 'required' => true,
1319 'type' => 'email',
1320 'class' => array( 'form-row-wide' ),
1321 'validate' => array( 'email' ),
1322 'autocomplete' => 'no' === get_option( 'woocommerce_registration_generate_username' ) ? 'email' : 'email username',
1323 'priority' => 110,
1324 );
1325 }
1326
1327 /**
1328 * Important note on this filter: Changes to address fields can and will be overridden by
1329 * the woocommerce_default_address_fields. The locales/default locales apply on top based
1330 * on country selection. If you want to change things like the required status of an
1331 * address field, filter woocommerce_default_address_fields instead.
1332 */
1333 $address_fields = apply_filters( 'woocommerce_' . $type . 'fields', $address_fields, $country );
1334 // Sort each of the fields based on priority.
1335 uasort( $address_fields, 'wc_checkout_fields_uasort_comparison' );
1336
1337 return $address_fields;
1338 }
1339 }
1340