Merge pull request #25916 from woocommerce/fix/revert-25128

Made the is_package_shippable check more permissive
This commit is contained in:
Peter Fabian 2020-03-17 14:14:23 +01:00 committed by GitHub
commit 2a05f7c000
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 31 deletions

View File

@ -279,28 +279,19 @@ class WC_Shipping {
/**
* See if package is shippable.
*
* Packages must have a valid destination to be shipped.
* Packages are shippable until proven otherwise e.g. after getting a shipping country.
*
* @param array $package Package of cart items.
* @return bool
*/
public function is_package_shippable( $package ) {
// Packages are shippable until proven otherwise.
if ( empty( $package['destination']['country'] ) ) {
return false;
}
$country = $package['destination']['country'];
$countries = array_keys( WC()->countries->get_shipping_countries() );
if ( ! in_array( $country, $countries, true ) ) {
return false;
return true;
}
$states = WC()->countries->get_states( $country );
if ( is_array( $states ) && ! empty( $states ) && ! isset( $states[ $package['destination']['state'] ] ) ) {
return false;
}
return true;
$allowed = array_keys( WC()->countries->get_shipping_countries() );
return in_array( $package['destination']['country'], $allowed, true );
}
/**

View File

@ -21,7 +21,7 @@ class WC_Tests_Shipping extends WC_Unit_Test_Case {
public function test_is_package_shippable() {
$shipping = new WC_Shipping();
// Failure for no country.
// Success for no country.
$result = $shipping->is_package_shippable(
array(
'destination' => array(
@ -32,7 +32,7 @@ class WC_Tests_Shipping extends WC_Unit_Test_Case {
),
)
);
$this->assertFalse( $result );
$this->assertTrue( $result );
// Failure for disallowed country.
$result = $shipping->is_package_shippable(
@ -47,26 +47,13 @@ class WC_Tests_Shipping extends WC_Unit_Test_Case {
);
$this->assertFalse( $result );
// Failure for no state when required.
// Success for correct country.
$result = $shipping->is_package_shippable(
array(
'destination' => array(
'country' => 'US',
'state' => '',
'postcode' => '99999',
'address' => '',
),
)
);
$this->assertFalse( $result );
// Success for correct address.
$result = $shipping->is_package_shippable(
array(
'destination' => array(
'country' => 'US',
'state' => 'CA',
'postcode' => '99999',
'postcode' => '',
'address' => '',
),
)