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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 4 years ago admin 4 years ago blocks 5 years ago cli 4 years ago customizer 4 years ago data-stores 4 years ago emails 4 years ago export 4 years ago gateways 4 years ago import 4 years ago integrations 5 years ago interfaces 4 years ago legacy 5 years ago libraries 6 years ago log-handlers 5 years ago payment-tokens 5 years ago queue 5 years ago rest-api 4 years ago shipping 5 years ago shortcodes 5 years ago theme-support 4 years ago tracks 4 years ago traits 5 years ago walkers 5 years ago wccom-site 5 years ago widgets 4 years ago class-wc-ajax.php 4 years ago class-wc-api.php 5 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 5 years ago class-wc-cart-totals.php 4 years ago class-wc-cart.php 4 years ago class-wc-checkout.php 4 years ago class-wc-cli.php 4 years ago class-wc-comments.php 4 years ago class-wc-countries.php 4 years ago class-wc-coupon.php 5 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 6 years ago class-wc-datetime.php 5 years ago class-wc-deprecated-action-hooks.php 8 years ago class-wc-deprecated-filter-hooks.php 7 years ago class-wc-discounts.php 4 years ago class-wc-download-handler.php 4 years ago class-wc-emails.php 5 years ago class-wc-embed.php 5 years ago class-wc-form-handler.php 5 years ago class-wc-frontend-scripts.php 4 years ago class-wc-geo-ip.php 5 years ago class-wc-geolite-integration.php 6 years ago class-wc-geolocation.php 4 years ago class-wc-https.php 4 years ago class-wc-install.php 4 years ago class-wc-integrations.php 5 years ago class-wc-log-levels.php 5 years ago class-wc-logger.php 5 years ago class-wc-meta-data.php 7 years ago class-wc-order-factory.php 5 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 5 years ago class-wc-order.php 4 years ago class-wc-payment-gateways.php 4 years ago class-wc-payment-tokens.php 5 years ago class-wc-post-data.php 4 years ago class-wc-post-types.php 4 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 5 years ago class-wc-product-variable.php 4 years ago class-wc-product-variation.php 4 years ago class-wc-query.php 4 years ago class-wc-rate-limiter.php 4 years ago class-wc-regenerate-images-request.php 5 years ago class-wc-regenerate-images.php 5 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 5 years ago class-wc-shipping-rate.php 4 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 5 years ago class-wc-template-loader.php 4 years ago class-wc-tracker.php 4 years ago class-wc-validation.php 5 years ago class-wc-webhook.php 5 years ago class-woocommerce.php 4 years ago wc-account-functions.php 5 years ago wc-attribute-functions.php 4 years ago wc-cart-functions.php 5 years ago wc-conditional-functions.php 4 years ago wc-core-functions.php 4 years ago wc-coupon-functions.php 5 years ago wc-deprecated-functions.php 4 years ago wc-formatting-functions.php 4 years ago wc-notice-functions.php 5 years ago wc-order-functions.php 4 years ago wc-order-item-functions.php 5 years ago wc-page-functions.php 5 years ago wc-product-functions.php 4 years ago wc-rest-functions.php 5 years ago wc-stock-functions.php 5 years ago wc-template-functions.php 4 years ago wc-template-hooks.php 5 years ago wc-term-functions.php 4 years ago wc-update-functions.php 4 years ago wc-user-functions.php 5 years ago wc-webhook-functions.php 5 years ago wc-widget-functions.php 5 years ago
class-wc-countries.php
1615 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 ) ? __( 'to the', 'woocommerce' ) : __( 'to', '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 'BH' => array(
886 'postcode' => array(
887 'required' => false,
888 ),
889 'state' => array(
890 'required' => false,
891 'hidden' => true,
892 ),
893 ),
894 'BI' => array(
895 'state' => array(
896 'required' => false,
897 'hidden' => true,
898 ),
899 ),
900 'BO' => array(
901 'postcode' => array(
902 'required' => false,
903 'hidden' => true,
904 ),
905 'state' => array(
906 'label' => __( 'Department', 'woocommerce' ),
907 ),
908 ),
909 'BS' => array(
910 'postcode' => array(
911 'required' => false,
912 'hidden' => true,
913 ),
914 ),
915 'CA' => array(
916 'postcode' => array(
917 'label' => __( 'Postal code', 'woocommerce' ),
918 ),
919 'state' => array(
920 'label' => __( 'Province', 'woocommerce' ),
921 ),
922 ),
923 'CH' => array(
924 'postcode' => array(
925 'priority' => 65,
926 ),
927 'state' => array(
928 'label' => __( 'Canton', 'woocommerce' ),
929 'required' => false,
930 ),
931 ),
932 'CL' => array(
933 'city' => array(
934 'required' => true,
935 ),
936 'postcode' => array(
937 'required' => false,
938 ),
939 'state' => array(
940 'label' => __( 'Region', 'woocommerce' ),
941 ),
942 ),
943 'CN' => array(
944 'state' => array(
945 'label' => __( 'Province', 'woocommerce' ),
946 ),
947 ),
948 'CO' => array(
949 'postcode' => array(
950 'required' => false,
951 ),
952 'state' => array(
953 'label' => __( 'Department', 'woocommerce' ),
954 ),
955 ),
956 'CR' => array(
957 'state' => array(
958 'label' => __( 'Province', 'woocommerce' ),
959 ),
960 ),
961 'CW' => array(
962 'postcode' => array(
963 'required' => false,
964 'hidden' => true,
965 ),
966 'state' => array(
967 'required' => false,
968 ),
969 ),
970 'CZ' => array(
971 'state' => array(
972 'required' => false,
973 'hidden' => true,
974 ),
975 ),
976 'DE' => array(
977 'postcode' => array(
978 'priority' => 65,
979 ),
980 'state' => array(
981 'required' => false,
982 'hidden' => true,
983 ),
984 ),
985 'DK' => array(
986 'postcode' => array(
987 'priority' => 65,
988 ),
989 'state' => array(
990 'required' => false,
991 'hidden' => true,
992 ),
993 ),
994 'DO' => array(
995 'state' => array(
996 'label' => __( 'Province', 'woocommerce' ),
997 ),
998 ),
999 'EC' => array(
1000 'state' => array(
1001 'label' => __( 'Province', 'woocommerce' ),
1002 ),
1003 ),
1004 'EE' => array(
1005 'postcode' => array(
1006 'priority' => 65,
1007 ),
1008 'state' => array(
1009 'required' => false,
1010 'hidden' => true,
1011 ),
1012 ),
1013 'FI' => array(
1014 'postcode' => array(
1015 'priority' => 65,
1016 ),
1017 'state' => array(
1018 'required' => false,
1019 'hidden' => true,
1020 ),
1021 ),
1022 'FR' => array(
1023 'postcode' => array(
1024 'priority' => 65,
1025 ),
1026 'state' => array(
1027 'required' => false,
1028 'hidden' => true,
1029 ),
1030 ),
1031 'GH' => array(
1032 'postcode' => array(
1033 'required' => false,
1034 ),
1035 'state' => array(
1036 'label' => __( 'Region', 'woocommerce' ),
1037 ),
1038 ),
1039 'GP' => array(
1040 'state' => array(
1041 'required' => false,
1042 'hidden' => true,
1043 ),
1044 ),
1045 'GF' => array(
1046 'state' => array(
1047 'required' => false,
1048 'hidden' => true,
1049 ),
1050 ),
1051 'GR' => array(
1052 'state' => array(
1053 'required' => false,
1054 ),
1055 ),
1056 'GT' => array(
1057 'postcode' => array(
1058 'required' => false,
1059 'hidden' => true,
1060 ),
1061 'state' => array(
1062 'label' => __( 'Department', 'woocommerce' ),
1063 ),
1064 ),
1065 'HK' => array(
1066 'postcode' => array(
1067 'required' => false,
1068 ),
1069 'city' => array(
1070 'label' => __( 'Town / District', 'woocommerce' ),
1071 ),
1072 'state' => array(
1073 'label' => __( 'Region', 'woocommerce' ),
1074 ),
1075 ),
1076 'HN' => array(
1077 'state' => array(
1078 'label' => __( 'Department', 'woocommerce' ),
1079 ),
1080 ),
1081 'HU' => array(
1082 'last_name' => array(
1083 'class' => array( 'form-row-first' ),
1084 'priority' => 10,
1085 ),
1086 'first_name' => array(
1087 'class' => array( 'form-row-last' ),
1088 'priority' => 20,
1089 ),
1090 'postcode' => array(
1091 'class' => array( 'form-row-first', 'address-field' ),
1092 'priority' => 65,
1093 ),
1094 'city' => array(
1095 'class' => array( 'form-row-last', 'address-field' ),
1096 ),
1097 'address_1' => array(
1098 'priority' => 71,
1099 ),
1100 'address_2' => array(
1101 'priority' => 72,
1102 ),
1103 'state' => array(
1104 'label' => __( 'County', 'woocommerce' ),
1105 ),
1106 ),
1107 'ID' => array(
1108 'state' => array(
1109 'label' => __( 'Province', 'woocommerce' ),
1110 ),
1111 ),
1112 'IE' => array(
1113 'postcode' => array(
1114 'required' => false,
1115 'label' => __( 'Eircode', 'woocommerce' ),
1116 ),
1117 'state' => array(
1118 'label' => __( 'County', 'woocommerce' ),
1119 ),
1120 ),
1121 'IS' => array(
1122 'postcode' => array(
1123 'priority' => 65,
1124 ),
1125 'state' => array(
1126 'required' => false,
1127 'hidden' => true,
1128 ),
1129 ),
1130 'IL' => array(
1131 'postcode' => array(
1132 'priority' => 65,
1133 ),
1134 'state' => array(
1135 'required' => false,
1136 'hidden' => true,
1137 ),
1138 ),
1139 'IM' => array(
1140 'state' => array(
1141 'required' => false,
1142 'hidden' => true,
1143 ),
1144 ),
1145 'IN' => array(
1146 'postcode' => array(
1147 'label' => __( 'PIN', 'woocommerce' ),
1148 ),
1149 'state' => array(
1150 'label' => __( 'State', 'woocommerce' ),
1151 ),
1152 ),
1153 'IT' => array(
1154 'postcode' => array(
1155 'priority' => 65,
1156 ),
1157 'state' => array(
1158 'required' => true,
1159 'label' => __( 'Province', 'woocommerce' ),
1160 ),
1161 ),
1162 'JM' => array(
1163 'city' => array(
1164 'label' => __( 'Town / City / Post Office', 'woocommerce' ),
1165 ),
1166 'postcode' => array(
1167 'required' => false,
1168 'label' => __( 'Postal Code', 'woocommerce' ),
1169 ),
1170 'state' => array(
1171 'required' => true,
1172 'label' => __( 'Parish', 'woocommerce' ),
1173 ),
1174 ),
1175 'JP' => array(
1176 'last_name' => array(
1177 'class' => array( 'form-row-first' ),
1178 'priority' => 10,
1179 ),
1180 'first_name' => array(
1181 'class' => array( 'form-row-last' ),
1182 'priority' => 20,
1183 ),
1184 'postcode' => array(
1185 'class' => array( 'form-row-first', 'address-field' ),
1186 'priority' => 65,
1187 ),
1188 'state' => array(
1189 'label' => __( 'Prefecture', 'woocommerce' ),
1190 'class' => array( 'form-row-last', 'address-field' ),
1191 'priority' => 66,
1192 ),
1193 'city' => array(
1194 'priority' => 67,
1195 ),
1196 'address_1' => array(
1197 'priority' => 68,
1198 ),
1199 'address_2' => array(
1200 'priority' => 69,
1201 ),
1202 ),
1203 'KR' => array(
1204 'state' => array(
1205 'required' => false,
1206 'hidden' => true,
1207 ),
1208 ),
1209 'KW' => array(
1210 'state' => array(
1211 'required' => false,
1212 'hidden' => true,
1213 ),
1214 ),
1215 'LV' => array(
1216 'state' => array(
1217 'label' => __( 'Municipality', 'woocommerce' ),
1218 'required' => false,
1219 ),
1220 ),
1221 'LB' => array(
1222 'state' => array(
1223 'required' => false,
1224 'hidden' => true,
1225 ),
1226 ),
1227 'MQ' => array(
1228 'state' => array(
1229 'required' => false,
1230 'hidden' => true,
1231 ),
1232 ),
1233 'MT' => array(
1234 'state' => array(
1235 'required' => false,
1236 'hidden' => true,
1237 ),
1238 ),
1239 'MZ' => array(
1240 'postcode' => array(
1241 'required' => false,
1242 'hidden' => true,
1243 ),
1244 'state' => array(
1245 'label' => __( 'Province', 'woocommerce' ),
1246 ),
1247 ),
1248 'NI' => array(
1249 'state' => array(
1250 'label' => __( 'Department', 'woocommerce' ),
1251 ),
1252 ),
1253 'NL' => array(
1254 'postcode' => array(
1255 'priority' => 65,
1256 ),
1257 'state' => array(
1258 'required' => false,
1259 'hidden' => true,
1260 ),
1261 ),
1262 'NG' => array(
1263 'postcode' => array(
1264 'label' => __( 'Postcode', 'woocommerce' ),
1265 'required' => false,
1266 'hidden' => true,
1267 ),
1268 'state' => array(
1269 'label' => __( 'State', 'woocommerce' ),
1270 ),
1271 ),
1272 'NZ' => array(
1273 'postcode' => array(
1274 'label' => __( 'Postcode', 'woocommerce' ),
1275 ),
1276 'state' => array(
1277 'required' => false,
1278 'label' => __( 'Region', 'woocommerce' ),
1279 ),
1280 ),
1281 'NO' => array(
1282 'postcode' => array(
1283 'priority' => 65,
1284 ),
1285 'state' => array(
1286 'required' => false,
1287 'hidden' => true,
1288 ),
1289 ),
1290 'NP' => array(
1291 'state' => array(
1292 'label' => __( 'State / Zone', 'woocommerce' ),
1293 ),
1294 'postcode' => array(
1295 'required' => false,
1296 ),
1297 ),
1298 'PA' => array(
1299 'state' => array(
1300 'label' => __( 'Province', 'woocommerce' ),
1301 ),
1302 ),
1303 'PL' => array(
1304 'postcode' => array(
1305 'priority' => 65,
1306 ),
1307 'state' => array(
1308 'required' => false,
1309 'hidden' => true,
1310 ),
1311 ),
1312 'PR' => array(
1313 'city' => array(
1314 'label' => __( 'Municipality', 'woocommerce' ),
1315 ),
1316 'state' => array(
1317 'required' => false,
1318 'hidden' => true,
1319 ),
1320 ),
1321 'PT' => array(
1322 'state' => array(
1323 'required' => false,
1324 'hidden' => true,
1325 ),
1326 ),
1327 'PY' => array(
1328 'state' => array(
1329 'label' => __( 'Department', 'woocommerce' ),
1330 ),
1331 ),
1332 'RE' => array(
1333 'state' => array(
1334 'required' => false,
1335 'hidden' => true,
1336 ),
1337 ),
1338 'RO' => array(
1339 'state' => array(
1340 'label' => __( 'County', 'woocommerce' ),
1341 'required' => true,
1342 ),
1343 ),
1344 'RS' => array(
1345 'city' => array(
1346 'required' => true,
1347 ),
1348 'postcode' => array(
1349 'required' => true,
1350 ),
1351 'state' => array(
1352 'label' => __( 'District', 'woocommerce' ),
1353 'required' => false,
1354 ),
1355 ),
1356 'SG' => array(
1357 'state' => array(
1358 'required' => false,
1359 'hidden' => true,
1360 ),
1361 'city' => array(
1362 'required' => false,
1363 ),
1364 ),
1365 'SK' => array(
1366 'postcode' => array(
1367 'priority' => 65,
1368 ),
1369 'state' => array(
1370 'required' => false,
1371 'hidden' => true,
1372 ),
1373 ),
1374 'SI' => array(
1375 'postcode' => array(
1376 'priority' => 65,
1377 ),
1378 'state' => array(
1379 'required' => false,
1380 'hidden' => true,
1381 ),
1382 ),
1383 'SR' => array(
1384 'postcode' => array(
1385 'required' => false,
1386 'hidden' => true,
1387 ),
1388 ),
1389 'SV' => array(
1390 'state' => array(
1391 'label' => __( 'Department', 'woocommerce' ),
1392 ),
1393 ),
1394 'ES' => array(
1395 'postcode' => array(
1396 'priority' => 65,
1397 ),
1398 'state' => array(
1399 'label' => __( 'Province', 'woocommerce' ),
1400 ),
1401 ),
1402 'LI' => array(
1403 'postcode' => array(
1404 'priority' => 65,
1405 ),
1406 'state' => array(
1407 'label' => __( 'Municipality', 'woocommerce' ),
1408 'required' => false,
1409 ),
1410 ),
1411 'LK' => array(
1412 'state' => array(
1413 'required' => false,
1414 'hidden' => true,
1415 ),
1416 ),
1417 'LU' => array(
1418 'state' => array(
1419 'required' => false,
1420 'hidden' => true,
1421 ),
1422 ),
1423 'MD' => array(
1424 'state' => array(
1425 'label' => __( 'Municipality / District', 'woocommerce' ),
1426 ),
1427 ),
1428 'SE' => array(
1429 'postcode' => array(
1430 'priority' => 65,
1431 ),
1432 'state' => array(
1433 'required' => false,
1434 'hidden' => true,
1435 ),
1436 ),
1437 'TR' => array(
1438 'postcode' => array(
1439 'priority' => 65,
1440 ),
1441 'state' => array(
1442 'label' => __( 'Province', 'woocommerce' ),
1443 ),
1444 ),
1445 'UG' => array(
1446 'postcode' => array(
1447 'required' => false,
1448 'hidden' => true,
1449 ),
1450 'city' => array(
1451 'label' => __( 'Town / Village', 'woocommerce' ),
1452 'required' => true,
1453 ),
1454 'state' => array(
1455 'label' => __( 'District', 'woocommerce' ),
1456 'required' => true,
1457 ),
1458 ),
1459 'US' => array(
1460 'postcode' => array(
1461 'label' => __( 'ZIP Code', 'woocommerce' ),
1462 ),
1463 'state' => array(
1464 'label' => __( 'State', 'woocommerce' ),
1465 ),
1466 ),
1467 'UY' => array(
1468 'state' => array(
1469 'label' => __( 'Department', 'woocommerce' ),
1470 ),
1471 ),
1472 'GB' => array(
1473 'postcode' => array(
1474 'label' => __( 'Postcode', 'woocommerce' ),
1475 ),
1476 'state' => array(
1477 'label' => __( 'County', 'woocommerce' ),
1478 'required' => false,
1479 ),
1480 ),
1481 'ST' => array(
1482 'postcode' => array(
1483 'required' => false,
1484 'hidden' => true,
1485 ),
1486 'state' => array(
1487 'label' => __( 'District', 'woocommerce' ),
1488 ),
1489 ),
1490 'VN' => array(
1491 'state' => array(
1492 'required' => false,
1493 'hidden' => true,
1494 ),
1495 'postcode' => array(
1496 'priority' => 65,
1497 'required' => false,
1498 'hidden' => false,
1499 ),
1500 'address_2' => array(
1501 'required' => false,
1502 'hidden' => true,
1503 ),
1504 ),
1505 'WS' => array(
1506 'postcode' => array(
1507 'required' => false,
1508 'hidden' => true,
1509 ),
1510 ),
1511 'YT' => array(
1512 'state' => array(
1513 'required' => false,
1514 'hidden' => true,
1515 ),
1516 ),
1517 'ZA' => array(
1518 'state' => array(
1519 'label' => __( 'Province', 'woocommerce' ),
1520 ),
1521 ),
1522 'ZW' => array(
1523 'postcode' => array(
1524 'required' => false,
1525 'hidden' => true,
1526 ),
1527 ),
1528 )
1529 );
1530
1531 $this->locale = array_intersect_key( $this->locale, array_merge( $this->get_allowed_countries(), $this->get_shipping_countries() ) );
1532
1533 // Default Locale Can be filtered to override fields in get_address_fields(). Countries with no specific locale will use default.
1534 $this->locale['default'] = apply_filters( 'woocommerce_get_country_locale_default', $this->get_default_address_fields() );
1535
1536 // Filter default AND shop base locales to allow overides via a single function. These will be used when changing countries on the checkout.
1537 if ( ! isset( $this->locale[ $this->get_base_country() ] ) ) {
1538 $this->locale[ $this->get_base_country() ] = $this->locale['default'];
1539 }
1540
1541 $this->locale['default'] = apply_filters( 'woocommerce_get_country_locale_base', $this->locale['default'] );
1542 $this->locale[ $this->get_base_country() ] = apply_filters( 'woocommerce_get_country_locale_base', $this->locale[ $this->get_base_country() ] );
1543 }
1544
1545 return $this->locale;
1546 }
1547
1548 /**
1549 * Apply locale and get address fields.
1550 *
1551 * @param mixed $country Country.
1552 * @param string $type Address type, defaults to 'billing_'.
1553 * @return array
1554 */
1555 public function get_address_fields( $country = '', $type = 'billing_' ) {
1556 if ( ! $country ) {
1557 $country = $this->get_base_country();
1558 }
1559
1560 $fields = $this->get_default_address_fields();
1561 $locale = $this->get_country_locale();
1562
1563 if ( isset( $locale[ $country ] ) ) {
1564 $fields = wc_array_overlay( $fields, $locale[ $country ] );
1565 }
1566
1567 // Prepend field keys.
1568 $address_fields = array();
1569
1570 foreach ( $fields as $key => $value ) {
1571 if ( 'state' === $key ) {
1572 $value['country_field'] = $type . 'country';
1573 $value['country'] = $country;
1574 }
1575 $address_fields[ $type . $key ] = $value;
1576 }
1577
1578 // Add email and phone fields.
1579 if ( 'billing_' === $type ) {
1580 if ( 'hidden' !== get_option( 'woocommerce_checkout_phone_field', 'required' ) ) {
1581 $address_fields['billing_phone'] = array(
1582 'label' => __( 'Phone', 'woocommerce' ),
1583 'required' => 'required' === get_option( 'woocommerce_checkout_phone_field', 'required' ),
1584 'type' => 'tel',
1585 'class' => array( 'form-row-wide' ),
1586 'validate' => array( 'phone' ),
1587 'autocomplete' => 'tel',
1588 'priority' => 100,
1589 );
1590 }
1591 $address_fields['billing_email'] = array(
1592 'label' => __( 'Email address', 'woocommerce' ),
1593 'required' => true,
1594 'type' => 'email',
1595 'class' => array( 'form-row-wide' ),
1596 'validate' => array( 'email' ),
1597 'autocomplete' => 'no' === get_option( 'woocommerce_registration_generate_username' ) ? 'email' : 'email username',
1598 'priority' => 110,
1599 );
1600 }
1601
1602 /**
1603 * Important note on this filter: Changes to address fields can and will be overridden by
1604 * the woocommerce_default_address_fields. The locales/default locales apply on top based
1605 * on country selection. If you want to change things like the required status of an
1606 * address field, filter woocommerce_default_address_fields instead.
1607 */
1608 $address_fields = apply_filters( 'woocommerce_' . $type . 'fields', $address_fields, $country );
1609 // Sort each of the fields based on priority.
1610 uasort( $address_fields, 'wc_checkout_fields_uasort_comparison' );
1611
1612 return $address_fields;
1613 }
1614 }
1615