Merge pull request #25916 from woocommerce/fix/revert-25128
Made the is_package_shippable check more permissive
This commit is contained in:
commit
2a05f7c000
|
@ -279,30 +279,21 @@ 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;
|
||||
}
|
||||
|
||||
$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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate shipping rates for a package,
|
||||
*
|
||||
|
|
|
@ -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' => '',
|
||||
),
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue