Merge pull request #29654 from woocommerce/fix/29499

Set US:CA as the default store location
This commit is contained in:
Vedanshu Jain 2021-04-16 16:54:50 +05:30 committed by GitHub
commit d79e86932b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 91 additions and 89 deletions

View File

@ -172,7 +172,7 @@ if ( ! class_exists( 'WC_Admin_Dashboard_Setup', false ) ) :
*/
private function populate_payment_tasks() {
$is_woo_payment_installed = is_plugin_active( 'woocommerce-payments/woocommerce-payments.php' );
$country = explode( ':', get_option( 'woocommerce_default_country', '' ) )[0];
$country = explode( ':', get_option( 'woocommerce_default_country', 'US:CA' ) )[0];
// woocommerce-payments requires its plugin activated and country must be US.
if ( ! $is_woo_payment_installed || 'US' !== $country ) {

View File

@ -81,7 +81,7 @@ class WC_Settings_General extends WC_Settings_Page {
'title' => __( 'Country / State', 'woocommerce' ),
'desc' => __( 'The country and state or province, if any, in which your business is located.', 'woocommerce' ),
'id' => 'woocommerce_default_country',
'default' => 'GB',
'default' => 'US:CA',
'type' => 'single_select_country',
'desc_tip' => true,
),

View File

@ -390,7 +390,7 @@ function wc_locate_template( $template_name, $template_path = '', $default_path
// Look within passed path within the theme - this is priority.
if ( false !== strpos( $template_name, 'product_cat' ) || false !== strpos( $template_name, 'product_tag' ) ) {
$cs_template = str_replace( '_', '-', $template_name );
$template = locate_template(
$template = locate_template(
array(
trailingslashit( $template_path ) . $cs_template,
$cs_template,
@ -1270,7 +1270,7 @@ function wc_format_country_state_string( $country_string ) {
* @return array
*/
function wc_get_base_location() {
$default = apply_filters( 'woocommerce_get_base_location', get_option( 'woocommerce_default_country' ) );
$default = apply_filters( 'woocommerce_get_base_location', get_option( 'woocommerce_default_country', 'US:CA' ) );
return wc_format_country_state_string( $default );
}
@ -1286,7 +1286,7 @@ function wc_get_base_location() {
*/
function wc_get_customer_default_location() {
$set_default_location_to = get_option( 'woocommerce_default_customer_address', 'base' );
$default_location = '' === $set_default_location_to ? '' : get_option( 'woocommerce_default_country', '' );
$default_location = '' === $set_default_location_to ? '' : get_option( 'woocommerce_default_country', 'US:CA' );
$location = wc_format_country_state_string( apply_filters( 'woocommerce_customer_default_location', $default_location ) );
// Geolocation takes priority if used and if geolocation is possible.
@ -2269,9 +2269,9 @@ function wc_prevent_dangerous_auto_updates( $should_update, $plugin ) {
include_once dirname( __FILE__ ) . '/admin/plugin-updates/class-wc-plugin-updates.php';
}
$new_version = wc_clean( $plugin->new_version );
$plugin_updates = new WC_Plugin_Updates();
$version_type = Constants::get_constant( 'WC_SSR_PLUGIN_UPDATE_RELEASE_VERSION_TYPE' );
$new_version = wc_clean( $plugin->new_version );
$plugin_updates = new WC_Plugin_Updates();
$version_type = Constants::get_constant( 'WC_SSR_PLUGIN_UPDATE_RELEASE_VERSION_TYPE' );
if ( ! is_string( $version_type ) ) {
$version_type = 'none';
}

View File

@ -17,15 +17,15 @@ class WC_Helper_Customer {
'id' => 0,
'date_modified' => null,
'country' => 'US',
'state' => 'PA',
'postcode' => '19123',
'city' => 'Philadelphia',
'state' => 'CA',
'postcode' => '94110',
'city' => 'San Francisco',
'address' => '123 South Street',
'address_2' => 'Apt 1',
'shipping_country' => 'US',
'shipping_state' => 'PA',
'shipping_postcode' => '19123',
'shipping_city' => 'Philadelphia',
'shipping_state' => 'CA',
'shipping_postcode' => '94110',
'shipping_city' => 'San Francisco',
'shipping_address' => '123 South Street',
'shipping_address_2' => 'Apt 1',
'is_vat_exempt' => false,
@ -46,15 +46,15 @@ class WC_Helper_Customer {
$customer = new WC_Customer();
$customer->set_billing_country( 'US' );
$customer->set_first_name( 'Justin' );
$customer->set_billing_state( 'PA' );
$customer->set_billing_postcode( '19123' );
$customer->set_billing_city( 'Philadelphia' );
$customer->set_billing_state( 'CA' );
$customer->set_billing_postcode( '94110' );
$customer->set_billing_city( 'San Francisco' );
$customer->set_billing_address( '123 South Street' );
$customer->set_billing_address_2( 'Apt 1' );
$customer->set_shipping_country( 'US' );
$customer->set_shipping_state( 'PA' );
$customer->set_shipping_postcode( '19123' );
$customer->set_shipping_city( 'Philadelphia' );
$customer->set_shipping_state( 'CA' );
$customer->set_shipping_postcode( '94110' );
$customer->set_shipping_city( 'San Francisco' );
$customer->set_shipping_address( '123 South Street' );
$customer->set_shipping_address_2( 'Apt 1' );
$customer->set_username( $username );
@ -70,7 +70,7 @@ class WC_Helper_Customer {
* @return array
*/
public static function get_expected_store_location() {
return array( 'GB', '', '', '' );
return array( 'US', 'CA', '', '' );
}
/**

View File

@ -179,7 +179,7 @@ class WC_Tests_Account_Functions extends WC_Unit_Test_Case {
public function test_wc_get_account_formatted_address() {
$customer = WC_Helper_Customer::create_customer();
$this->assertEquals( '123 South Street<br/>Apt 1<br/>Philadelphia, PA 19123<br/>United States (US)', wc_get_account_formatted_address( 'billing', $customer->get_id() ) );
$this->assertEquals( '123 South Street<br/>Apt 1<br/>San Francisco, CA 94110', wc_get_account_formatted_address( 'billing', $customer->get_id() ) );
$customer->delete( true );
}

View File

@ -5,6 +5,8 @@
* @package WooCommerce\Tests\Countries
*/
// phpcs:disable WordPress.Files.FileName
/**
* WC_Countries tests.
*/
@ -178,7 +180,7 @@ class WC_Tests_Countries extends WC_Unit_Test_Case {
update_option( 'woocommerce_default_country', 'NO' );
$this->assertEquals( 'VAT', $countries->tax_or_vat() );
update_option( 'woocommerce_default_country', 'US' );
update_option( 'woocommerce_default_country', 'US:CA' );
$this->assertEquals( 'Tax', $countries->tax_or_vat() );
}

View File

@ -324,16 +324,16 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
update_option( 'woocommerce_tax_based_on', 'shipping' );
$taxable = $customer->get_taxable_address();
$this->assertEquals( 'US', $taxable[0] );
$this->assertEquals( 'PA', $taxable[1] );
$this->assertEquals( 'CA', $taxable[1] );
$this->assertEquals( '11111', $taxable[2] );
$this->assertEquals( 'Test', $taxable[3] );
update_option( 'woocommerce_tax_based_on', 'billing' );
$taxable = $customer->get_taxable_address();
$this->assertEquals( 'US', $taxable[0] );
$this->assertEquals( 'PA', $taxable[1] );
$this->assertEquals( '19123', $taxable[2] );
$this->assertEquals( 'Philadelphia', $taxable[3] );
$this->assertEquals( 'CA', $taxable[1] );
$this->assertEquals( '94110', $taxable[2] );
$this->assertEquals( 'San Francisco', $taxable[3] );
update_option( 'woocommerce_tax_based_on', 'base' );
$taxable = $customer->get_taxable_address();
@ -431,7 +431,7 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
*/
public function test_customer_is_customer_outside_base() {
$customer = WC_Helper_Customer::create_customer();
$this->assertTrue( $customer->is_customer_outside_base() );
$this->assertFalse( $customer->is_customer_outside_base() );
update_option( 'woocommerce_tax_based_on', 'base' );
$customer->set_billing_address_to_base();
$this->assertFalse( $customer->is_customer_outside_base() );
@ -444,9 +444,9 @@ class WC_Tests_CustomerCRUD extends WC_Unit_Test_Case {
public function test_customer_sessions() {
$session = WC_Helper_Customer::create_mock_customer(); // set into session....
$this->assertEquals( '19123', $session->get_billing_postcode() );
$this->assertEquals( '94110', $session->get_billing_postcode() );
$this->assertEquals( '123 South Street', $session->get_billing_address() );
$this->assertEquals( 'Philadelphia', $session->get_billing_city() );
$this->assertEquals( 'San Francisco', $session->get_billing_city() );
$session->set_billing_address( '124 South Street' );
$session->save();

View File

@ -83,7 +83,7 @@ class WC_Tests_Customer extends WC_Unit_Test_Case {
// Customer is going with the Free Shipping option, and the store calculates tax based on the customer's billing address.
WC_Helper_Customer::set_chosen_shipping_methods( array( 'free_shipping' ) );
WC_Helper_Customer::set_tax_based_on( 'billing' );
$this->assertEquals( $customer->is_customer_outside_base(), true );
$this->assertEquals( $customer->is_customer_outside_base(), false );
// Customer is going with the Free Shipping option, and the store calculates tax based on the store base location.
WC_Helper_Customer::set_chosen_shipping_methods( array( 'free_shipping' ) );

View File

@ -618,7 +618,7 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
// Ex tax label.
$calc_taxes = get_option( 'woocommerce_calc_taxes' );
update_option( 'woocommerce_calc_taxes', 'yes' );
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">&pound;</span>1,111.17</bdi></span> <small class="woocommerce-Price-taxLabel tax_label">(ex. VAT)</small>', wc_price( '1111.17', array( 'ex_tax_label' => true ) ) );
$this->assertEquals( '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">&pound;</span>1,111.17</bdi></span> <small class="woocommerce-Price-taxLabel tax_label">(ex. tax)</small>', wc_price( '1111.17', array( 'ex_tax_label' => true ) ) );
update_option( 'woocommerce_calc_taxes', $calc_taxes );
}

View File

@ -1245,7 +1245,7 @@ class WC_Tests_CRUD_Orders extends WC_Unit_Test_Case {
$order->set_billing_country( 'US' );
$order->set_billing_city( 'Portland' );
$order->set_billing_postcode( '97266' );
$this->assertEquals( '123 Test St.<br/>Portland, 97266<br/>United States (US)', $order->get_formatted_billing_address( 'none' ) );
$this->assertEquals( '123 Test St.<br/>Portland, 97266', $order->get_formatted_billing_address( 'none' ) );
$this->assertTrue( $order->has_billing_address() );
$this->assertFalse( $order->has_shipping_address() );
@ -1265,7 +1265,7 @@ class WC_Tests_CRUD_Orders extends WC_Unit_Test_Case {
$order->set_shipping_country( 'US' );
$order->set_shipping_city( 'Portland' );
$order->set_shipping_postcode( '97266' );
$this->assertEquals( '123 Test St.<br/>Portland, 97266<br/>United States (US)', $order->get_formatted_shipping_address( 'none' ) );
$this->assertEquals( '123 Test St.<br/>Portland, 97266', $order->get_formatted_shipping_address( 'none' ) );
$this->assertFalse( $order->has_billing_address() );
$this->assertTrue( $order->has_shipping_address() );
@ -1498,7 +1498,7 @@ class WC_Tests_CRUD_Orders extends WC_Unit_Test_Case {
$object->set_billing_state( 'Boulder' );
$object->set_billing_postcode( '00001' );
$object->set_billing_country( 'US' );
$this->assertEquals( 'Fred Flintstone<br/>Bedrock Ltd.<br/>34 Stonepants avenue<br/>Rockville<br/>Bedrock, BOULDER 00001<br/>United States (US)', $object->get_formatted_billing_address() );
$this->assertEquals( 'Fred Flintstone<br/>Bedrock Ltd.<br/>34 Stonepants avenue<br/>Rockville<br/>Bedrock, BOULDER 00001', $object->get_formatted_billing_address() );
}
/**
@ -1515,7 +1515,7 @@ class WC_Tests_CRUD_Orders extends WC_Unit_Test_Case {
$object->set_shipping_state( 'Boulder' );
$object->set_shipping_postcode( '00001' );
$object->set_shipping_country( 'US' );
$this->assertEquals( 'Barney Rubble<br/>Bedrock Ltd.<br/>34 Stonepants avenue<br/>Rockville<br/>Bedrock, BOULDER 00001<br/>United States (US)', $object->get_formatted_shipping_address() );
$this->assertEquals( 'Barney Rubble<br/>Bedrock Ltd.<br/>34 Stonepants avenue<br/>Rockville<br/>Bedrock, BOULDER 00001', $object->get_formatted_shipping_address() );
}
/**

View File

@ -86,15 +86,15 @@ class WC_Test_Privacy_Export extends WC_Unit_Test_Case {
),
array(
'name' => 'Billing City',
'value' => 'Philadelphia',
'value' => 'San Francisco',
),
array(
'name' => 'Billing Postal/Zip Code',
'value' => '19123',
'value' => '94110',
),
array(
'name' => 'Billing State',
'value' => 'PA',
'value' => 'CA',
),
array(
'name' => 'Billing Country / Region',
@ -114,15 +114,15 @@ class WC_Test_Privacy_Export extends WC_Unit_Test_Case {
),
array(
'name' => 'Shipping City',
'value' => 'Philadelphia',
'value' => 'San Francisco',
),
array(
'name' => 'Shipping Postal/Zip Code',
'value' => '19123',
'value' => '94110',
),
array(
'name' => 'Shipping State',
'value' => 'PA',
'value' => 'CA',
),
array(
'name' => 'Shipping Country / Region',

View File

@ -26,15 +26,15 @@ class CustomerHelper {
'id' => 0,
'date_modified' => null,
'country' => 'US',
'state' => 'PA',
'postcode' => '19123',
'city' => 'Philadelphia',
'state' => 'CA',
'postcode' => '94110',
'city' => 'San Francisco',
'address' => '123 South Street',
'address_2' => 'Apt 1',
'shipping_country' => 'US',
'shipping_state' => 'PA',
'shipping_postcode' => '19123',
'shipping_city' => 'Philadelphia',
'shipping_state' => 'CA',
'shipping_postcode' => '94110',
'shipping_city' => 'San Francisco',
'shipping_address' => '123 South Street',
'shipping_address_2' => 'Apt 1',
'is_vat_exempt' => false,
@ -55,15 +55,15 @@ class CustomerHelper {
$customer = new WC_Customer();
$customer->set_billing_country( 'US' );
$customer->set_first_name( 'Justin' );
$customer->set_billing_state( 'PA' );
$customer->set_billing_postcode( '19123' );
$customer->set_billing_city( 'Philadelphia' );
$customer->set_billing_state( 'CA' );
$customer->set_billing_postcode( '94110' );
$customer->set_billing_city( 'San Francisco' );
$customer->set_billing_address( '123 South Street' );
$customer->set_billing_address_2( 'Apt 1' );
$customer->set_shipping_country( 'US' );
$customer->set_shipping_state( 'PA' );
$customer->set_shipping_postcode( '19123' );
$customer->set_shipping_city( 'Philadelphia' );
$customer->set_shipping_state( 'CA' );
$customer->set_shipping_postcode( '94110' );
$customer->set_shipping_city( 'San Francisco' );
$customer->set_shipping_address( '123 South Street' );
$customer->set_shipping_address_2( 'Apt 1' );
$customer->set_username( $username );
@ -79,7 +79,7 @@ class CustomerHelper {
* @return array
*/
public static function get_expected_store_location() {
return array( 'GB', '', '', '' );
return array( 'US', 'CA', '', '' );
}
/**

View File

@ -70,9 +70,9 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
'company' => '',
'address_1' => '123 South Street',
'address_2' => 'Apt 1',
'city' => 'Philadelphia',
'state' => 'PA',
'postcode' => '19123',
'city' => 'San Francisco',
'state' => 'CA',
'postcode' => '94110',
'country' => 'US',
'email' => '',
'phone' => '',
@ -83,9 +83,9 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
'company' => '',
'address_1' => '123 South Street',
'address_2' => 'Apt 1',
'city' => 'Philadelphia',
'state' => 'PA',
'postcode' => '19123',
'city' => 'San Francisco',
'state' => 'CA',
'postcode' => '94110',
'country' => 'US',
),
'is_paying_customer' => false,
@ -315,9 +315,9 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
'company' => '',
'address_1' => '123 South Street',
'address_2' => 'Apt 1',
'city' => 'Philadelphia',
'state' => 'PA',
'postcode' => '19123',
'city' => 'San Francisco',
'state' => 'CA',
'postcode' => '94110',
'country' => 'US',
'email' => '',
'phone' => '',
@ -328,9 +328,9 @@ class Customers_V2 extends WC_REST_Unit_Test_Case {
'company' => '',
'address_1' => '123 South Street',
'address_2' => 'Apt 1',
'city' => 'Philadelphia',
'state' => 'PA',
'postcode' => '19123',
'city' => 'San Francisco',
'state' => 'CA',
'postcode' => '94110',
'country' => 'US',
),
'is_paying_customer' => false,

View File

@ -77,9 +77,9 @@ class Customers extends WC_REST_Unit_Test_Case {
'company' => '',
'address_1' => '123 South Street',
'address_2' => 'Apt 1',
'city' => 'Philadelphia',
'state' => 'PA',
'postcode' => '19123',
'city' => 'San Francisco',
'state' => 'CA',
'postcode' => '94110',
'country' => 'US',
'email' => '',
'phone' => '',
@ -90,9 +90,9 @@ class Customers extends WC_REST_Unit_Test_Case {
'company' => '',
'address_1' => '123 South Street',
'address_2' => 'Apt 1',
'city' => 'Philadelphia',
'state' => 'PA',
'postcode' => '19123',
'city' => 'San Francisco',
'state' => 'CA',
'postcode' => '94110',
'country' => 'US',
),
'is_paying_customer' => false,
@ -147,9 +147,9 @@ class Customers extends WC_REST_Unit_Test_Case {
'company' => '',
'address_1' => '123 South Street',
'address_2' => 'Apt 1',
'city' => 'Philadelphia',
'state' => 'PA',
'postcode' => '19123',
'city' => 'San Francisco',
'state' => 'CA',
'postcode' => '94110',
'country' => 'US',
'email' => '',
'phone' => '',
@ -160,9 +160,9 @@ class Customers extends WC_REST_Unit_Test_Case {
'company' => '',
'address_1' => '123 South Street',
'address_2' => 'Apt 1',
'city' => 'Philadelphia',
'state' => 'PA',
'postcode' => '19123',
'city' => 'San Francisco',
'state' => 'CA',
'postcode' => '94110',
'country' => 'US',
),
'is_paying_customer' => false,
@ -387,9 +387,9 @@ class Customers extends WC_REST_Unit_Test_Case {
'company' => '',
'address_1' => '123 South Street',
'address_2' => 'Apt 1',
'city' => 'Philadelphia',
'state' => 'PA',
'postcode' => '19123',
'city' => 'San Francisco',
'state' => 'CA',
'postcode' => '94110',
'country' => 'US',
'email' => '',
'phone' => '',
@ -400,9 +400,9 @@ class Customers extends WC_REST_Unit_Test_Case {
'company' => '',
'address_1' => '123 South Street',
'address_2' => 'Apt 1',
'city' => 'Philadelphia',
'state' => 'PA',
'postcode' => '19123',
'city' => 'San Francisco',
'state' => 'CA',
'postcode' => '94110',
'country' => 'US',
),
'is_paying_customer' => false,

View File

@ -117,8 +117,8 @@ class WC_Tests_Tax extends WC_Unit_Test_Case {
*/
public function test_get_base_tax_rates() {
$tax_rate = array(
'tax_rate_country' => 'GB',
'tax_rate_state' => '',
'tax_rate_country' => 'US',
'tax_rate_state' => 'CA',
'tax_rate' => '20.0000',
'tax_rate_name' => 'VAT',
'tax_rate_priority' => '1',

View File

@ -348,8 +348,8 @@ class WC_Tests_Core_Functions extends WC_Unit_Test_Case {
public function test_wc_get_base_location() {
$default = wc_get_base_location();
$this->assertEquals( 'GB', $default['country'] );
$this->assertEquals( '', $default['state'] );
$this->assertEquals( 'US', $default['country'] );
$this->assertEquals( 'CA', $default['state'] );
}
/**