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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 3 years ago admin 3 years ago blocks 5 years ago cli 3 years ago customizer 3 years ago data-stores 3 years ago emails 3 years ago export 3 years ago gateways 3 years ago import 3 years ago integrations 4 years ago interfaces 3 years ago legacy 3 years ago libraries 3 years ago log-handlers 4 years ago payment-tokens 5 years ago queue 4 years ago react-admin 3 years ago rest-api 3 years ago shipping 4 years ago shortcodes 3 years ago theme-support 3 years ago tracks 3 years ago traits 5 years ago walkers 5 years ago wccom-site 5 years ago widgets 4 years ago class-wc-ajax.php 3 years ago class-wc-api.php 4 years ago class-wc-auth.php 4 years ago class-wc-autoloader.php 5 years ago class-wc-background-emailer.php 5 years ago class-wc-background-updater.php 5 years ago class-wc-breadcrumb.php 5 years ago class-wc-cache-helper.php 4 years ago class-wc-cart-fees.php 5 years ago class-wc-cart-session.php 3 years ago class-wc-cart-totals.php 4 years ago class-wc-cart.php 3 years ago class-wc-checkout.php 3 years ago class-wc-cli.php 3 years ago class-wc-comments.php 3 years ago class-wc-countries.php 3 years ago class-wc-coupon.php 4 years ago class-wc-customer-download-log.php 5 years ago class-wc-customer-download.php 4 years ago class-wc-customer.php 4 years ago class-wc-data-exception.php 8 years ago class-wc-data-store.php 3 years ago class-wc-datetime.php 4 years ago class-wc-deprecated-action-hooks.php 8 years ago class-wc-deprecated-filter-hooks.php 3 years ago class-wc-discounts.php 3 years ago class-wc-download-handler.php 3 years ago class-wc-emails.php 3 years ago class-wc-embed.php 5 years ago class-wc-form-handler.php 4 years ago class-wc-frontend-scripts.php 3 years ago class-wc-geo-ip.php 4 years ago class-wc-geolite-integration.php 6 years ago class-wc-geolocation.php 3 years ago class-wc-https.php 4 years ago class-wc-install.php 3 years ago class-wc-integrations.php 5 years ago class-wc-log-levels.php 5 years ago class-wc-logger.php 4 years ago class-wc-meta-data.php 4 years ago class-wc-order-factory.php 3 years ago class-wc-order-item-coupon.php 4 years ago class-wc-order-item-fee.php 4 years ago class-wc-order-item-meta.php 4 years ago class-wc-order-item-product.php 4 years ago class-wc-order-item-shipping.php 4 years ago class-wc-order-item-tax.php 4 years ago class-wc-order-item.php 4 years ago class-wc-order-query.php 4 years ago class-wc-order-refund.php 3 years ago class-wc-order.php 3 years ago class-wc-payment-gateways.php 4 years ago class-wc-payment-tokens.php 3 years ago class-wc-post-data.php 3 years ago class-wc-post-types.php 3 years ago class-wc-privacy-background-process.php 5 years ago class-wc-privacy-erasers.php 4 years ago class-wc-privacy-exporters.php 4 years ago class-wc-privacy.php 4 years ago class-wc-product-attribute.php 4 years ago class-wc-product-download.php 4 years ago class-wc-product-external.php 5 years ago class-wc-product-factory.php 5 years ago class-wc-product-grouped.php 8 years ago class-wc-product-query.php 5 years ago class-wc-product-simple.php 3 years ago class-wc-product-variable.php 4 years ago class-wc-product-variation.php 4 years ago class-wc-query.php 3 years ago class-wc-rate-limiter.php 4 years ago class-wc-regenerate-images-request.php 3 years ago class-wc-regenerate-images.php 3 years ago class-wc-register-wp-admin-settings.php 4 years ago class-wc-rest-authentication.php 5 years ago class-wc-rest-exception.php 5 years ago class-wc-session-handler.php 3 years ago class-wc-shipping-rate.php 3 years ago class-wc-shipping-zone.php 5 years ago class-wc-shipping-zones.php 5 years ago class-wc-shipping.php 4 years ago class-wc-shortcodes.php 5 years ago class-wc-structured-data.php 5 years ago class-wc-tax.php 4 years ago class-wc-template-loader.php 3 years ago class-wc-tracker.php 3 years ago class-wc-validation.php 3 years ago class-wc-webhook.php 3 years ago class-woocommerce.php 3 years ago wc-account-functions.php 3 years ago wc-attribute-functions.php 3 years ago wc-cart-functions.php 3 years ago wc-conditional-functions.php 3 years ago wc-core-functions.php 3 years ago wc-coupon-functions.php 5 years ago wc-deprecated-functions.php 3 years ago wc-formatting-functions.php 3 years ago wc-notice-functions.php 5 years ago wc-order-functions.php 3 years ago wc-order-item-functions.php 3 years ago wc-page-functions.php 5 years ago wc-product-functions.php 3 years ago wc-rest-functions.php 3 years ago wc-stock-functions.php 4 years ago wc-template-functions.php 3 years ago wc-template-hooks.php 5 years ago wc-term-functions.php 3 years ago wc-update-functions.php 3 years ago wc-user-functions.php 3 years ago wc-webhook-functions.php 4 years ago wc-widget-functions.php 5 years ago
class-wc-countries.php
1655 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 wc_asort_by_locale( $this->countries );
54 }
55 }
56
57 return $this->countries;
58 }
59
60 /**
61 * Check if a given code represents a valid ISO 3166-1 alpha-2 code for a country known to us.
62 *
63 * @since 5.1.0
64 * @param string $country_code The country code to check as a ISO 3166-1 alpha-2 code.
65 * @return bool True if the country is known to us, false otherwise.
66 */
67 public function country_exists( $country_code ) {
68 return isset( $this->get_countries()[ $country_code ] );
69 }
70
71 /**
72 * Get all continents.
73 *
74 * @return array
75 */
76 public function get_continents() {
77 if ( empty( $this->continents ) ) {
78 $this->continents = apply_filters( 'woocommerce_continents', include WC()->plugin_path() . '/i18n/continents.php' );
79 }
80
81 return $this->continents;
82 }
83
84 /**
85 * Get continent code for a country code.
86 *
87 * @since 2.6.0
88 * @param string $cc Country code.
89 * @return string
90 */
91 public function get_continent_code_for_country( $cc ) {
92 $cc = trim( strtoupper( $cc ) );
93 $continents = $this->get_continents();
94 $continents_and_ccs = wp_list_pluck( $continents, 'countries' );
95 foreach ( $continents_and_ccs as $continent_code => $countries ) {
96 if ( false !== array_search( $cc, $countries, true ) ) {
97 return $continent_code;
98 }
99 }
100
101 return '';
102 }
103
104 /**
105 * Get calling code for a country code.
106 *
107 * @since 3.6.0
108 * @param string $cc Country code.
109 * @return string|array Some countries have multiple. The code will be stripped of - and spaces and always be prefixed with +.
110 */
111 public function get_country_calling_code( $cc ) {
112 $codes = wp_cache_get( 'calling-codes', 'countries' );
113
114 if ( ! $codes ) {
115 $codes = include WC()->plugin_path() . '/i18n/phone.php';
116 wp_cache_set( 'calling-codes', $codes, 'countries' );
117 }
118
119 $calling_code = isset( $codes[ $cc ] ) ? $codes[ $cc ] : '';
120
121 if ( is_array( $calling_code ) ) {
122 $calling_code = $calling_code[0];
123 }
124
125 return $calling_code;
126 }
127
128 /**
129 * Get continents that the store ships to.
130 *
131 * @since 3.6.0
132 * @return array
133 */
134 public function get_shipping_continents() {
135 $continents = $this->get_continents();
136 $shipping_countries = $this->get_shipping_countries();
137 $shipping_country_codes = array_keys( $shipping_countries );
138 $shipping_continents = array();
139
140 foreach ( $continents as $continent_code => $continent ) {
141 if ( count( array_intersect( $continent['countries'], $shipping_country_codes ) ) ) {
142 $shipping_continents[ $continent_code ] = $continent;
143 }
144 }
145
146 return $shipping_continents;
147 }
148
149 /**
150 * Load the states.
151 *
152 * @deprecated 3.6.0 This method was used to load state files, but is no longer needed. @see get_states().
153 */
154 public function load_country_states() {
155 global $states;
156
157 $states = include WC()->plugin_path() . '/i18n/states.php';
158 $this->states = apply_filters( 'woocommerce_states', $states );
159 }
160
161 /**
162 * Get the states for a country.
163 *
164 * @param string $cc Country code.
165 * @return false|array of states
166 */
167 public function get_states( $cc = null ) {
168 if ( ! isset( $this->states ) ) {
169 $this->states = apply_filters( 'woocommerce_states', include WC()->plugin_path() . '/i18n/states.php' );
170 }
171
172 if ( ! is_null( $cc ) ) {
173 return isset( $this->states[ $cc ] ) ? $this->states[ $cc ] : false;
174 } else {
175 return $this->states;
176 }
177 }
178
179 /**
180 * Get the base address (first line) for the store.
181 *
182 * @since 3.1.1
183 * @return string
184 */
185 public function get_base_address() {
186 $base_address = get_option( 'woocommerce_store_address', '' );
187 return apply_filters( 'woocommerce_countries_base_address', $base_address );
188 }
189
190 /**
191 * Get the base address (second line) for the store.
192 *
193 * @since 3.1.1
194 * @return string
195 */
196 public function get_base_address_2() {
197 $base_address_2 = get_option( 'woocommerce_store_address_2', '' );
198 return apply_filters( 'woocommerce_countries_base_address_2', $base_address_2 );
199 }
200
201 /**
202 * Get the base country for the store.
203 *
204 * @return string
205 */
206 public function get_base_country() {
207 $default = wc_get_base_location();
208 return apply_filters( 'woocommerce_countries_base_country', $default['country'] );
209 }
210
211 /**
212 * Get the base state for the store.
213 *
214 * @return string
215 */
216 public function get_base_state() {
217 $default = wc_get_base_location();
218 return apply_filters( 'woocommerce_countries_base_state', $default['state'] );
219 }
220
221 /**
222 * Get the base city for the store.
223 *
224 * @version 3.1.1
225 * @return string
226 */
227 public function get_base_city() {
228 $base_city = get_option( 'woocommerce_store_city', '' );
229 return apply_filters( 'woocommerce_countries_base_city', $base_city );
230 }
231
232 /**
233 * Get the base postcode for the store.
234 *
235 * @since 3.1.1
236 * @return string
237 */
238 public function get_base_postcode() {
239 $base_postcode = get_option( 'woocommerce_store_postcode', '' );
240 return apply_filters( 'woocommerce_countries_base_postcode', $base_postcode );
241 }
242
243 /**
244 * Get countries that the store sells to.
245 *
246 * @return array
247 */
248 public function get_allowed_countries() {
249 if ( 'all' === get_option( 'woocommerce_allowed_countries' ) ) {
250 return apply_filters( 'woocommerce_countries_allowed_countries', $this->countries );
251 }
252
253 if ( 'all_except' === get_option( 'woocommerce_allowed_countries' ) ) {
254 $except_countries = get_option( 'woocommerce_all_except_countries', array() );
255
256 if ( ! $except_countries ) {
257 return $this->countries;
258 } else {
259 $all_except_countries = $this->countries;
260 foreach ( $except_countries as $country ) {
261 unset( $all_except_countries[ $country ] );
262 }
263 return apply_filters( 'woocommerce_countries_allowed_countries', $all_except_countries );
264 }
265 }
266
267 $countries = array();
268
269 $raw_countries = get_option( 'woocommerce_specific_allowed_countries', array() );
270
271 if ( $raw_countries ) {
272 foreach ( $raw_countries as $country ) {
273 $countries[ $country ] = $this->countries[ $country ];
274 }
275 }
276
277 return apply_filters( 'woocommerce_countries_allowed_countries', $countries );
278 }
279
280 /**
281 * Get countries that the store ships to.
282 *
283 * @return array
284 */
285 public function get_shipping_countries() {
286 if ( '' === get_option( 'woocommerce_ship_to_countries' ) ) {
287 return $this->get_allowed_countries();
288 }
289
290 if ( 'all' === get_option( 'woocommerce_ship_to_countries' ) ) {
291 return $this->countries;
292 }
293
294 $countries = array();
295
296 $raw_countries = get_option( 'woocommerce_specific_ship_to_countries' );
297
298 if ( $raw_countries ) {
299 foreach ( $raw_countries as $country ) {
300 $countries[ $country ] = $this->countries[ $country ];
301 }
302 }
303
304 return apply_filters( 'woocommerce_countries_shipping_countries', $countries );
305 }
306
307 /**
308 * Get allowed country states.
309 *
310 * @return array
311 */
312 public function get_allowed_country_states() {
313 if ( get_option( 'woocommerce_allowed_countries' ) !== 'specific' ) {
314 return $this->states;
315 }
316
317 $states = array();
318
319 $raw_countries = get_option( 'woocommerce_specific_allowed_countries' );
320
321 if ( $raw_countries ) {
322 foreach ( $raw_countries as $country ) {
323 if ( isset( $this->states[ $country ] ) ) {
324 $states[ $country ] = $this->states[ $country ];
325 }
326 }
327 }
328
329 return apply_filters( 'woocommerce_countries_allowed_country_states', $states );
330 }
331
332 /**
333 * Get shipping country states.
334 *
335 * @return array
336 */
337 public function get_shipping_country_states() {
338 if ( get_option( 'woocommerce_ship_to_countries' ) === '' ) {
339 return $this->get_allowed_country_states();
340 }
341
342 if ( get_option( 'woocommerce_ship_to_countries' ) !== 'specific' ) {
343 return $this->states;
344 }
345
346 $states = array();
347
348 $raw_countries = get_option( 'woocommerce_specific_ship_to_countries' );
349
350 if ( $raw_countries ) {
351 foreach ( $raw_countries as $country ) {
352 if ( ! empty( $this->states[ $country ] ) ) {
353 $states[ $country ] = $this->states[ $country ];
354 }
355 }
356 }
357
358 return apply_filters( 'woocommerce_countries_shipping_country_states', $states );
359 }
360
361 /**
362 * Gets an array of countries in the EU.
363 *
364 * @param string $type Type of countries to retrieve. Blank for EU member countries. eu_vat for EU VAT countries.
365 * @return string[]
366 */
367 public function get_european_union_countries( $type = '' ) {
368 $countries = array( 'AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GR', 'HR', 'HU', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK' );
369
370 if ( 'eu_vat' === $type ) {
371 $countries[] = 'MC';
372 }
373
374 return apply_filters( 'woocommerce_european_union_countries', $countries, $type );
375 }
376
377 /**
378 * Gets an array of Non-EU countries that use VAT as the Local name for their taxes based on this list - https://en.wikipedia.org/wiki/Value-added_tax#Non-European_Union_countries
379 *
380 * @deprecated 4.0.0
381 * @since 3.9.0
382 * @return string[]
383 */
384 public function countries_using_vat() {
385 wc_deprecated_function( 'countries_using_vat', '4.0', 'WC_Countries::get_vat_countries' );
386 $countries = array( 'AE', 'AL', 'AR', 'AZ', 'BB', 'BH', 'BO', 'BS', 'BY', 'CL', 'CO', 'EC', 'EG', 'ET', 'FJ', 'GH', 'GM', 'GT', 'IL', 'IN', 'IR', 'KN', 'KR', 'KZ', 'LK', 'MD', 'ME', 'MK', 'MN', 'MU', 'MX', 'NA', 'NG', 'NP', 'PS', 'PY', 'RS', 'RU', 'RW', 'SA', 'SV', 'TH', 'TR', 'UA', 'UY', 'UZ', 'VE', 'VN', 'ZA' );
387
388 return apply_filters( 'woocommerce_countries_using_vat', $countries );
389 }
390
391 /**
392 * Gets an array of countries using VAT.
393 *
394 * @since 4.0.0
395 * @return string[] of country codes.
396 */
397 public function get_vat_countries() {
398 $eu_countries = $this->get_european_union_countries();
399 $vat_countries = array( 'AE', 'AL', 'AR', 'AZ', 'BB', 'BH', 'BO', 'BS', 'BY', 'CL', 'CO', 'EC', 'EG', 'ET', 'FJ', 'GB', 'GH', 'GM', 'GT', 'IL', 'IM', 'IN', 'IR', 'KN', 'KR', 'KZ', 'LK', 'MC', 'MD', 'ME', 'MK', 'MN', 'MU', 'MX', 'NA', 'NG', 'NO', 'NP', 'PS', 'PY', 'RS', 'RU', 'RW', 'SA', 'SV', 'TH', 'TR', 'UA', 'UY', 'UZ', 'VE', 'VN', 'ZA' );
400
401 return apply_filters( 'woocommerce_vat_countries', array_merge( $eu_countries, $vat_countries ) );
402 }
403
404 /**
405 * Gets the correct string for shipping - either 'to the' or 'to'.
406 *
407 * @param string $country_code Country code.
408 * @return string
409 */
410 public function shipping_to_prefix( $country_code = '' ) {
411 $country_code = $country_code ? $country_code : WC()->customer->get_shipping_country();
412 $countries = array( 'AE', 'CZ', 'DO', 'GB', 'NL', 'PH', 'US', 'USAF' );
413 $return = in_array( $country_code, $countries, true ) ? _x( 'to the', 'shipping country prefix', 'woocommerce' ) : _x( 'to', 'shipping country prefix', 'woocommerce' );
414
415 return apply_filters( 'woocommerce_countries_shipping_to_prefix', $return, $country_code );
416 }
417
418 /**
419 * Prefix certain countries with 'the'.
420 *
421 * @param string $country_code Country code.
422 * @return string
423 */
424 public function estimated_for_prefix( $country_code = '' ) {
425 $country_code = $country_code ? $country_code : $this->get_base_country();
426 $countries = array( 'AE', 'CZ', 'DO', 'GB', 'NL', 'PH', 'US', 'USAF' );
427 $return = in_array( $country_code, $countries, true ) ? __( 'the', 'woocommerce' ) . ' ' : '';
428
429 return apply_filters( 'woocommerce_countries_estimated_for_prefix', $return, $country_code );
430 }
431
432 /**
433 * Correctly name tax in some countries VAT on the frontend.
434 *
435 * @return string
436 */
437 public function tax_or_vat() {
438 $return = in_array( $this->get_base_country(), $this->get_vat_countries(), true ) ? __( 'VAT', 'woocommerce' ) : __( 'Tax', 'woocommerce' );
439
440 return apply_filters( 'woocommerce_countries_tax_or_vat', $return );
441 }
442
443 /**
444 * Include the Inc Tax label.
445 *
446 * @return string
447 */
448 public function inc_tax_or_vat() {
449 $return = in_array( $this->get_base_country(), $this->get_vat_countries(), true ) ? __( '(incl. VAT)', 'woocommerce' ) : __( '(incl. tax)', 'woocommerce' );
450
451 return apply_filters( 'woocommerce_countries_inc_tax_or_vat', $return );
452 }
453
454 /**
455 * Include the Ex Tax label.
456 *
457 * @return string
458 */
459 public function ex_tax_or_vat() {
460 $return = in_array( $this->get_base_country(), $this->get_vat_countries(), true ) ? __( '(ex. VAT)', 'woocommerce' ) : __( '(ex. tax)', 'woocommerce' );
461
462 return apply_filters( 'woocommerce_countries_ex_tax_or_vat', $return );
463 }
464
465 /**
466 * Outputs the list of countries and states for use in dropdown boxes.
467 *
468 * @param string $selected_country Selected country.
469 * @param string $selected_state Selected state.
470 * @param bool $escape If we should escape HTML.
471 */
472 public function country_dropdown_options( $selected_country = '', $selected_state = '', $escape = false ) {
473 if ( $this->countries ) {
474 foreach ( $this->countries as $key => $value ) {
475 $states = $this->get_states( $key );
476 if ( $states ) {
477 echo '<optgroup label="' . esc_attr( $value ) . '">';
478 foreach ( $states as $state_key => $state_value ) {
479 echo '<option value="' . esc_attr( $key ) . ':' . esc_attr( $state_key ) . '"';
480
481 if ( $selected_country === $key && $selected_state === $state_key ) {
482 echo ' selected="selected"';
483 }
484
485 echo '>' . esc_html( $value ) . ' &mdash; ' . ( $escape ? esc_html( $state_value ) : $state_value ) . '</option>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
486
487 }
488 echo '</optgroup>';
489 } else {
490 echo '<option';
491 if ( $selected_country === $key && '*' === $selected_state ) {
492 echo ' selected="selected"';
493 }
494 echo ' value="' . esc_attr( $key ) . '">' . ( $escape ? esc_html( $value ) : $value ) . '</option>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
495 }
496 }
497 }
498 }
499
500 /**
501 * Get country address formats.
502 *
503 * These define how addresses are formatted for display in various countries.
504 *
505 * @return array
506 */
507 public function get_address_formats() {
508 if ( empty( $this->address_formats ) ) {
509 $this->address_formats = apply_filters(
510 'woocommerce_localisation_address_formats',
511 array(
512 'default' => "{name}\n{company}\n{address_1}\n{address_2}\n{city}\n{state}\n{postcode}\n{country}",
513 'AT' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
514 'AU' => "{name}\n{company}\n{address_1}\n{address_2}\n{city} {state} {postcode}\n{country}",
515 'BE' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
516 'CA' => "{company}\n{name}\n{address_1}\n{address_2}\n{city} {state_code} {postcode}\n{country}",
517 'CH' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
518 'CL' => "{company}\n{name}\n{address_1}\n{address_2}\n{state}\n{postcode} {city}\n{country}",
519 'CN' => "{country} {postcode}\n{state}, {city}, {address_2}, {address_1}\n{company}\n{name}",
520 'CZ' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
521 'DE' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
522 'DK' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
523 'EE' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
524 'ES' => "{name}\n{company}\n{address_1}\n{address_2}\n{postcode} {city}\n{state}\n{country}",
525 'FI' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
526 'FR' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city_upper}\n{country}",
527 'HK' => "{company}\n{first_name} {last_name_upper}\n{address_1}\n{address_2}\n{city_upper}\n{state_upper}\n{country}",
528 'HU' => "{last_name} {first_name}\n{company}\n{city}\n{address_1}\n{address_2}\n{postcode}\n{country}",
529 'IN' => "{company}\n{name}\n{address_1}\n{address_2}\n{city} {postcode}\n{state}, {country}",
530 'IS' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
531 'IT' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode}\n{city}\n{state_upper}\n{country}",
532 'JM' => "{name}\n{company}\n{address_1}\n{address_2}\n{city}\n{state}\n{postcode_upper}\n{country}",
533 'JP' => "{postcode}\n{state} {city} {address_1}\n{address_2}\n{company}\n{last_name} {first_name}\n{country}",
534 'LI' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
535 'NL' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
536 'NO' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
537 'NZ' => "{name}\n{company}\n{address_1}\n{address_2}\n{city} {postcode}\n{country}",
538 'PL' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
539 'PR' => "{company}\n{name}\n{address_1} {address_2}\n{city} \n{country} {postcode}",
540 'PT' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
541 'RS' => "{name}\n{company}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
542 'SE' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
543 'SI' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
544 'SK' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
545 'TR' => "{name}\n{company}\n{address_1}\n{address_2}\n{postcode} {city} {state}\n{country}",
546 'TW' => "{company}\n{last_name} {first_name}\n{address_1}\n{address_2}\n{state}, {city} {postcode}\n{country}",
547 'UG' => "{name}\n{company}\n{address_1}\n{address_2}\n{city}\n{state}, {country}",
548 'US' => "{name}\n{company}\n{address_1}\n{address_2}\n{city}, {state_code} {postcode}\n{country}",
549 'VN' => "{name}\n{company}\n{address_1}\n{city}\n{country}",
550 )
551 );
552 }
553 return $this->address_formats;
554 }
555
556 /**
557 * Get country address format.
558 *
559 * @param array $args Arguments.
560 * @param string $separator How to separate address lines. @since 3.5.0.
561 * @return string
562 */
563 public function get_formatted_address( $args = array(), $separator = '<br/>' ) {
564 $default_args = array(
565 'first_name' => '',
566 'last_name' => '',
567 'company' => '',
568 'address_1' => '',
569 'address_2' => '',
570 'city' => '',
571 'state' => '',
572 'postcode' => '',
573 'country' => '',
574 );
575
576 $args = array_map( 'trim', wp_parse_args( $args, $default_args ) );
577 $state = $args['state'];
578 $country = $args['country'];
579
580 // Get all formats.
581 $formats = $this->get_address_formats();
582
583 // Get format for the address' country.
584 $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
585
586 // Handle full country name.
587 $full_country = ( isset( $this->countries[ $country ] ) ) ? $this->countries[ $country ] : $country;
588
589 // Country is not needed if the same as base.
590 if ( $country === $this->get_base_country() && ! apply_filters( 'woocommerce_formatted_address_force_country_display', false ) ) {
591 $format = str_replace( '{country}', '', $format );
592 }
593
594 // Handle full state name.
595 $full_state = ( $country && $state && isset( $this->states[ $country ][ $state ] ) ) ? $this->states[ $country ][ $state ] : $state;
596
597 // Substitute address parts into the string.
598 $replace = array_map(
599 'esc_html',
600 apply_filters(
601 'woocommerce_formatted_address_replacements',
602 array(
603 '{first_name}' => $args['first_name'],
604 '{last_name}' => $args['last_name'],
605 '{name}' => sprintf(
606 /* translators: 1: first name 2: last name */
607 _x( '%1$s %2$s', 'full name', 'woocommerce' ),
608 $args['first_name'],
609 $args['last_name']
610 ),
611 '{company}' => $args['company'],
612 '{address_1}' => $args['address_1'],
613 '{address_2}' => $args['address_2'],
614 '{city}' => $args['city'],
615 '{state}' => $full_state,
616 '{postcode}' => $args['postcode'],
617 '{country}' => $full_country,
618 '{first_name_upper}' => wc_strtoupper( $args['first_name'] ),
619 '{last_name_upper}' => wc_strtoupper( $args['last_name'] ),
620 '{name_upper}' => wc_strtoupper(
621 sprintf(
622 /* translators: 1: first name 2: last name */
623 _x( '%1$s %2$s', 'full name', 'woocommerce' ),
624 $args['first_name'],
625 $args['last_name']
626 )
627 ),
628 '{company_upper}' => wc_strtoupper( $args['company'] ),
629 '{address_1_upper}' => wc_strtoupper( $args['address_1'] ),
630 '{address_2_upper}' => wc_strtoupper( $args['address_2'] ),
631 '{city_upper}' => wc_strtoupper( $args['city'] ),
632 '{state_upper}' => wc_strtoupper( $full_state ),
633 '{state_code}' => wc_strtoupper( $state ),
634 '{postcode_upper}' => wc_strtoupper( $args['postcode'] ),
635 '{country_upper}' => wc_strtoupper( $full_country ),
636 ),
637 $args
638 )
639 );
640
641 $formatted_address = str_replace( array_keys( $replace ), $replace, $format );
642
643 // Clean up white space.
644 $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) );
645 $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
646
647 // Break newlines apart and remove empty lines/trim commas and white space.
648 $formatted_address = array_filter( array_map( array( $this, 'trim_formatted_address_line' ), explode( "\n", $formatted_address ) ) );
649
650 // Add html breaks.
651 $formatted_address = implode( $separator, $formatted_address );
652
653 // We're done!
654 return $formatted_address;
655 }
656
657 /**
658 * Trim white space and commas off a line.
659 *
660 * @param string $line Line.
661 * @return string
662 */
663 private function trim_formatted_address_line( $line ) {
664 return trim( $line, ', ' );
665 }
666
667 /**
668 * Returns the fields we show by default. This can be filtered later on.
669 *
670 * @return array
671 */
672 public function get_default_address_fields() {
673 $address_2_label = __( 'Apartment, suite, unit, etc.', 'woocommerce' );
674
675 // If necessary, append '(optional)' to the placeholder: we don't need to worry about the
676 // label, though, as woocommerce_form_field() takes care of that.
677 if ( 'optional' === get_option( 'woocommerce_checkout_address_2_field', 'optional' ) ) {
678 $address_2_placeholder = __( 'Apartment, suite, unit, etc. (optional)', 'woocommerce' );
679 } else {
680 $address_2_placeholder = $address_2_label;
681 }
682
683 $fields = array(
684 'first_name' => array(
685 'label' => __( 'First name', 'woocommerce' ),
686 'required' => true,
687 'class' => array( 'form-row-first' ),
688 'autocomplete' => 'given-name',
689 'priority' => 10,
690 ),
691 'last_name' => array(
692 'label' => __( 'Last name', 'woocommerce' ),
693 'required' => true,
694 'class' => array( 'form-row-last' ),
695 'autocomplete' => 'family-name',
696 'priority' => 20,
697 ),
698 'company' => array(
699 'label' => __( 'Company name', 'woocommerce' ),
700 'class' => array( 'form-row-wide' ),
701 'autocomplete' => 'organization',
702 'priority' => 30,
703 'required' => 'required' === get_option( 'woocommerce_checkout_company_field', 'optional' ),
704 ),
705 'country' => array(
706 'type' => 'country',
707 'label' => __( 'Country / Region', 'woocommerce' ),
708 'required' => true,
709 'class' => array( 'form-row-wide', 'address-field', 'update_totals_on_change' ),
710 'autocomplete' => 'country',
711 'priority' => 40,
712 ),
713 'address_1' => array(
714 'label' => __( 'Street address', 'woocommerce' ),
715 /* translators: use local order of street name and house number. */
716 'placeholder' => esc_attr__( 'House number and street name', 'woocommerce' ),
717 'required' => true,
718 'class' => array( 'form-row-wide', 'address-field' ),
719 'autocomplete' => 'address-line1',
720 'priority' => 50,
721 ),
722 'address_2' => array(
723 'label' => $address_2_label,
724 'label_class' => array( 'screen-reader-text' ),
725 'placeholder' => esc_attr( $address_2_placeholder ),
726 'class' => array( 'form-row-wide', 'address-field' ),
727 'autocomplete' => 'address-line2',
728 'priority' => 60,
729 'required' => 'required' === get_option( 'woocommerce_checkout_address_2_field', 'optional' ),
730 ),
731 'city' => array(
732 'label' => __( 'Town / City', 'woocommerce' ),
733 'required' => true,
734 'class' => array( 'form-row-wide', 'address-field' ),
735 'autocomplete' => 'address-level2',
736 'priority' => 70,
737 ),
738 'state' => array(
739 'type' => 'state',
740 'label' => __( 'State / County', 'woocommerce' ),
741 'required' => true,
742 'class' => array( 'form-row-wide', 'address-field' ),
743 'validate' => array( 'state' ),
744 'autocomplete' => 'address-level1',
745 'priority' => 80,
746 ),
747 'postcode' => array(
748 'label' => __( 'Postcode / ZIP', 'woocommerce' ),
749 'required' => true,
750 'class' => array( 'form-row-wide', 'address-field' ),
751 'validate' => array( 'postcode' ),
752 'autocomplete' => 'postal-code',
753 'priority' => 90,
754 ),
755 );
756
757 if ( 'hidden' === get_option( 'woocommerce_checkout_company_field', 'optional' ) ) {
758 unset( $fields['company'] );
759 }
760
761 if ( 'hidden' === get_option( 'woocommerce_checkout_address_2_field', 'optional' ) ) {
762 unset( $fields['address_2'] );
763 }
764
765 $default_address_fields = apply_filters( 'woocommerce_default_address_fields', $fields );
766 // Sort each of the fields based on priority.
767 uasort( $default_address_fields, 'wc_checkout_fields_uasort_comparison' );
768
769 return $default_address_fields;
770 }
771
772 /**
773 * Get JS selectors for fields which are shown/hidden depending on the locale.
774 *
775 * @return array
776 */
777 public function get_country_locale_field_selectors() {
778 $locale_fields = array(
779 'address_1' => '#billing_address_1_field, #shipping_address_1_field',
780 'address_2' => '#billing_address_2_field, #shipping_address_2_field',
781 'state' => '#billing_state_field, #shipping_state_field, #calc_shipping_state_field',
782 'postcode' => '#billing_postcode_field, #shipping_postcode_field, #calc_shipping_postcode_field',
783 'city' => '#billing_city_field, #shipping_city_field, #calc_shipping_city_field',
784 );
785 return apply_filters( 'woocommerce_country_locale_field_selectors', $locale_fields );
786 }
787
788 /**
789 * Get country locale settings.
790 *
791 * These locales override the default country selections after a country is chosen.
792 *
793 * @return array
794 */
795 public function get_country_locale() {
796 if ( empty( $this->locale ) ) {
797 $this->locale = apply_filters(
798 'woocommerce_get_country_locale',
799 array(
800 'AE' => array(
801 'postcode' => array(
802 'required' => false,
803 'hidden' => true,
804 ),
805 'state' => array(
806 'required' => false,
807 ),
808 ),
809 'AF' => array(
810 'state' => array(
811 'required' => false,
812 'hidden' => true,
813 ),
814 ),
815 'AL' => array(
816 'state' => array(
817 'label' => __( 'County', 'woocommerce' ),
818 ),
819 ),
820 'AO' => array(
821 'postcode' => array(
822 'required' => false,
823 'hidden' => true,
824 ),
825 'state' => array(
826 'label' => __( 'Province', 'woocommerce' ),
827 ),
828 ),
829 'AT' => array(
830 'postcode' => array(
831 'priority' => 65,
832 ),
833 'state' => array(
834 'required' => false,
835 'hidden' => true,
836 ),
837 ),
838 'AU' => array(
839 'city' => array(
840 'label' => __( 'Suburb', 'woocommerce' ),
841 ),
842 'postcode' => array(
843 'label' => __( 'Postcode', 'woocommerce' ),
844 ),
845 'state' => array(
846 'label' => __( 'State', 'woocommerce' ),
847 ),
848 ),
849 'AX' => array(
850 'postcode' => array(
851 'priority' => 65,
852 ),
853 'state' => array(
854 'required' => false,
855 'hidden' => true,
856 ),
857 ),
858 'BA' => array(
859 'postcode' => array(
860 'priority' => 65,
861 ),
862 'state' => array(
863 'label' => __( 'Canton', 'woocommerce' ),
864 'required' => false,
865 'hidden' => true,
866 ),
867 ),
868 'BD' => array(
869 'postcode' => array(
870 'required' => false,
871 ),
872 'state' => array(
873 'label' => __( 'District', 'woocommerce' ),
874 ),
875 ),
876 'BE' => array(
877 'postcode' => array(
878 'priority' => 65,
879 ),
880 'state' => array(
881 'required' => false,
882 'hidden' => true,
883 ),
884 ),
885 'BG' => array(
886 'state' => array(
887 'required' => false,
888 ),
889 ),
890 'BH' => array(
891 'postcode' => array(
892 'required' => false,
893 ),
894 'state' => array(
895 'required' => false,
896 'hidden' => true,
897 ),
898 ),
899 'BI' => array(
900 'state' => array(
901 'required' => false,
902 'hidden' => true,
903 ),
904 ),
905 'BO' => array(
906 'postcode' => array(
907 'required' => false,
908 'hidden' => true,
909 ),
910 'state' => array(
911 'label' => __( 'Department', 'woocommerce' ),
912 ),
913 ),
914 'BS' => array(
915 'postcode' => array(
916 'required' => false,
917 'hidden' => true,
918 ),
919 ),
920 'BZ' => array(
921 'postcode' => array(
922 'required' => false,
923 'hidden' => true,
924 ),
925 'state' => array(
926 'required' => false,
927 ),
928 ),
929 'CA' => array(
930 'postcode' => array(
931 'label' => __( 'Postal code', 'woocommerce' ),
932 ),
933 'state' => array(
934 'label' => __( 'Province', 'woocommerce' ),
935 ),
936 ),
937 'CH' => array(
938 'postcode' => array(
939 'priority' => 65,
940 ),
941 'state' => array(
942 'label' => __( 'Canton', 'woocommerce' ),
943 'required' => false,
944 ),
945 ),
946 'CL' => array(
947 'city' => array(
948 'required' => true,
949 ),
950 'postcode' => array(
951 'required' => false,
952 ),
953 'state' => array(
954 'label' => __( 'Region', 'woocommerce' ),
955 ),
956 ),
957 'CN' => array(
958 'state' => array(
959 'label' => __( 'Province', 'woocommerce' ),
960 ),
961 ),
962 'CO' => array(
963 'postcode' => array(
964 'required' => false,
965 ),
966 'state' => array(
967 'label' => __( 'Department', 'woocommerce' ),
968 ),
969 ),
970 'CR' => array(
971 'state' => array(
972 'label' => __( 'Province', 'woocommerce' ),
973 ),
974 ),
975 'CW' => array(
976 'postcode' => array(
977 'required' => false,
978 'hidden' => true,
979 ),
980 'state' => array(
981 'required' => false,
982 ),
983 ),
984 'CZ' => array(
985 'state' => array(
986 'required' => false,
987 'hidden' => true,
988 ),
989 ),
990 'DE' => array(
991 'postcode' => array(
992 'priority' => 65,
993 ),
994 'state' => array(
995 'required' => false,
996 'hidden' => true,
997 ),
998 ),
999 'DK' => array(
1000 'postcode' => array(
1001 'priority' => 65,
1002 ),
1003 'state' => array(
1004 'required' => false,
1005 'hidden' => true,
1006 ),
1007 ),
1008 'DO' => array(
1009 'state' => array(
1010 'label' => __( 'Province', 'woocommerce' ),
1011 ),
1012 ),
1013 'EC' => array(
1014 'state' => array(
1015 'label' => __( 'Province', 'woocommerce' ),
1016 ),
1017 ),
1018 'EE' => array(
1019 'postcode' => array(
1020 'priority' => 65,
1021 ),
1022 'state' => array(
1023 'required' => false,
1024 'hidden' => true,
1025 ),
1026 ),
1027 'FI' => array(
1028 'postcode' => array(
1029 'priority' => 65,
1030 ),
1031 'state' => array(
1032 'required' => false,
1033 'hidden' => true,
1034 ),
1035 ),
1036 'FR' => array(
1037 'postcode' => array(
1038 'priority' => 65,
1039 ),
1040 'state' => array(
1041 'required' => false,
1042 'hidden' => true,
1043 ),
1044 ),
1045 'GG' => array(
1046 'state' => array(
1047 'required' => false,
1048 'label' => __( 'Parish', 'woocommerce' ),
1049 ),
1050 ),
1051 'GH' => array(
1052 'postcode' => array(
1053 'required' => false,
1054 ),
1055 'state' => array(
1056 'label' => __( 'Region', 'woocommerce' ),
1057 ),
1058 ),
1059 'GP' => array(
1060 'state' => array(
1061 'required' => false,
1062 'hidden' => true,
1063 ),
1064 ),
1065 'GF' => array(
1066 'state' => array(
1067 'required' => false,
1068 'hidden' => true,
1069 ),
1070 ),
1071 'GR' => array(
1072 'state' => array(
1073 'required' => false,
1074 ),
1075 ),
1076 'GT' => array(
1077 'postcode' => array(
1078 'required' => false,
1079 ),
1080 'state' => array(
1081 'label' => __( 'Department', 'woocommerce' ),
1082 ),
1083 ),
1084 'HK' => array(
1085 'postcode' => array(
1086 'required' => false,
1087 ),
1088 'city' => array(
1089 'label' => __( 'Town / District', 'woocommerce' ),
1090 ),
1091 'state' => array(
1092 'label' => __( 'Region', 'woocommerce' ),
1093 ),
1094 ),
1095 'HN' => array(
1096 'state' => array(
1097 'label' => __( 'Department', 'woocommerce' ),
1098 ),
1099 ),
1100 'HU' => array(
1101 'last_name' => array(
1102 'class' => array( 'form-row-first' ),
1103 'priority' => 10,
1104 ),
1105 'first_name' => array(
1106 'class' => array( 'form-row-last' ),
1107 'priority' => 20,
1108 ),
1109 'postcode' => array(
1110 'class' => array( 'form-row-first', 'address-field' ),
1111 'priority' => 65,
1112 ),
1113 'city' => array(
1114 'class' => array( 'form-row-last', 'address-field' ),
1115 ),
1116 'address_1' => array(
1117 'priority' => 71,
1118 ),
1119 'address_2' => array(
1120 'priority' => 72,
1121 ),
1122 'state' => array(
1123 'label' => __( 'County', 'woocommerce' ),
1124 'required' => false,
1125 ),
1126 ),
1127 'ID' => array(
1128 'state' => array(
1129 'label' => __( 'Province', 'woocommerce' ),
1130 ),
1131 ),
1132 'IE' => array(
1133 'postcode' => array(
1134 'required' => false,
1135 'label' => __( 'Eircode', 'woocommerce' ),
1136 ),
1137 'state' => array(
1138 'label' => __( 'County', 'woocommerce' ),
1139 ),
1140 ),
1141 'IS' => array(
1142 'postcode' => array(
1143 'priority' => 65,
1144 ),
1145 'state' => array(
1146 'required' => false,
1147 'hidden' => true,
1148 ),
1149 ),
1150 'IL' => array(
1151 'postcode' => array(
1152 'priority' => 65,
1153 ),
1154 'state' => array(
1155 'required' => false,
1156 'hidden' => true,
1157 ),
1158 ),
1159 'IM' => array(
1160 'state' => array(
1161 'required' => false,
1162 'hidden' => true,
1163 ),
1164 ),
1165 'IN' => array(
1166 'postcode' => array(
1167 'label' => __( 'PIN Code', 'woocommerce' ),
1168 ),
1169 'state' => array(
1170 'label' => __( 'State', 'woocommerce' ),
1171 ),
1172 ),
1173 'IR' => array(
1174 'state' => array(
1175 'priority' => 50,
1176 ),
1177 'city' => array(
1178 'priority' => 60,
1179 ),
1180 'address_1' => array(
1181 'priority' => 70,
1182 ),
1183 'address_2' => array(
1184 'priority' => 80,
1185 ),
1186 ),
1187 'IT' => array(
1188 'postcode' => array(
1189 'priority' => 65,
1190 ),
1191 'state' => array(
1192 'required' => true,
1193 'label' => __( 'Province', 'woocommerce' ),
1194 ),
1195 ),
1196 'JM' => array(
1197 'city' => array(
1198 'label' => __( 'Town / City / Post Office', 'woocommerce' ),
1199 ),
1200 'postcode' => array(
1201 'required' => false,
1202 'label' => __( 'Postal Code', 'woocommerce' ),
1203 ),
1204 'state' => array(
1205 'required' => true,
1206 'label' => __( 'Parish', 'woocommerce' ),
1207 ),
1208 ),
1209 'JP' => array(
1210 'last_name' => array(
1211 'class' => array( 'form-row-first' ),
1212 'priority' => 10,
1213 ),
1214 'first_name' => array(
1215 'class' => array( 'form-row-last' ),
1216 'priority' => 20,
1217 ),
1218 'postcode' => array(
1219 'class' => array( 'form-row-first', 'address-field' ),
1220 'priority' => 65,
1221 ),
1222 'state' => array(
1223 'label' => __( 'Prefecture', 'woocommerce' ),
1224 'class' => array( 'form-row-last', 'address-field' ),
1225 'priority' => 66,
1226 ),
1227 'city' => array(
1228 'priority' => 67,
1229 ),
1230 'address_1' => array(
1231 'priority' => 68,
1232 ),
1233 'address_2' => array(
1234 'priority' => 69,
1235 ),
1236 ),
1237 'KR' => array(
1238 'state' => array(
1239 'required' => false,
1240 'hidden' => true,
1241 ),
1242 ),
1243 'KW' => array(
1244 'state' => array(
1245 'required' => false,
1246 'hidden' => true,
1247 ),
1248 ),
1249 'LV' => array(
1250 'state' => array(
1251 'label' => __( 'Municipality', 'woocommerce' ),
1252 'required' => false,
1253 ),
1254 ),
1255 'LB' => array(
1256 'state' => array(
1257 'required' => false,
1258 'hidden' => true,
1259 ),
1260 ),
1261 'MF' => array(
1262 'state' => array(
1263 'required' => false,
1264 'hidden' => true,
1265 ),
1266 ),
1267 'MQ' => array(
1268 'state' => array(
1269 'required' => false,
1270 'hidden' => true,
1271 ),
1272 ),
1273 'MT' => array(
1274 'state' => array(
1275 'required' => false,
1276 'hidden' => true,
1277 ),
1278 ),
1279 'MZ' => array(
1280 'postcode' => array(
1281 'required' => false,
1282 'hidden' => true,
1283 ),
1284 'state' => array(
1285 'label' => __( 'Province', 'woocommerce' ),
1286 ),
1287 ),
1288 'NI' => array(
1289 'state' => array(
1290 'label' => __( 'Department', 'woocommerce' ),
1291 ),
1292 ),
1293 'NL' => array(
1294 'postcode' => array(
1295 'priority' => 65,
1296 ),
1297 'state' => array(
1298 'required' => false,
1299 'hidden' => true,
1300 ),
1301 ),
1302 'NG' => array(
1303 'postcode' => array(
1304 'label' => __( 'Postcode', 'woocommerce' ),
1305 'required' => false,
1306 'hidden' => true,
1307 ),
1308 'state' => array(
1309 'label' => __( 'State', 'woocommerce' ),
1310 ),
1311 ),
1312 'NZ' => array(
1313 'postcode' => array(
1314 'label' => __( 'Postcode', 'woocommerce' ),
1315 ),
1316 'state' => array(
1317 'required' => false,
1318 'label' => __( 'Region', 'woocommerce' ),
1319 ),
1320 ),
1321 'NO' => array(
1322 'postcode' => array(
1323 'priority' => 65,
1324 ),
1325 'state' => array(
1326 'required' => false,
1327 'hidden' => true,
1328 ),
1329 ),
1330 'NP' => array(
1331 'state' => array(
1332 'label' => __( 'State / Zone', 'woocommerce' ),
1333 ),
1334 'postcode' => array(
1335 'required' => false,
1336 ),
1337 ),
1338 'PA' => array(
1339 'state' => array(
1340 'label' => __( 'Province', 'woocommerce' ),
1341 ),
1342 ),
1343 'PL' => array(
1344 'postcode' => array(
1345 'priority' => 65,
1346 ),
1347 'state' => array(
1348 'required' => false,
1349 'hidden' => true,
1350 ),
1351 ),
1352 'PR' => array(
1353 'city' => array(
1354 'label' => __( 'Municipality', 'woocommerce' ),
1355 ),
1356 'state' => array(
1357 'required' => false,
1358 'hidden' => true,
1359 ),
1360 ),
1361 'PT' => array(
1362 'state' => array(
1363 'required' => false,
1364 'hidden' => true,
1365 ),
1366 ),
1367 'PY' => array(
1368 'state' => array(
1369 'label' => __( 'Department', 'woocommerce' ),
1370 ),
1371 ),
1372 'RE' => array(
1373 'state' => array(
1374 'required' => false,
1375 'hidden' => true,
1376 ),
1377 ),
1378 'RO' => array(
1379 'state' => array(
1380 'label' => __( 'County', 'woocommerce' ),
1381 'required' => true,
1382 ),
1383 ),
1384 'RS' => array(
1385 'city' => array(
1386 'required' => true,
1387 ),
1388 'postcode' => array(
1389 'required' => true,
1390 ),
1391 'state' => array(
1392 'label' => __( 'District', 'woocommerce' ),
1393 'required' => false,
1394 ),
1395 ),
1396 'SG' => array(
1397 'state' => array(
1398 'required' => false,
1399 'hidden' => true,
1400 ),
1401 'city' => array(
1402 'required' => false,
1403 ),
1404 ),
1405 'SK' => array(
1406 'postcode' => array(
1407 'priority' => 65,
1408 ),
1409 'state' => array(
1410 'required' => false,
1411 'hidden' => true,
1412 ),
1413 ),
1414 'SI' => array(
1415 'postcode' => array(
1416 'priority' => 65,
1417 ),
1418 'state' => array(
1419 'required' => false,
1420 'hidden' => true,
1421 ),
1422 ),
1423 'SR' => array(
1424 'postcode' => array(
1425 'required' => false,
1426 'hidden' => true,
1427 ),
1428 ),
1429 'SV' => array(
1430 'state' => array(
1431 'label' => __( 'Department', 'woocommerce' ),
1432 ),
1433 ),
1434 'ES' => array(
1435 'postcode' => array(
1436 'priority' => 65,
1437 ),
1438 'state' => array(
1439 'label' => __( 'Province', 'woocommerce' ),
1440 ),
1441 ),
1442 'LI' => array(
1443 'postcode' => array(
1444 'priority' => 65,
1445 ),
1446 'state' => array(
1447 'label' => __( 'Municipality', 'woocommerce' ),
1448 'required' => false,
1449 ),
1450 ),
1451 'LK' => array(
1452 'state' => array(
1453 'required' => false,
1454 'hidden' => true,
1455 ),
1456 ),
1457 'LU' => array(
1458 'state' => array(
1459 'required' => false,
1460 'hidden' => true,
1461 ),
1462 ),
1463 'MD' => array(
1464 'state' => array(
1465 'label' => __( 'Municipality / District', 'woocommerce' ),
1466 ),
1467 ),
1468 'SE' => array(
1469 'postcode' => array(
1470 'priority' => 65,
1471 ),
1472 'state' => array(
1473 'required' => false,
1474 'hidden' => true,
1475 ),
1476 ),
1477 'TR' => array(
1478 'postcode' => array(
1479 'priority' => 65,
1480 ),
1481 'state' => array(
1482 'label' => __( 'Province', 'woocommerce' ),
1483 ),
1484 ),
1485 'UG' => array(
1486 'postcode' => array(
1487 'required' => false,
1488 'hidden' => true,
1489 ),
1490 'city' => array(
1491 'label' => __( 'Town / Village', 'woocommerce' ),
1492 'required' => true,
1493 ),
1494 'state' => array(
1495 'label' => __( 'District', 'woocommerce' ),
1496 'required' => true,
1497 ),
1498 ),
1499 'US' => array(
1500 'postcode' => array(
1501 'label' => __( 'ZIP Code', 'woocommerce' ),
1502 ),
1503 'state' => array(
1504 'label' => __( 'State', 'woocommerce' ),
1505 ),
1506 ),
1507 'UY' => array(
1508 'state' => array(
1509 'label' => __( 'Department', 'woocommerce' ),
1510 ),
1511 ),
1512 'GB' => array(
1513 'postcode' => array(
1514 'label' => __( 'Postcode', 'woocommerce' ),
1515 ),
1516 'state' => array(
1517 'label' => __( 'County', 'woocommerce' ),
1518 'required' => false,
1519 ),
1520 ),
1521 'ST' => array(
1522 'postcode' => array(
1523 'required' => false,
1524 'hidden' => true,
1525 ),
1526 'state' => array(
1527 'label' => __( 'District', 'woocommerce' ),
1528 ),
1529 ),
1530 'VN' => array(
1531 'state' => array(
1532 'required' => false,
1533 'hidden' => true,
1534 ),
1535 'postcode' => array(
1536 'priority' => 65,
1537 'required' => false,
1538 'hidden' => false,
1539 ),
1540 'address_2' => array(
1541 'required' => false,
1542 'hidden' => false,
1543 ),
1544 ),
1545 'WS' => array(
1546 'postcode' => array(
1547 'required' => false,
1548 'hidden' => true,
1549 ),
1550 ),
1551 'YT' => array(
1552 'state' => array(
1553 'required' => false,
1554 'hidden' => true,
1555 ),
1556 ),
1557 'ZA' => array(
1558 'state' => array(
1559 'label' => __( 'Province', 'woocommerce' ),
1560 ),
1561 ),
1562 'ZW' => array(
1563 'postcode' => array(
1564 'required' => false,
1565 'hidden' => true,
1566 ),
1567 ),
1568 )
1569 );
1570
1571 $this->locale = array_intersect_key( $this->locale, array_merge( $this->get_allowed_countries(), $this->get_shipping_countries() ) );
1572
1573 // Default Locale Can be filtered to override fields in get_address_fields(). Countries with no specific locale will use default.
1574 $this->locale['default'] = apply_filters( 'woocommerce_get_country_locale_default', $this->get_default_address_fields() );
1575
1576 // Filter default AND shop base locales to allow overides via a single function. These will be used when changing countries on the checkout.
1577 if ( ! isset( $this->locale[ $this->get_base_country() ] ) ) {
1578 $this->locale[ $this->get_base_country() ] = $this->locale['default'];
1579 }
1580
1581 $this->locale['default'] = apply_filters( 'woocommerce_get_country_locale_base', $this->locale['default'] );
1582 $this->locale[ $this->get_base_country() ] = apply_filters( 'woocommerce_get_country_locale_base', $this->locale[ $this->get_base_country() ] );
1583 }
1584
1585 return $this->locale;
1586 }
1587
1588 /**
1589 * Apply locale and get address fields.
1590 *
1591 * @param mixed $country Country.
1592 * @param string $type Address type, defaults to 'billing_'.
1593 * @return array
1594 */
1595 public function get_address_fields( $country = '', $type = 'billing_' ) {
1596 if ( ! $country ) {
1597 $country = $this->get_base_country();
1598 }
1599
1600 $fields = $this->get_default_address_fields();
1601 $locale = $this->get_country_locale();
1602
1603 if ( isset( $locale[ $country ] ) ) {
1604 $fields = wc_array_overlay( $fields, $locale[ $country ] );
1605 }
1606
1607 // Prepend field keys.
1608 $address_fields = array();
1609
1610 foreach ( $fields as $key => $value ) {
1611 if ( 'state' === $key ) {
1612 $value['country_field'] = $type . 'country';
1613 $value['country'] = $country;
1614 }
1615 $address_fields[ $type . $key ] = $value;
1616 }
1617
1618 // Add email and phone fields.
1619 if ( 'billing_' === $type ) {
1620 if ( 'hidden' !== get_option( 'woocommerce_checkout_phone_field', 'required' ) ) {
1621 $address_fields['billing_phone'] = array(
1622 'label' => __( 'Phone', 'woocommerce' ),
1623 'required' => 'required' === get_option( 'woocommerce_checkout_phone_field', 'required' ),
1624 'type' => 'tel',
1625 'class' => array( 'form-row-wide' ),
1626 'validate' => array( 'phone' ),
1627 'autocomplete' => 'tel',
1628 'priority' => 100,
1629 );
1630 }
1631 $address_fields['billing_email'] = array(
1632 'label' => __( 'Email address', 'woocommerce' ),
1633 'required' => true,
1634 'type' => 'email',
1635 'class' => array( 'form-row-wide' ),
1636 'validate' => array( 'email' ),
1637 'autocomplete' => 'no' === get_option( 'woocommerce_registration_generate_username' ) ? 'email' : 'email username',
1638 'priority' => 110,
1639 );
1640 }
1641
1642 /**
1643 * Important note on this filter: Changes to address fields can and will be overridden by
1644 * the woocommerce_default_address_fields. The locales/default locales apply on top based
1645 * on country selection. If you want to change things like the required status of an
1646 * address field, filter woocommerce_default_address_fields instead.
1647 */
1648 $address_fields = apply_filters( 'woocommerce_' . $type . 'fields', $address_fields, $country );
1649 // Sort each of the fields based on priority.
1650 uasort( $address_fields, 'wc_checkout_fields_uasort_comparison' );
1651
1652 return $address_fields;
1653 }
1654 }
1655