From d5e543f72f494418c138da44e6294610f9118eee Mon Sep 17 00:00:00 2001 From: Alex P Date: Tue, 25 Jan 2022 16:55:53 +0200 Subject: [PATCH] Omit shipping because of missing postal code only if country requires it --- .../src/Factory/PurchaseUnitFactory.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/modules/ppcp-api-client/src/Factory/PurchaseUnitFactory.php b/modules/ppcp-api-client/src/Factory/PurchaseUnitFactory.php index b73fae6ad..c018d9917 100644 --- a/modules/ppcp-api-client/src/Factory/PurchaseUnitFactory.php +++ b/modules/ppcp-api-client/src/Factory/PurchaseUnitFactory.php @@ -112,7 +112,7 @@ class PurchaseUnitFactory { if ( ! $this->shipping_needed( ... array_values( $items ) ) || empty( $shipping->address()->country_code() ) || - ( $shipping->address()->country_code() && ! $shipping->address()->postal_code() ) + ( ! $shipping->address()->postal_code() && ! $this->country_without_postal_code( $shipping->address()->country_code() ) ) ) { $shipping = null; } @@ -157,9 +157,8 @@ class PurchaseUnitFactory { if ( $this->shipping_needed( ... array_values( $items ) ) && is_a( $customer, \WC_Customer::class ) ) { $shipping = $this->shipping_factory->from_wc_customer( \WC()->customer ); if ( - 2 !== strlen( $shipping->address()->country_code() ) - || ( ! $shipping->address()->postal_code() ) - || $this->country_without_postal_code( $shipping->address()->country_code() ) + 2 !== strlen( $shipping->address()->country_code() ) || + ( ! $shipping->address()->postal_code() && ! $this->country_without_postal_code( $shipping->address()->country_code() ) ) ) { $shipping = null; } @@ -275,9 +274,6 @@ class PurchaseUnitFactory { */ private function country_without_postal_code( string $country_code ): bool { $countries = array( 'AE', 'AF', 'AG', 'AI', 'AL', 'AN', 'AO', 'AW', 'BB', 'BF', 'BH', 'BI', 'BJ', 'BM', 'BO', 'BS', 'BT', 'BW', 'BZ', 'CD', 'CF', 'CG', 'CI', 'CK', 'CL', 'CM', 'CO', 'CR', 'CV', 'DJ', 'DM', 'DO', 'EC', 'EG', 'ER', 'ET', 'FJ', 'FK', 'GA', 'GD', 'GH', 'GI', 'GM', 'GN', 'GQ', 'GT', 'GW', 'GY', 'HK', 'HN', 'HT', 'IE', 'IQ', 'IR', 'JM', 'JO', 'KE', 'KH', 'KI', 'KM', 'KN', 'KP', 'KW', 'KY', 'LA', 'LB', 'LC', 'LK', 'LR', 'LS', 'LY', 'ML', 'MM', 'MO', 'MR', 'MS', 'MT', 'MU', 'MW', 'MZ', 'NA', 'NE', 'NG', 'NI', 'NP', 'NR', 'NU', 'OM', 'PA', 'PE', 'PF', 'PY', 'QA', 'RW', 'SA', 'SB', 'SC', 'SD', 'SL', 'SN', 'SO', 'SR', 'SS', 'ST', 'SV', 'SY', 'TC', 'TD', 'TG', 'TL', 'TO', 'TT', 'TV', 'TZ', 'UG', 'UY', 'VC', 'VE', 'VG', 'VN', 'VU', 'WS', 'XA', 'XB', 'XC', 'XE', 'XL', 'XM', 'XN', 'XS', 'YE', 'ZM', 'ZW' ); - if ( in_array( $country_code, $countries, true ) ) { - return true; - } - return false; + return in_array( $country_code, $countries, true ); } }