Merge pull request #24943 from woocommerce/refactor/eu-vat-brexit
Brexit and VAT refactor
This commit is contained in:
commit
d3a33f8d05
|
@ -350,33 +350,47 @@ class WC_Countries {
|
||||||
/**
|
/**
|
||||||
* Gets an array of countries in the EU.
|
* Gets an array of countries in the EU.
|
||||||
*
|
*
|
||||||
* MC (monaco) and IM (isle of man, part of UK) also use VAT.
|
* @param string $deprecated Function used to return VAT countries based on this.
|
||||||
*
|
|
||||||
* @param string $type Type of countries to retrieve. Blank for EU member countries. eu_vat for EU VAT countries.
|
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
public function get_european_union_countries( $type = '' ) {
|
public function get_european_union_countries( $deprecated = '' ) {
|
||||||
$countries = array( 'AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HU', 'HR', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK' );
|
$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' );
|
||||||
|
|
||||||
if ( 'eu_vat' === $type ) {
|
if ( ! empty( $deprecated ) ) {
|
||||||
$countries[] = 'MC';
|
wc_deprecated_argument( 'type', '4.0.0', 'Use the WC_Countries::get_vat_countries method instead.' );
|
||||||
$countries[] = 'IM';
|
$countries = $this->get_vat_countries();
|
||||||
}
|
}
|
||||||
|
|
||||||
return apply_filters( 'woocommerce_european_union_countries', $countries, $type );
|
return apply_filters( 'woocommerce_european_union_countries', $countries, $deprecated );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
* 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
|
||||||
*
|
*
|
||||||
|
* @deprecated 4.0.0
|
||||||
|
* @since 3.9.0
|
||||||
* @return string[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
public function countries_using_vat() {
|
public function countries_using_vat() {
|
||||||
|
wc_deprecated_function( 'countries_using_vat', '4.0', 'WC_Countries::get_vat_countries' );
|
||||||
$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' );
|
$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' );
|
||||||
|
|
||||||
return apply_filters( 'woocommerce_countries_using_vat', $countries );
|
return apply_filters( 'woocommerce_countries_using_vat', $countries );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an array of countries using VAT.
|
||||||
|
*
|
||||||
|
* @since 4.0.0
|
||||||
|
* @return string[] of country codes.
|
||||||
|
*/
|
||||||
|
public function get_vat_countries() {
|
||||||
|
$eu_countries = $this->get_european_union_countries();
|
||||||
|
$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' );
|
||||||
|
|
||||||
|
return apply_filters( 'woocommerce_vat_countries', array_merge( $eu_countries, $vat_countries ) );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the correct string for shipping - either 'to the' or 'to'.
|
* Gets the correct string for shipping - either 'to the' or 'to'.
|
||||||
*
|
*
|
||||||
|
@ -411,7 +425,7 @@ class WC_Countries {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function tax_or_vat() {
|
public function tax_or_vat() {
|
||||||
$return = in_array( $this->get_base_country(), array_merge( $this->get_european_union_countries( 'eu_vat' ), array( 'NO' ), $this->countries_using_vat() ), true ) ? __( 'VAT', 'woocommerce' ) : __( 'Tax', 'woocommerce' );
|
$return = in_array( $this->get_base_country(), $this->get_vat_countries(), true ) ? __( 'VAT', 'woocommerce' ) : __( 'Tax', 'woocommerce' );
|
||||||
|
|
||||||
return apply_filters( 'woocommerce_countries_tax_or_vat', $return );
|
return apply_filters( 'woocommerce_countries_tax_or_vat', $return );
|
||||||
}
|
}
|
||||||
|
@ -422,7 +436,7 @@ class WC_Countries {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function inc_tax_or_vat() {
|
public function inc_tax_or_vat() {
|
||||||
$return = in_array( $this->get_base_country(), array_merge( $this->get_european_union_countries( 'eu_vat' ), array( 'NO' ), $this->countries_using_vat() ), true ) ? __( '(incl. VAT)', 'woocommerce' ) : __( '(incl. tax)', 'woocommerce' );
|
$return = in_array( $this->get_base_country(), $this->get_vat_countries(), true ) ? __( '(incl. VAT)', 'woocommerce' ) : __( '(incl. tax)', 'woocommerce' );
|
||||||
|
|
||||||
return apply_filters( 'woocommerce_countries_inc_tax_or_vat', $return );
|
return apply_filters( 'woocommerce_countries_inc_tax_or_vat', $return );
|
||||||
}
|
}
|
||||||
|
@ -433,7 +447,7 @@ class WC_Countries {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function ex_tax_or_vat() {
|
public function ex_tax_or_vat() {
|
||||||
$return = in_array( $this->get_base_country(), array_merge( $this->get_european_union_countries( 'eu_vat' ), array( 'NO' ), $this->countries_using_vat() ), true ) ? __( '(ex. VAT)', 'woocommerce' ) : __( '(ex. tax)', 'woocommerce' );
|
$return = in_array( $this->get_base_country(), $this->get_vat_countries(), true ) ? __( '(ex. VAT)', 'woocommerce' ) : __( '(ex. tax)', 'woocommerce' );
|
||||||
|
|
||||||
return apply_filters( 'woocommerce_countries_ex_tax_or_vat', $return );
|
return apply_filters( 'woocommerce_countries_ex_tax_or_vat', $return );
|
||||||
}
|
}
|
||||||
|
@ -458,7 +472,8 @@ class WC_Countries {
|
||||||
echo ' selected="selected"';
|
echo ' selected="selected"';
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '>' . esc_html( $value ) . ' — ' . ( $escape ? esc_js( $state_value ) : $state_value ) . '</option>'; // WPCS: XSS ok.
|
echo '>' . esc_html( $value ) . ' — ' . ( $escape ? esc_js( $state_value ) : $state_value ) . '</option>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
|
|
||||||
}
|
}
|
||||||
echo '</optgroup>';
|
echo '</optgroup>';
|
||||||
} else {
|
} else {
|
||||||
|
@ -466,7 +481,7 @@ class WC_Countries {
|
||||||
if ( $selected_country === $key && '*' === $selected_state ) {
|
if ( $selected_country === $key && '*' === $selected_state ) {
|
||||||
echo ' selected="selected"';
|
echo ' selected="selected"';
|
||||||
}
|
}
|
||||||
echo ' value="' . esc_attr( $key ) . '">' . ( $escape ? esc_js( $value ) : $value ) . '</option>'; // WPCS: XSS ok.
|
echo ' value="' . esc_attr( $key ) . '">' . ( $escape ? esc_js( $value ) : $value ) . '</option>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -848,7 +863,7 @@ class WC_Countries {
|
||||||
'postcode' => array(
|
'postcode' => array(
|
||||||
'label' => __( 'Postal code', 'woocommerce' ),
|
'label' => __( 'Postal code', 'woocommerce' ),
|
||||||
),
|
),
|
||||||
'state' => array(
|
'state' => array(
|
||||||
'label' => __( 'Province', 'woocommerce' ),
|
'label' => __( 'Province', 'woocommerce' ),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -1003,7 +1018,7 @@ class WC_Countries {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
'JP' => array(
|
'JP' => array(
|
||||||
'last_name' => array(
|
'last_name' => array(
|
||||||
'class' => array( 'form-row-first' ),
|
'class' => array( 'form-row-first' ),
|
||||||
'priority' => 10,
|
'priority' => 10,
|
||||||
),
|
),
|
||||||
|
@ -1011,22 +1026,22 @@ class WC_Countries {
|
||||||
'class' => array( 'form-row-last' ),
|
'class' => array( 'form-row-last' ),
|
||||||
'priority' => 20,
|
'priority' => 20,
|
||||||
),
|
),
|
||||||
'postcode' => array(
|
'postcode' => array(
|
||||||
'class' => array( 'form-row-first' ),
|
'class' => array( 'form-row-first' ),
|
||||||
'priority' => 65,
|
'priority' => 65,
|
||||||
),
|
),
|
||||||
'state' => array(
|
'state' => array(
|
||||||
'label' => __( 'Prefecture', 'woocommerce' ),
|
'label' => __( 'Prefecture', 'woocommerce' ),
|
||||||
'class' => array( 'form-row-last' ),
|
'class' => array( 'form-row-last' ),
|
||||||
'priority' => 66,
|
'priority' => 66,
|
||||||
),
|
),
|
||||||
'city' => array(
|
'city' => array(
|
||||||
'priority' => 67,
|
'priority' => 67,
|
||||||
),
|
),
|
||||||
'address_1' => array(
|
'address_1' => array(
|
||||||
'priority' => 68,
|
'priority' => 68,
|
||||||
),
|
),
|
||||||
'address_2' => array(
|
'address_2' => array(
|
||||||
'priority' => 69,
|
'priority' => 69,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -1265,7 +1280,7 @@ class WC_Countries {
|
||||||
'VN' => array(
|
'VN' => array(
|
||||||
'state' => array(
|
'state' => array(
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'hidden' => true,
|
'hidden' => true,
|
||||||
),
|
),
|
||||||
'postcode' => array(
|
'postcode' => array(
|
||||||
'priority' => 65,
|
'priority' => 65,
|
||||||
|
|
|
@ -198,4 +198,25 @@ class WC_Tests_Countries extends WC_Unit_Test_Case {
|
||||||
$this->assertArrayNotHasKey( 'AU', $locales );
|
$this->assertArrayNotHasKey( 'AU', $locales );
|
||||||
$this->assertArrayHasKey( 'default', $locales );
|
$this->assertArrayHasKey( 'default', $locales );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test get_european_union_countries.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function test_get_european_union_countries() {
|
||||||
|
// After Brexit there should be 27 countries in the EU.
|
||||||
|
$countries = new WC_Countries();
|
||||||
|
$this->assertCount( 27, $countries->get_european_union_countries() );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test get_vat_countries.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function test_get_vat_countries() {
|
||||||
|
$countries = new WC_Countries();
|
||||||
|
$this->assertCount( 80, $countries->get_vat_countries() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue