2011-08-09 15:16:18 +00:00
|
|
|
<?php
|
2017-12-21 20:10:55 +00:00
|
|
|
/**
|
|
|
|
* WooCommerce countries
|
|
|
|
*
|
2018-03-19 22:42:55 +00:00
|
|
|
* @package WooCommerce\l10n
|
|
|
|
* @version 3.3.0
|
2017-12-21 20:10:55 +00:00
|
|
|
*/
|
2015-11-06 09:22:19 +00:00
|
|
|
|
2018-03-19 22:42:55 +00:00
|
|
|
defined( 'ABSPATH' ) || exit;
|
2015-11-06 09:22:19 +00:00
|
|
|
|
2011-08-09 15:16:18 +00:00
|
|
|
/**
|
2011-08-10 17:11:11 +00:00
|
|
|
* The WooCommerce countries class stores country/state data.
|
2011-08-09 15:16:18 +00:00
|
|
|
*/
|
2012-01-27 16:38:39 +00:00
|
|
|
class WC_Countries {
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2017-12-21 20:10:55 +00:00
|
|
|
/**
|
|
|
|
* Locales list.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $locale = array();
|
2012-08-14 19:42:38 +00:00
|
|
|
|
2017-12-21 20:10:55 +00:00
|
|
|
/**
|
|
|
|
* List of address formats for locales.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $address_formats = array();
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2011-11-17 10:40:32 +00:00
|
|
|
/**
|
2014-05-28 15:48:21 +00:00
|
|
|
* Auto-load in-accessible properties on demand.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
|
|
|
* @param mixed $key Key.
|
2014-05-28 15:48:21 +00:00
|
|
|
* @return mixed
|
2011-11-17 10:40:32 +00:00
|
|
|
*/
|
2014-05-28 15:48:21 +00:00
|
|
|
public function __get( $key ) {
|
2017-12-21 20:10:55 +00:00
|
|
|
if ( 'countries' === $key ) {
|
2014-05-28 15:48:21 +00:00
|
|
|
return $this->get_countries();
|
2017-12-21 20:10:55 +00:00
|
|
|
} elseif ( 'states' === $key ) {
|
2014-05-28 15:48:21 +00:00
|
|
|
return $this->get_states();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-01-18 18:59:17 +00:00
|
|
|
* Get all countries.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
2014-05-28 15:48:21 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_countries() {
|
|
|
|
if ( empty( $this->countries ) ) {
|
2020-08-19 23:22:18 +00:00
|
|
|
$this->countries = apply_filters( 'woocommerce_countries', include WC()->plugin_path() . '/i18n/countries.php' );
|
2015-01-18 18:59:17 +00:00
|
|
|
if ( apply_filters( 'woocommerce_sort_countries', true ) ) {
|
2020-09-10 19:02:39 +00:00
|
|
|
wc_asort_by_locale( $this->countries );
|
2014-05-28 15:48:21 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-21 20:10:55 +00:00
|
|
|
|
2014-05-28 15:48:21 +00:00
|
|
|
return $this->countries;
|
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2015-12-08 11:15:02 +00:00
|
|
|
/**
|
|
|
|
* Get all continents.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
2015-12-08 11:15:02 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_continents() {
|
|
|
|
if ( empty( $this->continents ) ) {
|
2017-12-21 20:18:04 +00:00
|
|
|
$this->continents = apply_filters( 'woocommerce_continents', include WC()->plugin_path() . '/i18n/continents.php' );
|
2015-12-08 11:15:02 +00:00
|
|
|
}
|
2017-12-21 20:10:55 +00:00
|
|
|
|
2015-12-08 11:15:02 +00:00
|
|
|
return $this->continents;
|
|
|
|
}
|
|
|
|
|
2015-12-15 12:39:52 +00:00
|
|
|
/**
|
|
|
|
* Get continent code for a country code.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
2015-12-15 12:39:52 +00:00
|
|
|
* @since 2.6.0
|
2019-01-09 17:54:37 +00:00
|
|
|
* @param string $cc Country code.
|
2015-12-15 12:39:52 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_continent_code_for_country( $cc ) {
|
2015-12-15 15:00:45 +00:00
|
|
|
$cc = trim( strtoupper( $cc ) );
|
2015-12-15 12:39:52 +00:00
|
|
|
$continents = $this->get_continents();
|
|
|
|
$continents_and_ccs = wp_list_pluck( $continents, 'countries' );
|
2015-12-15 15:00:45 +00:00
|
|
|
foreach ( $continents_and_ccs as $continent_code => $countries ) {
|
2018-03-19 22:42:55 +00:00
|
|
|
if ( false !== array_search( $cc, $countries, true ) ) {
|
2015-12-15 15:00:45 +00:00
|
|
|
return $continent_code;
|
|
|
|
}
|
|
|
|
}
|
2017-12-21 20:10:55 +00:00
|
|
|
|
2015-12-15 15:00:45 +00:00
|
|
|
return '';
|
2015-12-15 12:39:52 +00:00
|
|
|
}
|
|
|
|
|
2019-02-08 11:09:42 +00:00
|
|
|
/**
|
|
|
|
* Get calling code for a country code.
|
|
|
|
*
|
|
|
|
* @since 3.6.0
|
|
|
|
* @param string $cc Country code.
|
2019-03-06 12:33:46 +00:00
|
|
|
* @return string|array Some countries have multiple. The code will be stripped of - and spaces and always be prefixed with +.
|
2019-02-08 11:09:42 +00:00
|
|
|
*/
|
2019-03-06 12:25:06 +00:00
|
|
|
public function get_country_calling_code( $cc ) {
|
2019-02-08 11:09:42 +00:00
|
|
|
$codes = wp_cache_get( 'calling-codes', 'countries' );
|
|
|
|
|
|
|
|
if ( ! $codes ) {
|
2019-03-06 12:25:06 +00:00
|
|
|
$codes = include WC()->plugin_path() . '/i18n/phone.php';
|
2019-02-08 11:09:42 +00:00
|
|
|
wp_cache_set( 'calling-codes', $codes, 'countries' );
|
|
|
|
}
|
|
|
|
|
2019-03-06 12:25:06 +00:00
|
|
|
$calling_code = isset( $codes[ $cc ] ) ? $codes[ $cc ] : '';
|
|
|
|
|
|
|
|
if ( is_array( $calling_code ) ) {
|
|
|
|
$calling_code = $calling_code[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $calling_code;
|
2019-02-08 11:09:42 +00:00
|
|
|
}
|
|
|
|
|
2019-01-09 17:48:18 +00:00
|
|
|
/**
|
|
|
|
* Get continents that the store ships to.
|
|
|
|
*
|
2019-01-09 18:31:30 +00:00
|
|
|
* @since 3.6.0
|
2019-01-09 17:48:18 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_shipping_continents() {
|
|
|
|
$continents = $this->get_continents();
|
|
|
|
$shipping_countries = $this->get_shipping_countries();
|
|
|
|
$shipping_country_codes = array_keys( $shipping_countries );
|
|
|
|
$shipping_continents = array();
|
|
|
|
|
|
|
|
foreach ( $continents as $continent_code => $continent ) {
|
|
|
|
if ( count( array_intersect( $continent['countries'], $shipping_country_codes ) ) ) {
|
|
|
|
$shipping_continents[ $continent_code ] = $continent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $shipping_continents;
|
|
|
|
}
|
|
|
|
|
2014-05-28 15:48:21 +00:00
|
|
|
/**
|
2015-01-18 18:59:17 +00:00
|
|
|
* Load the states.
|
2019-01-04 12:04:47 +00:00
|
|
|
*
|
|
|
|
* @deprecated 3.6.0 This method was used to load state files, but is no longer needed. @see get_states().
|
2014-05-28 15:48:21 +00:00
|
|
|
*/
|
|
|
|
public function load_country_states() {
|
|
|
|
global $states;
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2019-01-04 12:04:47 +00:00
|
|
|
$states = include WC()->plugin_path() . '/i18n/states.php';
|
2013-09-24 15:56:55 +00:00
|
|
|
$this->states = apply_filters( 'woocommerce_states', $states );
|
2011-11-17 10:40:32 +00:00
|
|
|
}
|
2012-01-16 06:37:50 +00:00
|
|
|
|
2014-05-28 15:48:21 +00:00
|
|
|
/**
|
|
|
|
* Get the states for a country.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
|
|
|
* @param string $cc Country code.
|
2017-05-15 11:50:52 +00:00
|
|
|
* @return false|array of states
|
2014-05-28 15:48:21 +00:00
|
|
|
*/
|
2014-05-30 12:33:09 +00:00
|
|
|
public function get_states( $cc = null ) {
|
2019-01-04 12:04:47 +00:00
|
|
|
if ( ! isset( $this->states ) ) {
|
|
|
|
$this->states = apply_filters( 'woocommerce_states', include WC()->plugin_path() . '/i18n/states.php' );
|
2014-05-28 15:48:21 +00:00
|
|
|
}
|
2015-01-18 18:59:17 +00:00
|
|
|
|
2014-05-30 12:33:09 +00:00
|
|
|
if ( ! is_null( $cc ) ) {
|
2014-05-28 15:48:21 +00:00
|
|
|
return isset( $this->states[ $cc ] ) ? $this->states[ $cc ] : false;
|
|
|
|
} else {
|
|
|
|
return $this->states;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 17:54:24 +00:00
|
|
|
/**
|
|
|
|
* Get the base address (first line) for the store.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
2017-06-15 17:54:24 +00:00
|
|
|
* @since 3.1.1
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_base_address() {
|
|
|
|
$base_address = get_option( 'woocommerce_store_address', '' );
|
|
|
|
return apply_filters( 'woocommerce_countries_base_address', $base_address );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the base address (second line) for the store.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
2017-06-15 17:54:24 +00:00
|
|
|
* @since 3.1.1
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_base_address_2() {
|
|
|
|
$base_address_2 = get_option( 'woocommerce_store_address_2', '' );
|
|
|
|
return apply_filters( 'woocommerce_countries_base_address_2', $base_address_2 );
|
|
|
|
}
|
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
/**
|
|
|
|
* Get the base country for the store.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
2012-08-14 19:42:38 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function get_base_country() {
|
2014-12-23 17:34:05 +00:00
|
|
|
$default = wc_get_base_location();
|
|
|
|
return apply_filters( 'woocommerce_countries_base_country', $default['country'] );
|
2013-09-24 15:56:55 +00:00
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
2013-09-24 15:56:55 +00:00
|
|
|
* Get the base state for the store.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
2012-08-14 19:42:38 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function get_base_state() {
|
2014-12-23 17:34:05 +00:00
|
|
|
$default = wc_get_base_location();
|
|
|
|
return apply_filters( 'woocommerce_countries_base_state', $default['state'] );
|
2013-09-24 15:56:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the base city for the store.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
2017-06-15 17:54:24 +00:00
|
|
|
* @version 3.1.1
|
2013-09-24 15:56:55 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_base_city() {
|
2017-06-15 17:54:24 +00:00
|
|
|
$base_city = get_option( 'woocommerce_store_city', '' );
|
|
|
|
return apply_filters( 'woocommerce_countries_base_city', $base_city );
|
2013-09-24 15:56:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the base postcode for the store.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
2017-06-15 17:54:24 +00:00
|
|
|
* @since 3.1.1
|
2013-09-24 15:56:55 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_base_postcode() {
|
2017-06-15 17:54:24 +00:00
|
|
|
$base_postcode = get_option( 'woocommerce_store_postcode', '' );
|
|
|
|
return apply_filters( 'woocommerce_countries_base_postcode', $base_postcode );
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-01-16 06:37:50 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
/**
|
2019-01-09 17:54:37 +00:00
|
|
|
* Get countries that the store sells to.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
2012-08-14 19:42:38 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function get_allowed_countries() {
|
2016-04-28 16:37:30 +00:00
|
|
|
if ( 'all' === get_option( 'woocommerce_allowed_countries' ) ) {
|
2017-09-06 09:40:40 +00:00
|
|
|
return apply_filters( 'woocommerce_countries_allowed_countries', $this->countries );
|
2016-04-28 16:37:30 +00:00
|
|
|
}
|
|
|
|
|
2016-08-27 04:23:02 +00:00
|
|
|
if ( 'all_except' === get_option( 'woocommerce_allowed_countries' ) ) {
|
2016-04-20 17:55:05 +00:00
|
|
|
$except_countries = get_option( 'woocommerce_all_except_countries', array() );
|
|
|
|
|
|
|
|
if ( ! $except_countries ) {
|
|
|
|
return $this->countries;
|
|
|
|
} else {
|
|
|
|
$all_except_countries = $this->countries;
|
2016-08-27 04:23:02 +00:00
|
|
|
foreach ( $except_countries as $country ) {
|
2016-04-20 17:55:05 +00:00
|
|
|
unset( $all_except_countries[ $country ] );
|
|
|
|
}
|
|
|
|
return apply_filters( 'woocommerce_countries_allowed_countries', $all_except_countries );
|
|
|
|
}
|
2014-05-28 15:48:21 +00:00
|
|
|
}
|
2011-08-09 15:16:18 +00:00
|
|
|
|
2013-08-02 15:54:28 +00:00
|
|
|
$countries = array();
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2016-02-01 12:04:30 +00:00
|
|
|
$raw_countries = get_option( 'woocommerce_specific_allowed_countries', array() );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2016-02-01 12:04:30 +00:00
|
|
|
if ( $raw_countries ) {
|
|
|
|
foreach ( $raw_countries as $country ) {
|
|
|
|
$countries[ $country ] = $this->countries[ $country ];
|
|
|
|
}
|
2015-01-18 18:59:17 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2013-08-02 15:54:28 +00:00
|
|
|
return apply_filters( 'woocommerce_countries_allowed_countries', $countries );
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2013-08-02 15:54:28 +00:00
|
|
|
/**
|
2019-01-09 17:54:37 +00:00
|
|
|
* Get countries that the store ships to.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
2013-08-02 15:54:28 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_shipping_countries() {
|
2016-04-20 17:55:05 +00:00
|
|
|
if ( '' === get_option( 'woocommerce_ship_to_countries' ) ) {
|
2016-04-28 16:37:30 +00:00
|
|
|
return $this->get_allowed_countries();
|
2015-01-18 18:59:17 +00:00
|
|
|
}
|
2013-08-02 15:54:28 +00:00
|
|
|
|
2016-04-28 16:37:30 +00:00
|
|
|
if ( 'all' === get_option( 'woocommerce_ship_to_countries' ) ) {
|
|
|
|
return $this->countries;
|
2015-01-18 18:59:17 +00:00
|
|
|
}
|
2013-08-02 15:54:28 +00:00
|
|
|
|
|
|
|
$countries = array();
|
|
|
|
|
|
|
|
$raw_countries = get_option( 'woocommerce_specific_ship_to_countries' );
|
|
|
|
|
2016-05-14 09:02:05 +00:00
|
|
|
if ( $raw_countries ) {
|
|
|
|
foreach ( $raw_countries as $country ) {
|
|
|
|
$countries[ $country ] = $this->countries[ $country ];
|
|
|
|
}
|
2015-01-18 18:59:17 +00:00
|
|
|
}
|
2013-08-02 15:54:28 +00:00
|
|
|
|
|
|
|
return apply_filters( 'woocommerce_countries_shipping_countries', $countries );
|
|
|
|
}
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2012-08-22 15:13:58 +00:00
|
|
|
/**
|
2016-01-06 14:51:58 +00:00
|
|
|
* Get allowed country states.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
2012-08-22 15:13:58 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function get_allowed_country_states() {
|
2015-01-18 18:59:17 +00:00
|
|
|
if ( get_option( 'woocommerce_allowed_countries' ) !== 'specific' ) {
|
2012-08-22 15:13:58 +00:00
|
|
|
return $this->states;
|
2015-01-18 18:59:17 +00:00
|
|
|
}
|
2012-08-22 15:13:58 +00:00
|
|
|
|
2013-08-02 15:54:28 +00:00
|
|
|
$states = array();
|
2012-08-22 15:13:58 +00:00
|
|
|
|
2013-08-02 15:54:28 +00:00
|
|
|
$raw_countries = get_option( 'woocommerce_specific_allowed_countries' );
|
2012-08-22 15:13:58 +00:00
|
|
|
|
2016-05-14 09:02:05 +00:00
|
|
|
if ( $raw_countries ) {
|
|
|
|
foreach ( $raw_countries as $country ) {
|
|
|
|
if ( isset( $this->states[ $country ] ) ) {
|
|
|
|
$states[ $country ] = $this->states[ $country ];
|
|
|
|
}
|
2015-01-18 18:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-22 15:13:58 +00:00
|
|
|
|
2013-08-02 15:54:28 +00:00
|
|
|
return apply_filters( 'woocommerce_countries_allowed_country_states', $states );
|
2012-08-22 15:13:58 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2013-08-02 15:54:28 +00:00
|
|
|
/**
|
2016-01-06 14:51:58 +00:00
|
|
|
* Get shipping country states.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
2013-08-02 15:54:28 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_shipping_country_states() {
|
2017-12-21 20:10:55 +00:00
|
|
|
if ( get_option( 'woocommerce_ship_to_countries' ) === '' ) {
|
2013-08-02 15:54:28 +00:00
|
|
|
return $this->get_allowed_country_states();
|
2015-01-18 18:59:17 +00:00
|
|
|
}
|
2013-08-02 15:54:28 +00:00
|
|
|
|
2015-01-18 18:59:17 +00:00
|
|
|
if ( get_option( 'woocommerce_ship_to_countries' ) !== 'specific' ) {
|
2013-08-02 15:54:28 +00:00
|
|
|
return $this->states;
|
2015-01-18 18:59:17 +00:00
|
|
|
}
|
2013-08-02 15:54:28 +00:00
|
|
|
|
|
|
|
$states = array();
|
|
|
|
|
|
|
|
$raw_countries = get_option( 'woocommerce_specific_ship_to_countries' );
|
|
|
|
|
2016-05-14 09:02:05 +00:00
|
|
|
if ( $raw_countries ) {
|
|
|
|
foreach ( $raw_countries as $country ) {
|
|
|
|
if ( ! empty( $this->states[ $country ] ) ) {
|
|
|
|
$states[ $country ] = $this->states[ $country ];
|
|
|
|
}
|
2015-01-18 18:59:17 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-02 15:54:28 +00:00
|
|
|
|
|
|
|
return apply_filters( 'woocommerce_countries_shipping_country_states', $states );
|
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets an array of countries in the EU.
|
|
|
|
*
|
2020-04-07 22:01:46 +00:00
|
|
|
* @param string $type Type of countries to retrieve. Blank for EU member countries. eu_vat for EU VAT countries.
|
2014-09-07 23:37:55 +00:00
|
|
|
* @return string[]
|
2012-08-14 19:42:38 +00:00
|
|
|
*/
|
2020-04-07 22:01:46 +00:00
|
|
|
public function get_european_union_countries( $type = '' ) {
|
2019-10-31 07:33:14 +00:00
|
|
|
$countries = array( 'AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GR', 'HU', 'HR', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK' );
|
2015-01-05 17:29:01 +00:00
|
|
|
|
2020-04-07 22:01:46 +00:00
|
|
|
if ( 'eu_vat' === $type ) {
|
|
|
|
$countries[] = 'MC';
|
2015-01-05 17:29:01 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 22:01:46 +00:00
|
|
|
return apply_filters( 'woocommerce_european_union_countries', $countries, $type );
|
2011-10-31 10:54:49 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2019-11-07 19:48:05 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
2020-02-05 14:11:24 +00:00
|
|
|
* @deprecated 4.0.0
|
2019-10-31 07:18:34 +00:00
|
|
|
* @since 3.9.0
|
2019-11-07 19:48:05 +00:00
|
|
|
* @return string[]
|
|
|
|
*/
|
|
|
|
public function countries_using_vat() {
|
2020-02-05 18:18:08 +00:00
|
|
|
wc_deprecated_function( 'countries_using_vat', '4.0', 'WC_Countries::get_vat_countries' );
|
2019-11-09 10:54:09 +00:00
|
|
|
$countries = array( 'AL', 'AR', 'AZ', 'BS', 'BH', 'BY', 'BB', 'BO', 'EG', 'ET', 'CL', 'CO', 'EC', 'SV', 'FJ', 'GM', 'GH', 'GT', 'IN', 'IR', 'IL', 'KZ', 'MU', 'MK', 'MX', 'MD', 'MN', 'ME', 'NA', 'NP', 'NG', 'PS', 'PY', 'RU', 'RW', 'KN', 'SA', 'RS', 'ZA', 'KR', 'LK', 'TH', 'TR', 'UA', 'UY', 'UZ', 'VE', 'VN', 'AE' );
|
2019-11-07 19:48:05 +00:00
|
|
|
|
|
|
|
return apply_filters( 'woocommerce_countries_using_vat', $countries );
|
|
|
|
}
|
|
|
|
|
2020-01-27 16:19:16 +00:00
|
|
|
/**
|
|
|
|
* Gets an array of countries using VAT.
|
|
|
|
*
|
|
|
|
* @since 4.0.0
|
2020-02-05 14:11:24 +00:00
|
|
|
* @return string[] of country codes.
|
2019-10-31 07:18:34 +00:00
|
|
|
*/
|
|
|
|
public function get_vat_countries() {
|
2020-01-27 16:15:54 +00:00
|
|
|
$eu_countries = $this->get_european_union_countries();
|
2020-02-05 14:11:24 +00:00
|
|
|
$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' );
|
2019-10-31 07:18:34 +00:00
|
|
|
|
2020-02-05 14:11:46 +00:00
|
|
|
return apply_filters( 'woocommerce_vat_countries', array_merge( $eu_countries, $vat_countries ) );
|
2011-10-31 10:54:49 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
/**
|
2017-12-21 20:10:55 +00:00
|
|
|
* Gets the correct string for shipping - either 'to the' or 'to'.
|
2017-05-15 11:50:52 +00:00
|
|
|
*
|
2017-12-21 20:10:55 +00:00
|
|
|
* @param string $country_code Country code.
|
2012-08-14 19:42:38 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2016-01-25 10:06:53 +00:00
|
|
|
public function shipping_to_prefix( $country_code = '' ) {
|
|
|
|
$country_code = $country_code ? $country_code : WC()->customer->get_shipping_country();
|
|
|
|
$countries = array( 'GB', 'US', 'AE', 'CZ', 'DO', 'NL', 'PH', 'USAF' );
|
2018-03-19 22:42:55 +00:00
|
|
|
$return = in_array( $country_code, $countries, true ) ? __( 'to the', 'woocommerce' ) : __( 'to', 'woocommerce' );
|
2014-11-20 00:43:09 +00:00
|
|
|
|
2016-01-25 10:06:53 +00:00
|
|
|
return apply_filters( 'woocommerce_countries_shipping_to_prefix', $return, $country_code );
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
/**
|
2017-12-21 20:10:55 +00:00
|
|
|
* Prefix certain countries with 'the'.
|
2017-05-15 11:50:52 +00:00
|
|
|
*
|
2017-12-21 20:10:55 +00:00
|
|
|
* @param string $country_code Country code.
|
2012-08-14 19:42:38 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2016-01-25 10:06:53 +00:00
|
|
|
public function estimated_for_prefix( $country_code = '' ) {
|
|
|
|
$country_code = $country_code ? $country_code : $this->get_base_country();
|
|
|
|
$countries = array( 'GB', 'US', 'AE', 'CZ', 'DO', 'NL', 'PH', 'USAF' );
|
2018-03-19 22:42:55 +00:00
|
|
|
$return = in_array( $country_code, $countries, true ) ? __( 'the', 'woocommerce' ) . ' ' : '';
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2016-01-25 10:06:53 +00:00
|
|
|
return apply_filters( 'woocommerce_countries_estimated_for_prefix', $return, $country_code );
|
2015-01-18 18:59:17 +00:00
|
|
|
}
|
2012-08-14 19:42:38 +00:00
|
|
|
|
|
|
|
/**
|
2015-01-18 18:59:17 +00:00
|
|
|
* Correctly name tax in some countries VAT on the frontend.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
2012-08-14 19:42:38 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function tax_or_vat() {
|
2019-10-31 07:18:34 +00:00
|
|
|
$return = in_array( $this->get_base_country(), $this->get_vat_countries(), true ) ? __( 'VAT', 'woocommerce' ) : __( 'Tax', 'woocommerce' );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
return apply_filters( 'woocommerce_countries_tax_or_vat', $return );
|
2011-10-31 10:54:49 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
/**
|
|
|
|
* Include the Inc Tax label.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
2012-08-14 19:42:38 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function inc_tax_or_vat() {
|
2019-10-31 07:18:34 +00:00
|
|
|
$return = in_array( $this->get_base_country(), $this->get_vat_countries(), true ) ? __( '(incl. VAT)', 'woocommerce' ) : __( '(incl. tax)', 'woocommerce' );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
return apply_filters( 'woocommerce_countries_inc_tax_or_vat', $return );
|
2011-10-31 10:54:49 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
/**
|
|
|
|
* Include the Ex Tax label.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
2012-08-14 19:42:38 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function ex_tax_or_vat() {
|
2019-10-31 07:18:34 +00:00
|
|
|
$return = in_array( $this->get_base_country(), $this->get_vat_countries(), true ) ? __( '(ex. VAT)', 'woocommerce' ) : __( '(ex. tax)', 'woocommerce' );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
return apply_filters( 'woocommerce_countries_ex_tax_or_vat', $return );
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
/**
|
|
|
|
* Outputs the list of countries and states for use in dropdown boxes.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
|
|
|
* @param string $selected_country Selected country.
|
|
|
|
* @param string $selected_state Selected state.
|
2019-01-04 11:07:23 +00:00
|
|
|
* @param bool $escape If we should escape HTML.
|
2012-08-14 19:42:38 +00:00
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function country_dropdown_options( $selected_country = '', $selected_state = '', $escape = false ) {
|
2017-12-21 20:10:55 +00:00
|
|
|
if ( $this->countries ) {
|
|
|
|
foreach ( $this->countries as $key => $value ) {
|
|
|
|
$states = $this->get_states( $key );
|
|
|
|
if ( $states ) {
|
2017-03-07 20:24:24 +00:00
|
|
|
echo '<optgroup label="' . esc_attr( $value ) . '">';
|
2017-12-21 20:10:55 +00:00
|
|
|
foreach ( $states as $state_key => $state_value ) {
|
|
|
|
echo '<option value="' . esc_attr( $key ) . ':' . esc_attr( $state_key ) . '"';
|
2017-03-07 20:24:24 +00:00
|
|
|
|
2017-08-08 16:32:21 +00:00
|
|
|
if ( $selected_country === $key && $selected_state === $state_key ) {
|
2017-03-07 20:24:24 +00:00
|
|
|
echo ' selected="selected"';
|
2017-08-08 16:32:21 +00:00
|
|
|
}
|
2017-03-07 20:24:24 +00:00
|
|
|
|
2020-06-16 15:15:12 +00:00
|
|
|
echo '>' . esc_html( $value ) . ' — ' . ( $escape ? esc_html( $state_value ) : $state_value ) . '</option>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
2020-01-27 16:17:36 +00:00
|
|
|
|
2017-12-21 20:10:55 +00:00
|
|
|
}
|
2017-03-07 20:24:24 +00:00
|
|
|
echo '</optgroup>';
|
2017-12-21 20:10:55 +00:00
|
|
|
} else {
|
2017-03-07 20:24:24 +00:00
|
|
|
echo '<option';
|
2017-08-08 16:32:21 +00:00
|
|
|
if ( $selected_country === $key && '*' === $selected_state ) {
|
2016-08-27 01:46:45 +00:00
|
|
|
echo ' selected="selected"';
|
2017-03-07 20:24:24 +00:00
|
|
|
}
|
2020-06-16 15:15:12 +00:00
|
|
|
echo ' value="' . esc_attr( $key ) . '">' . ( $escape ? esc_html( $value ) : $value ) . '</option>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
2017-12-21 20:10:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-09 15:16:18 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Get country address formats.
|
2016-12-12 15:23:28 +00:00
|
|
|
*
|
|
|
|
* These define how addresses are formatted for display in various countries.
|
|
|
|
*
|
2012-08-14 19:42:38 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function get_address_formats() {
|
2016-06-06 18:39:23 +00:00
|
|
|
if ( empty( $this->address_formats ) ) {
|
2017-12-21 20:18:04 +00:00
|
|
|
$this->address_formats = apply_filters(
|
2018-11-23 13:17:43 +00:00
|
|
|
'woocommerce_localisation_address_formats',
|
|
|
|
array(
|
2017-12-21 20:18:04 +00:00
|
|
|
'default' => "{name}\n{company}\n{address_1}\n{address_2}\n{city}\n{state}\n{postcode}\n{country}",
|
|
|
|
'AU' => "{name}\n{company}\n{address_1}\n{address_2}\n{city} {state} {postcode}\n{country}",
|
|
|
|
'AT' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
|
|
|
|
'BE' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
|
2019-11-30 16:55:35 +00:00
|
|
|
'CA' => "{company}\n{name}\n{address_1}\n{address_2}\n{city} {state_code} {postcode}\n{country}",
|
2017-12-21 20:18:04 +00:00
|
|
|
'CH' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
|
|
|
|
'CL' => "{company}\n{name}\n{address_1}\n{address_2}\n{state}\n{postcode} {city}\n{country}",
|
|
|
|
'CN' => "{country} {postcode}\n{state}, {city}, {address_2}, {address_1}\n{company}\n{name}",
|
|
|
|
'CZ' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
|
|
|
|
'DE' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
|
|
|
|
'EE' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
|
|
|
|
'FI' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
|
|
|
|
'DK' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
|
|
|
|
'FR' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city_upper}\n{country}",
|
|
|
|
'HK' => "{company}\n{first_name} {last_name_upper}\n{address_1}\n{address_2}\n{city_upper}\n{state_upper}\n{country}",
|
2020-06-04 17:21:41 +00:00
|
|
|
'HU' => "{last_name} {first_name}\n{company}\n{city}\n{address_1}\n{address_2}\n{postcode}\n{country}",
|
2018-10-24 13:02:59 +00:00
|
|
|
'IN' => "{company}\n{name}\n{address_1}\n{address_2}\n{city} {postcode}\n{state}, {country}",
|
2017-12-21 20:18:04 +00:00
|
|
|
'IS' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
|
|
|
|
'IT' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode}\n{city}\n{state_upper}\n{country}",
|
2020-09-20 19:10:27 +00:00
|
|
|
'JM' => "{name}\n{company}\n{address_1}\n{address_2}\n{city}\n{state}\n{postcode_upper}\n{country}",
|
2018-01-02 11:45:56 +00:00
|
|
|
'JP' => "{postcode}\n{state} {city} {address_1}\n{address_2}\n{company}\n{last_name} {first_name}\n{country}",
|
2017-12-21 20:18:04 +00:00
|
|
|
'TW' => "{company}\n{last_name} {first_name}\n{address_1}\n{address_2}\n{state}, {city} {postcode}\n{country}",
|
|
|
|
'LI' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
|
|
|
|
'NL' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
|
|
|
|
'NZ' => "{name}\n{company}\n{address_1}\n{address_2}\n{city} {postcode}\n{country}",
|
|
|
|
'NO' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
|
|
|
|
'PL' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
|
2020-12-02 00:24:58 +00:00
|
|
|
'PR' => "{company}\n{name}\n{address_1} {address_2}\n{city} \n{country} {postcode}",
|
2017-12-21 20:18:04 +00:00
|
|
|
'PT' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
|
|
|
|
'SK' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
|
2019-04-21 18:28:58 +00:00
|
|
|
'RS' => "{name}\n{company}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
|
2017-12-21 20:18:04 +00:00
|
|
|
'SI' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
|
|
|
|
'ES' => "{name}\n{company}\n{address_1}\n{address_2}\n{postcode} {city}\n{state}\n{country}",
|
|
|
|
'SE' => "{company}\n{name}\n{address_1}\n{address_2}\n{postcode} {city}\n{country}",
|
|
|
|
'TR' => "{name}\n{company}\n{address_1}\n{address_2}\n{postcode} {city} {state}\n{country}",
|
2019-04-09 10:59:49 +00:00
|
|
|
'UG' => "{name}\n{company}\n{address_1}\n{address_2}\n{city}\n{state}, {country}",
|
2017-12-21 20:18:04 +00:00
|
|
|
'US' => "{name}\n{company}\n{address_1}\n{address_2}\n{city}, {state_code} {postcode}\n{country}",
|
|
|
|
'VN' => "{name}\n{company}\n{address_1}\n{city}\n{country}",
|
|
|
|
)
|
|
|
|
);
|
2016-06-06 18:39:23 +00:00
|
|
|
}
|
2011-12-18 01:29:10 +00:00
|
|
|
return $this->address_formats;
|
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
/**
|
2015-01-18 18:59:17 +00:00
|
|
|
* Get country address format.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
2018-06-01 20:29:07 +00:00
|
|
|
* @param array $args Arguments.
|
|
|
|
* @param string $separator How to separate address lines. @since 3.5.0.
|
2017-12-21 20:10:55 +00:00
|
|
|
* @return string
|
2012-08-14 19:42:38 +00:00
|
|
|
*/
|
2018-06-01 20:29:07 +00:00
|
|
|
public function get_formatted_address( $args = array(), $separator = '<br/>' ) {
|
2015-03-06 03:05:40 +00:00
|
|
|
$default_args = array(
|
2015-03-04 14:02:35 +00:00
|
|
|
'first_name' => '',
|
2015-03-05 09:20:24 +00:00
|
|
|
'last_name' => '',
|
|
|
|
'company' => '',
|
|
|
|
'address_1' => '',
|
|
|
|
'address_2' => '',
|
|
|
|
'city' => '',
|
|
|
|
'state' => '',
|
|
|
|
'postcode' => '',
|
2016-08-27 01:46:45 +00:00
|
|
|
'country' => '',
|
2015-03-04 14:02:35 +00:00
|
|
|
);
|
2015-03-05 09:20:24 +00:00
|
|
|
|
2017-12-21 20:10:55 +00:00
|
|
|
$args = array_map( 'trim', wp_parse_args( $args, $default_args ) );
|
|
|
|
$state = $args['state'];
|
|
|
|
$country = $args['country'];
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2017-12-21 20:10:55 +00:00
|
|
|
// Get all formats.
|
2015-03-06 03:05:40 +00:00
|
|
|
$formats = $this->get_address_formats();
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2017-12-21 20:10:55 +00:00
|
|
|
// Get format for the address' country.
|
2015-03-06 03:05:40 +00:00
|
|
|
$format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2017-12-21 20:10:55 +00:00
|
|
|
// Handle full country name.
|
2015-03-06 03:05:40 +00:00
|
|
|
$full_country = ( isset( $this->countries[ $country ] ) ) ? $this->countries[ $country ] : $country;
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2017-12-21 20:10:55 +00:00
|
|
|
// Country is not needed if the same as base.
|
2018-11-08 20:35:57 +00:00
|
|
|
if ( $country === $this->get_base_country() && ! apply_filters( 'woocommerce_formatted_address_force_country_display', false ) ) {
|
2012-10-16 15:22:07 +00:00
|
|
|
$format = str_replace( '{country}', '', $format );
|
2015-03-05 09:20:24 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2017-12-21 20:10:55 +00:00
|
|
|
// Handle full state name.
|
2015-03-05 09:20:24 +00:00
|
|
|
$full_state = ( $country && $state && isset( $this->states[ $country ][ $state ] ) ) ? $this->states[ $country ][ $state ] : $state;
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2017-12-21 20:10:55 +00:00
|
|
|
// Substitute address parts into the string.
|
2017-12-21 20:18:04 +00:00
|
|
|
$replace = array_map(
|
2018-11-23 13:17:43 +00:00
|
|
|
'esc_html',
|
|
|
|
apply_filters(
|
|
|
|
'woocommerce_formatted_address_replacements',
|
|
|
|
array(
|
2017-12-21 20:18:04 +00:00
|
|
|
'{first_name}' => $args['first_name'],
|
|
|
|
'{last_name}' => $args['last_name'],
|
|
|
|
'{name}' => $args['first_name'] . ' ' . $args['last_name'],
|
|
|
|
'{company}' => $args['company'],
|
|
|
|
'{address_1}' => $args['address_1'],
|
|
|
|
'{address_2}' => $args['address_2'],
|
|
|
|
'{city}' => $args['city'],
|
|
|
|
'{state}' => $full_state,
|
|
|
|
'{postcode}' => $args['postcode'],
|
|
|
|
'{country}' => $full_country,
|
2018-11-30 17:59:28 +00:00
|
|
|
'{first_name_upper}' => wc_strtoupper( $args['first_name'] ),
|
|
|
|
'{last_name_upper}' => wc_strtoupper( $args['last_name'] ),
|
|
|
|
'{name_upper}' => wc_strtoupper( $args['first_name'] . ' ' . $args['last_name'] ),
|
|
|
|
'{company_upper}' => wc_strtoupper( $args['company'] ),
|
|
|
|
'{address_1_upper}' => wc_strtoupper( $args['address_1'] ),
|
|
|
|
'{address_2_upper}' => wc_strtoupper( $args['address_2'] ),
|
|
|
|
'{city_upper}' => wc_strtoupper( $args['city'] ),
|
|
|
|
'{state_upper}' => wc_strtoupper( $full_state ),
|
|
|
|
'{state_code}' => wc_strtoupper( $state ),
|
|
|
|
'{postcode_upper}' => wc_strtoupper( $args['postcode'] ),
|
|
|
|
'{country_upper}' => wc_strtoupper( $full_country ),
|
2018-11-23 13:17:43 +00:00
|
|
|
),
|
|
|
|
$args
|
2017-12-21 20:18:04 +00:00
|
|
|
)
|
|
|
|
);
|
2012-10-16 15:22:07 +00:00
|
|
|
|
|
|
|
$formatted_address = str_replace( array_keys( $replace ), $replace, $format );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2017-12-21 20:10:55 +00:00
|
|
|
// Clean up white space.
|
2012-10-16 15:22:07 +00:00
|
|
|
$formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) );
|
|
|
|
$formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2017-12-21 20:10:55 +00:00
|
|
|
// Break newlines apart and remove empty lines/trim commas and white space.
|
2014-05-06 15:04:07 +00:00
|
|
|
$formatted_address = array_filter( array_map( array( $this, 'trim_formatted_address_line' ), explode( "\n", $formatted_address ) ) );
|
|
|
|
|
2017-12-21 20:10:55 +00:00
|
|
|
// Add html breaks.
|
2018-06-01 20:29:07 +00:00
|
|
|
$formatted_address = implode( $separator, $formatted_address );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2011-12-18 01:29:10 +00:00
|
|
|
// We're done!
|
|
|
|
return $formatted_address;
|
2011-12-15 23:24:02 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2014-05-06 15:04:07 +00:00
|
|
|
/**
|
2015-01-18 18:59:17 +00:00
|
|
|
* Trim white space and commas off a line.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
|
|
|
* @param string $line Line.
|
2014-05-06 15:04:07 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function trim_formatted_address_line( $line ) {
|
2017-12-21 20:10:55 +00:00
|
|
|
return trim( $line, ', ' );
|
2014-05-06 15:04:07 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 12:02:36 +00:00
|
|
|
/**
|
|
|
|
* Returns the fields we show by default. This can be filtered later on.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
2013-11-27 09:03:47 +00:00
|
|
|
* @return array
|
2013-03-18 12:02:36 +00:00
|
|
|
*/
|
|
|
|
public function get_default_address_fields() {
|
2018-06-26 13:13:53 +00:00
|
|
|
if ( 'optional' === get_option( 'woocommerce_checkout_address_2_field', 'optional' ) ) {
|
2020-03-05 09:31:19 +00:00
|
|
|
$address_2_placeholder = __( 'Apartment, suite, unit, etc. (optional)', 'woocommerce' );
|
2018-08-24 12:36:40 +00:00
|
|
|
} else {
|
2020-03-05 09:31:19 +00:00
|
|
|
$address_2_placeholder = __( 'Apartment, suite, unit, etc.', 'woocommerce' );
|
2018-06-26 13:13:53 +00:00
|
|
|
}
|
|
|
|
|
2013-03-18 12:02:36 +00:00
|
|
|
$fields = array(
|
2015-01-18 18:59:17 +00:00
|
|
|
'first_name' => array(
|
2016-10-12 10:16:30 +00:00
|
|
|
'label' => __( 'First name', 'woocommerce' ),
|
2015-12-24 20:06:41 +00:00
|
|
|
'required' => true,
|
|
|
|
'class' => array( 'form-row-first' ),
|
|
|
|
'autocomplete' => 'given-name',
|
2016-12-13 18:48:39 +00:00
|
|
|
'priority' => 10,
|
2013-04-24 12:20:23 +00:00
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'last_name' => array(
|
2016-10-12 10:16:30 +00:00
|
|
|
'label' => __( 'Last name', 'woocommerce' ),
|
2015-12-24 20:06:41 +00:00
|
|
|
'required' => true,
|
|
|
|
'class' => array( 'form-row-last' ),
|
|
|
|
'autocomplete' => 'family-name',
|
2016-12-13 18:48:39 +00:00
|
|
|
'priority' => 20,
|
2013-04-24 12:20:23 +00:00
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'company' => array(
|
2016-10-12 10:16:30 +00:00
|
|
|
'label' => __( 'Company name', 'woocommerce' ),
|
2015-12-24 20:06:41 +00:00
|
|
|
'class' => array( 'form-row-wide' ),
|
|
|
|
'autocomplete' => 'organization',
|
2016-12-13 18:48:39 +00:00
|
|
|
'priority' => 30,
|
2018-04-05 16:51:43 +00:00
|
|
|
'required' => 'required' === get_option( 'woocommerce_checkout_company_field', 'optional' ),
|
2013-04-24 12:20:23 +00:00
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'country' => array(
|
2015-12-24 20:06:41 +00:00
|
|
|
'type' => 'country',
|
2019-09-01 08:57:45 +00:00
|
|
|
'label' => __( 'Country / Region', 'woocommerce' ),
|
2015-12-24 20:06:41 +00:00
|
|
|
'required' => true,
|
|
|
|
'class' => array( 'form-row-wide', 'address-field', 'update_totals_on_change' ),
|
|
|
|
'autocomplete' => 'country',
|
2016-12-13 18:48:39 +00:00
|
|
|
'priority' => 40,
|
2015-06-17 09:17:39 +00:00
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'address_1' => array(
|
Change field label and placeholder to minimize user error, add translators notice
Status Quo:
Working with several high-volume WooCommerce shops (in the range of several thousand orders per day combined), we've seen that the current placeholder text (and its translations in particular) lead to quite a few users filling in their address data incorrectly. You'd be surprised by the number of people who fail to properly write down their own address (house number missing, house number in wrong place).
Problem:
This leads to incomplete shipping labels, unsuccessful deliveries, and costly returns (especially for international shipping: 10-40 Euros lost per parcel).
Solution:
While some of these may stem from misdirected or incomplete browser auto-fills, we've seen (by customizing the language files for German, French, Spanish and Italian) that a more descriptive placeholder text helps reduce user errors on address entry. The goal is basically to make this as fool-proof as possible.
Why this matters:
At 1000 orders shipped per day, getting the error rate from 5% down to 4% means 10 less parcels coming back every day, which can save hundreds of Euros per day.
Choice of wording:
- "Address" is not just one field, but rather the sum of all address fields that will end up on a shipping label.
- "Street Address" is what the user needs to input here, hence the new label for the two address fields
- "House number and street name" is the most descriptive placeholder text I can come up with for this field (assuming the U.S. as default), hence the new placeholder text.
- Translator notice added since many countries will have the house number after the street name.
References:
- https://en.wikipedia.org/wiki/Address_(geography)
2017-04-20 01:46:14 +00:00
|
|
|
'label' => __( 'Street address', 'woocommerce' ),
|
|
|
|
/* translators: use local order of street name and house number. */
|
|
|
|
'placeholder' => esc_attr__( 'House number and street name', 'woocommerce' ),
|
2015-12-24 20:06:41 +00:00
|
|
|
'required' => true,
|
|
|
|
'class' => array( 'form-row-wide', 'address-field' ),
|
|
|
|
'autocomplete' => 'address-line1',
|
2016-12-13 18:48:39 +00:00
|
|
|
'priority' => 50,
|
2013-04-24 12:20:23 +00:00
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'address_2' => array(
|
2018-06-26 13:48:29 +00:00
|
|
|
'placeholder' => esc_attr( $address_2_placeholder ),
|
2015-12-24 20:06:41 +00:00
|
|
|
'class' => array( 'form-row-wide', 'address-field' ),
|
|
|
|
'autocomplete' => 'address-line2',
|
2016-12-13 18:48:39 +00:00
|
|
|
'priority' => 60,
|
2018-04-05 16:51:43 +00:00
|
|
|
'required' => 'required' === get_option( 'woocommerce_checkout_address_2_field', 'optional' ),
|
2013-04-24 12:20:23 +00:00
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'city' => array(
|
2015-12-24 20:06:41 +00:00
|
|
|
'label' => __( 'Town / City', 'woocommerce' ),
|
|
|
|
'required' => true,
|
|
|
|
'class' => array( 'form-row-wide', 'address-field' ),
|
|
|
|
'autocomplete' => 'address-level2',
|
2016-12-13 18:48:39 +00:00
|
|
|
'priority' => 70,
|
2013-04-24 12:20:23 +00:00
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'state' => array(
|
2015-12-24 20:06:41 +00:00
|
|
|
'type' => 'state',
|
|
|
|
'label' => __( 'State / County', 'woocommerce' ),
|
|
|
|
'required' => true,
|
2016-12-12 15:23:28 +00:00
|
|
|
'class' => array( 'form-row-wide', 'address-field' ),
|
2015-12-24 20:06:41 +00:00
|
|
|
'validate' => array( 'state' ),
|
|
|
|
'autocomplete' => 'address-level1',
|
2016-12-13 18:48:39 +00:00
|
|
|
'priority' => 80,
|
2013-04-24 12:20:23 +00:00
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'postcode' => array(
|
2015-12-24 20:06:41 +00:00
|
|
|
'label' => __( 'Postcode / ZIP', 'woocommerce' ),
|
|
|
|
'required' => true,
|
2016-12-12 15:23:28 +00:00
|
|
|
'class' => array( 'form-row-wide', 'address-field' ),
|
2015-12-24 20:06:41 +00:00
|
|
|
'validate' => array( 'postcode' ),
|
|
|
|
'autocomplete' => 'postal-code',
|
2016-12-13 18:48:39 +00:00
|
|
|
'priority' => 90,
|
2013-04-24 12:20:23 +00:00
|
|
|
),
|
2013-03-18 12:02:36 +00:00
|
|
|
);
|
|
|
|
|
2018-04-05 16:51:43 +00:00
|
|
|
if ( 'hidden' === get_option( 'woocommerce_checkout_company_field', 'optional' ) ) {
|
|
|
|
unset( $fields['company'] );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( 'hidden' === get_option( 'woocommerce_checkout_address_2_field', 'optional' ) ) {
|
|
|
|
unset( $fields['address_2'] );
|
|
|
|
}
|
|
|
|
|
2018-11-07 19:16:05 +00:00
|
|
|
$default_address_fields = apply_filters( 'woocommerce_default_address_fields', $fields );
|
|
|
|
// Sort each of the fields based on priority.
|
|
|
|
uasort( $default_address_fields, 'wc_checkout_fields_uasort_comparison' );
|
|
|
|
|
|
|
|
return $default_address_fields;
|
2013-03-18 12:02:36 +00:00
|
|
|
}
|
|
|
|
|
2013-11-28 14:46:08 +00:00
|
|
|
/**
|
2013-12-03 12:14:12 +00:00
|
|
|
* Get JS selectors for fields which are shown/hidden depending on the locale.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
2013-11-28 14:46:08 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2013-12-03 12:14:12 +00:00
|
|
|
public function get_country_locale_field_selectors() {
|
2016-08-27 02:39:16 +00:00
|
|
|
$locale_fields = array(
|
2015-01-18 18:59:17 +00:00
|
|
|
'address_1' => '#billing_address_1_field, #shipping_address_1_field',
|
|
|
|
'address_2' => '#billing_address_2_field, #shipping_address_2_field',
|
2015-03-06 12:37:21 +00:00
|
|
|
'state' => '#billing_state_field, #shipping_state_field, #calc_shipping_state_field',
|
|
|
|
'postcode' => '#billing_postcode_field, #shipping_postcode_field, #calc_shipping_postcode_field',
|
|
|
|
'city' => '#billing_city_field, #shipping_city_field, #calc_shipping_city_field',
|
2013-11-28 14:46:08 +00:00
|
|
|
);
|
2013-12-03 12:14:12 +00:00
|
|
|
return apply_filters( 'woocommerce_country_locale_field_selectors', $locale_fields );
|
2013-11-28 14:46:08 +00:00
|
|
|
}
|
|
|
|
|
2012-08-14 19:42:38 +00:00
|
|
|
/**
|
2015-01-18 18:59:17 +00:00
|
|
|
* Get country locale settings.
|
2016-12-12 15:23:28 +00:00
|
|
|
*
|
|
|
|
* These locales override the default country selections after a country is chosen.
|
|
|
|
*
|
2012-08-14 19:42:38 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2012-12-14 21:37:41 +00:00
|
|
|
public function get_country_locale() {
|
2016-06-06 18:39:23 +00:00
|
|
|
if ( empty( $this->locale ) ) {
|
2017-12-21 20:18:04 +00:00
|
|
|
$this->locale = apply_filters(
|
2018-11-23 13:17:43 +00:00
|
|
|
'woocommerce_get_country_locale',
|
|
|
|
array(
|
2017-12-21 20:18:04 +00:00
|
|
|
'AE' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
|
|
|
'hidden' => true,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'AF' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
2018-11-20 12:36:45 +00:00
|
|
|
'AO' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
|
|
|
'hidden' => true,
|
|
|
|
),
|
2019-01-04 11:08:01 +00:00
|
|
|
'state' => array(
|
2018-11-20 14:17:11 +00:00
|
|
|
'label' => __( 'Province', 'woocommerce' ),
|
|
|
|
),
|
2018-11-20 12:36:45 +00:00
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'AT' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'priority' => 65,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'AU' => array(
|
|
|
|
'city' => array(
|
|
|
|
'label' => __( 'Suburb', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
'postcode' => array(
|
|
|
|
'label' => __( 'Postcode', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'State', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'AX' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'priority' => 65,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
2020-07-17 11:04:20 +00:00
|
|
|
'BA' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'priority' => 65,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'Canton', 'woocommerce' ),
|
|
|
|
'required' => false,
|
2020-07-20 21:08:02 +00:00
|
|
|
'hidden' => true,
|
2020-07-17 11:04:20 +00:00
|
|
|
),
|
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'BD' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'District', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'BE' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'priority' => 65,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
'label' => __( 'Province', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
),
|
2018-06-04 09:47:41 +00:00
|
|
|
'BH' => array(
|
2018-08-20 10:40:53 +00:00
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
'state' => array(
|
2018-06-04 09:47:41 +00:00
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'BI' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'BO' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
|
|
|
'hidden' => true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'BS' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
|
|
|
'hidden' => true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'CA' => array(
|
2019-05-16 21:27:08 +00:00
|
|
|
'postcode' => array(
|
|
|
|
'label' => __( 'Postal code', 'woocommerce' ),
|
|
|
|
),
|
2020-01-27 16:17:36 +00:00
|
|
|
'state' => array(
|
2017-12-21 20:18:04 +00:00
|
|
|
'label' => __( 'Province', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'CH' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'priority' => 65,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'Canton', 'woocommerce' ),
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'CL' => array(
|
|
|
|
'city' => array(
|
|
|
|
'required' => true,
|
|
|
|
),
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'Region', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'CN' => array(
|
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'Province', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'CO' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'CZ' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'DE' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'priority' => 65,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
2020-02-07 00:10:38 +00:00
|
|
|
'hidden' => true,
|
2017-12-21 20:18:04 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
'DK' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'priority' => 65,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
2020-02-07 00:10:38 +00:00
|
|
|
'hidden' => true,
|
2017-12-21 20:18:04 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
'EE' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'priority' => 65,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'FI' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'priority' => 65,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'FR' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'priority' => 65,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
2020-04-23 23:23:30 +00:00
|
|
|
'GH' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
'state' => array(
|
2020-04-24 09:08:11 +00:00
|
|
|
'label' => __( 'Region', 'woocommerce' ),
|
2020-04-23 23:23:30 +00:00
|
|
|
),
|
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'GP' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'GF' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
2019-04-18 10:21:06 +00:00
|
|
|
'GR' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'HK' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
'city' => array(
|
|
|
|
'label' => __( 'Town / District', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'Region', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'HU' => array(
|
2020-06-04 17:21:41 +00:00
|
|
|
'last_name' => array(
|
2020-06-23 14:09:21 +00:00
|
|
|
'class' => array( 'form-row-first' ),
|
2020-06-04 17:21:41 +00:00
|
|
|
'priority' => 10,
|
|
|
|
),
|
|
|
|
'first_name' => array(
|
2020-06-23 14:09:21 +00:00
|
|
|
'class' => array( 'form-row-last' ),
|
2020-06-04 17:21:41 +00:00
|
|
|
'priority' => 20,
|
|
|
|
),
|
|
|
|
'postcode' => array(
|
2020-06-23 14:09:21 +00:00
|
|
|
'class' => array( 'form-row-first', 'address-field' ),
|
2020-06-04 17:21:41 +00:00
|
|
|
'priority' => 65,
|
|
|
|
),
|
|
|
|
'city' => array(
|
2020-06-10 15:54:12 +00:00
|
|
|
'class' => array( 'form-row-last', 'address-field' ),
|
2020-06-04 17:21:41 +00:00
|
|
|
),
|
|
|
|
'address_1' => array(
|
|
|
|
'priority' => 71,
|
|
|
|
),
|
|
|
|
'address_2' => array(
|
|
|
|
'priority' => 72,
|
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'County', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'ID' => array(
|
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'Province', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'IE' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
|
|
|
'label' => __( 'Eircode', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'County', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'IS' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'priority' => 65,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'IL' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'priority' => 65,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
2018-02-12 10:34:40 +00:00
|
|
|
'IM' => array(
|
2018-03-19 22:42:55 +00:00
|
|
|
'state' => array(
|
2018-02-12 10:34:40 +00:00
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
2020-08-29 08:49:33 +00:00
|
|
|
'IN' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'label' => __( 'Pin code', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'State', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'IT' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'priority' => 65,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'required' => true,
|
|
|
|
'label' => __( 'Province', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
),
|
2020-09-20 19:10:27 +00:00
|
|
|
'JM' => array(
|
|
|
|
'city' => array(
|
|
|
|
'label' => __( 'Town / City / Post Office', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
|
|
|
'label' => __( 'Postal Code', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'required' => true,
|
|
|
|
'label' => __( 'Parish', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'JP' => array(
|
2020-01-27 16:17:36 +00:00
|
|
|
'last_name' => array(
|
2019-08-06 11:10:15 +00:00
|
|
|
'class' => array( 'form-row-first' ),
|
|
|
|
'priority' => 10,
|
|
|
|
),
|
2019-08-06 12:41:16 +00:00
|
|
|
'first_name' => array(
|
2019-08-06 11:10:15 +00:00
|
|
|
'class' => array( 'form-row-last' ),
|
|
|
|
'priority' => 20,
|
|
|
|
),
|
2020-01-27 16:17:36 +00:00
|
|
|
'postcode' => array(
|
2020-06-04 17:21:41 +00:00
|
|
|
'class' => array( 'form-row-first', 'address-field' ),
|
2019-02-19 16:20:02 +00:00
|
|
|
'priority' => 65,
|
|
|
|
),
|
2020-01-27 16:17:36 +00:00
|
|
|
'state' => array(
|
2017-12-21 20:18:04 +00:00
|
|
|
'label' => __( 'Prefecture', 'woocommerce' ),
|
2020-06-04 17:21:41 +00:00
|
|
|
'class' => array( 'form-row-last', 'address-field' ),
|
2017-12-21 20:18:04 +00:00
|
|
|
'priority' => 66,
|
|
|
|
),
|
2020-01-27 16:17:36 +00:00
|
|
|
'city' => array(
|
2019-02-19 16:20:02 +00:00
|
|
|
'priority' => 67,
|
|
|
|
),
|
2020-01-27 16:17:36 +00:00
|
|
|
'address_1' => array(
|
2019-02-19 16:20:02 +00:00
|
|
|
'priority' => 68,
|
|
|
|
),
|
2020-01-27 16:17:36 +00:00
|
|
|
'address_2' => array(
|
2019-02-19 16:20:02 +00:00
|
|
|
'priority' => 69,
|
2017-12-21 20:18:04 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
'KR' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'KW' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
2019-01-17 12:18:31 +00:00
|
|
|
'LV' => array(
|
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'Municipality', 'woocommerce' ),
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'LB' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'MQ' => array(
|
|
|
|
'state' => array(
|
2018-06-11 15:23:27 +00:00
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'MT' => array(
|
|
|
|
'state' => array(
|
2017-12-21 20:18:04 +00:00
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
2019-05-19 21:23:36 +00:00
|
|
|
'MZ' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
|
|
|
'hidden' => true,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'Province', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'NL' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'priority' => 65,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
'label' => __( 'Province', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
),
|
2018-08-15 09:36:20 +00:00
|
|
|
'NG' => array(
|
|
|
|
'postcode' => array(
|
2018-10-26 21:16:14 +00:00
|
|
|
'label' => __( 'Postcode', 'woocommerce' ),
|
2018-08-15 09:36:20 +00:00
|
|
|
'required' => false,
|
|
|
|
'hidden' => true,
|
|
|
|
),
|
|
|
|
'state' => array(
|
2018-10-26 21:16:14 +00:00
|
|
|
'label' => __( 'State', 'woocommerce' ),
|
2018-08-15 09:36:20 +00:00
|
|
|
),
|
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'NZ' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'label' => __( 'Postcode', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
'label' => __( 'Region', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'NO' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'priority' => 65,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'NP' => array(
|
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'State / Zone', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'PL' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'priority' => 65,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
2020-06-04 20:18:17 +00:00
|
|
|
'PR' => array(
|
2020-06-05 13:14:52 +00:00
|
|
|
'city' => array(
|
2020-12-02 00:24:58 +00:00
|
|
|
'label' => __( 'Municipality', 'woocommerce' ),
|
2020-06-04 20:18:17 +00:00
|
|
|
),
|
2020-06-05 13:14:52 +00:00
|
|
|
'state' => array(
|
2020-12-02 00:24:58 +00:00
|
|
|
'required' => false,
|
|
|
|
'hidden' => true,
|
2020-06-05 13:14:52 +00:00
|
|
|
),
|
2020-06-04 20:18:17 +00:00
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'PT' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'RE' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'RO' => array(
|
|
|
|
'state' => array(
|
2017-12-30 12:34:12 +00:00
|
|
|
'label' => __( 'County', 'woocommerce' ),
|
2018-08-24 07:16:07 +00:00
|
|
|
'required' => true,
|
2017-12-21 20:18:04 +00:00
|
|
|
),
|
|
|
|
),
|
2019-04-21 20:43:47 +00:00
|
|
|
'RS' => array(
|
2020-09-24 20:41:33 +00:00
|
|
|
'city' => array(
|
2020-11-25 21:36:44 +00:00
|
|
|
'required' => true,
|
2020-09-24 20:41:33 +00:00
|
|
|
),
|
|
|
|
'postcode' => array(
|
2020-11-25 21:36:44 +00:00
|
|
|
'required' => true,
|
2020-09-24 20:41:33 +00:00
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'District', 'woocommerce' ),
|
2019-04-21 20:43:47 +00:00
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'SG' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
2018-08-09 09:02:09 +00:00
|
|
|
'city' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
),
|
|
|
|
'SK' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'priority' => 65,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'SI' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'priority' => 65,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'SR' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
|
|
|
'hidden' => true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'ES' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'priority' => 65,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'Province', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'LI' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'priority' => 65,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'Municipality', 'woocommerce' ),
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'LK' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
2018-06-05 10:09:08 +00:00
|
|
|
'LU' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'MD' => array(
|
|
|
|
'state' => array(
|
2017-12-30 12:34:12 +00:00
|
|
|
'label' => __( 'Municipality / District', 'woocommerce' ),
|
2017-12-21 20:18:04 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
'SE' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'priority' => 65,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
2020-02-07 00:10:38 +00:00
|
|
|
'hidden' => true,
|
2017-12-21 20:18:04 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
'TR' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'priority' => 65,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'Province', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
),
|
2019-04-09 10:59:49 +00:00
|
|
|
'UG' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
2019-04-10 10:03:30 +00:00
|
|
|
'hidden' => true,
|
2019-04-09 10:59:49 +00:00
|
|
|
),
|
2019-04-10 10:03:30 +00:00
|
|
|
'city' => array(
|
|
|
|
'label' => __( 'Town / Village', 'woocommerce' ),
|
|
|
|
'required' => true,
|
2019-04-09 10:59:49 +00:00
|
|
|
),
|
2019-04-10 10:03:30 +00:00
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'District', 'woocommerce' ),
|
|
|
|
'required' => true,
|
2019-04-09 10:59:49 +00:00
|
|
|
),
|
2019-04-10 10:03:30 +00:00
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'US' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'label' => __( 'ZIP', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'State', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'GB' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'label' => __( 'Postcode', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'County', 'woocommerce' ),
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
2018-11-20 13:29:45 +00:00
|
|
|
'ST' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
|
|
|
'hidden' => true,
|
|
|
|
),
|
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'District', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
),
|
2017-12-21 20:18:04 +00:00
|
|
|
'VN' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
2020-01-27 16:17:36 +00:00
|
|
|
'hidden' => true,
|
2017-12-21 20:18:04 +00:00
|
|
|
),
|
|
|
|
'postcode' => array(
|
|
|
|
'priority' => 65,
|
|
|
|
'required' => false,
|
|
|
|
'hidden' => false,
|
|
|
|
),
|
|
|
|
'address_2' => array(
|
|
|
|
'required' => false,
|
|
|
|
'hidden' => true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'WS' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
|
|
|
'hidden' => true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'YT' => array(
|
|
|
|
'state' => array(
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'ZA' => array(
|
|
|
|
'state' => array(
|
|
|
|
'label' => __( 'Province', 'woocommerce' ),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'ZW' => array(
|
|
|
|
'postcode' => array(
|
|
|
|
'required' => false,
|
|
|
|
'hidden' => true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2013-08-02 15:54:28 +00:00
|
|
|
$this->locale = array_intersect_key( $this->locale, array_merge( $this->get_allowed_countries(), $this->get_shipping_countries() ) );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2016-12-12 15:23:28 +00:00
|
|
|
// Default Locale Can be filtered to override fields in get_address_fields(). Countries with no specific locale will use default.
|
2016-09-02 01:51:31 +00:00
|
|
|
$this->locale['default'] = apply_filters( 'woocommerce_get_country_locale_default', $this->get_default_address_fields() );
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2017-12-21 20:10:55 +00:00
|
|
|
// Filter default AND shop base locales to allow overides via a single function. These will be used when changing countries on the checkout.
|
2015-01-18 18:59:17 +00:00
|
|
|
if ( ! isset( $this->locale[ $this->get_base_country() ] ) ) {
|
2013-03-18 12:02:36 +00:00
|
|
|
$this->locale[ $this->get_base_country() ] = $this->locale['default'];
|
2015-01-18 18:59:17 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2015-01-18 18:59:17 +00:00
|
|
|
$this->locale['default'] = apply_filters( 'woocommerce_get_country_locale_base', $this->locale['default'] );
|
|
|
|
$this->locale[ $this->get_base_country() ] = apply_filters( 'woocommerce_get_country_locale_base', $this->locale[ $this->get_base_country() ] );
|
2012-04-10 12:07:23 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2011-12-16 15:11:41 +00:00
|
|
|
return $this->locale;
|
2011-12-15 23:24:02 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2013-03-18 12:02:36 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Apply locale and get address fields.
|
2017-12-21 20:10:55 +00:00
|
|
|
*
|
|
|
|
* @param mixed $country Country.
|
|
|
|
* @param string $type Address type, defaults to 'billing_'.
|
2013-11-27 09:03:47 +00:00
|
|
|
* @return array
|
2013-03-18 12:02:36 +00:00
|
|
|
*/
|
2014-09-22 12:23:28 +00:00
|
|
|
public function get_address_fields( $country = '', $type = 'billing_' ) {
|
|
|
|
if ( ! $country ) {
|
2015-01-18 18:59:17 +00:00
|
|
|
$country = $this->get_base_country();
|
2014-09-22 12:23:28 +00:00
|
|
|
}
|
2013-07-19 14:08:40 +00:00
|
|
|
|
2015-01-18 18:59:17 +00:00
|
|
|
$fields = $this->get_default_address_fields();
|
|
|
|
$locale = $this->get_country_locale();
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2013-01-03 12:34:31 +00:00
|
|
|
if ( isset( $locale[ $country ] ) ) {
|
2013-11-25 13:34:21 +00:00
|
|
|
$fields = wc_array_overlay( $fields, $locale[ $country ] );
|
2012-07-10 12:36:13 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2017-12-21 20:10:55 +00:00
|
|
|
// Prepend field keys.
|
2011-12-16 15:11:41 +00:00
|
|
|
$address_fields = array();
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2012-07-10 12:36:13 +00:00
|
|
|
foreach ( $fields as $key => $value ) {
|
2017-06-16 10:45:53 +00:00
|
|
|
if ( 'state' === $key ) {
|
|
|
|
$value['country_field'] = $type . 'country';
|
2019-01-07 16:04:01 +00:00
|
|
|
$value['country'] = $country;
|
2017-06-16 10:45:53 +00:00
|
|
|
}
|
2015-01-18 18:59:17 +00:00
|
|
|
$address_fields[ $type . $key ] = $value;
|
2016-11-25 11:32:42 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2016-11-25 11:32:42 +00:00
|
|
|
// Add email and phone fields.
|
|
|
|
if ( 'billing_' === $type ) {
|
2018-04-26 10:52:36 +00:00
|
|
|
if ( 'hidden' !== get_option( 'woocommerce_checkout_phone_field', 'required' ) ) {
|
2018-04-05 16:51:43 +00:00
|
|
|
$address_fields['billing_phone'] = array(
|
|
|
|
'label' => __( 'Phone', 'woocommerce' ),
|
2018-04-26 10:52:36 +00:00
|
|
|
'required' => 'required' === get_option( 'woocommerce_checkout_phone_field', 'required' ),
|
2018-04-05 16:51:43 +00:00
|
|
|
'type' => 'tel',
|
|
|
|
'class' => array( 'form-row-wide' ),
|
|
|
|
'validate' => array( 'phone' ),
|
|
|
|
'autocomplete' => 'tel',
|
|
|
|
'priority' => 100,
|
|
|
|
);
|
|
|
|
}
|
2016-11-25 11:32:42 +00:00
|
|
|
$address_fields['billing_email'] = array(
|
2016-12-19 12:19:44 +00:00
|
|
|
'label' => __( 'Email address', 'woocommerce' ),
|
|
|
|
'required' => true,
|
|
|
|
'type' => 'email',
|
2017-10-20 23:15:48 +00:00
|
|
|
'class' => array( 'form-row-wide' ),
|
2016-12-19 12:19:44 +00:00
|
|
|
'validate' => array( 'email' ),
|
|
|
|
'autocomplete' => 'no' === get_option( 'woocommerce_registration_generate_username' ) ? 'email' : 'email username',
|
|
|
|
'priority' => 110,
|
2016-11-25 11:32:42 +00:00
|
|
|
);
|
2012-07-10 12:36:13 +00:00
|
|
|
}
|
2012-08-06 22:43:39 +00:00
|
|
|
|
2016-11-25 12:24:23 +00:00
|
|
|
/**
|
|
|
|
* Important note on this filter: Changes to address fields can and will be overridden by
|
|
|
|
* the woocommerce_default_address_fields. The locales/default locales apply on top based
|
|
|
|
* on country selection. If you want to change things like the required status of an
|
|
|
|
* address field, filter woocommerce_default_address_fields instead.
|
|
|
|
*/
|
2018-11-07 19:16:05 +00:00
|
|
|
$address_fields = apply_filters( 'woocommerce_' . $type . 'fields', $address_fields, $country );
|
|
|
|
// Sort each of the fields based on priority.
|
|
|
|
uasort( $address_fields, 'wc_checkout_fields_uasort_comparison' );
|
|
|
|
|
|
|
|
return $address_fields;
|
2011-12-16 15:11:41 +00:00
|
|
|
}
|
2015-01-07 01:24:23 +00:00
|
|
|
}
|