Check for state and postcode fields only if required

We were doing state and postcode even for countries where its not required, but unfortunately as an unintended effect we were ending up not checking shipping requirements if this was not met.
This commit is contained in:
vedanshujain 2020-09-09 18:21:14 +05:30
parent 6eb65cb40c
commit 7f2b322085
1 changed files with 9 additions and 1 deletions

View File

@ -1528,7 +1528,15 @@ class WC_Cart extends WC_Legacy_Cart {
}
if ( 'yes' === get_option( 'woocommerce_shipping_cost_requires_address' ) ) {
if ( ! $this->get_customer()->get_shipping_country() || ! $this->get_customer()->get_shipping_state() || ! $this->get_customer()->get_shipping_postcode() ) {
$country = $this->get_customer()->get_shipping_country();
if ( ! $country ) {
return false;
}
$country_fields = WC()->countries->get_address_fields( $country, 'shipping_' );
if ( isset( $country_fields['shipping_state'] ) && $country_fields['shipping_state']['required'] && ! $this->get_customer()->get_shipping_state() ) {
return false;
}
if ( isset( $country_fields['shipping_postcode'] ) && $country_fields['shipping_postcode']['required'] && ! $this->get_customer()->get_shipping_postcode() ) {
return false;
}
}