From 7f2b32208550a7b4f803cbe8748628c86dd126a3 Mon Sep 17 00:00:00 2001 From: vedanshujain Date: Wed, 9 Sep 2020 18:21:14 +0530 Subject: [PATCH] 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. --- includes/class-wc-cart.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/includes/class-wc-cart.php b/includes/class-wc-cart.php index 23bf0737653..159660a1c26 100644 --- a/includes/class-wc-cart.php +++ b/includes/class-wc-cart.php @@ -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; } }