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