From ab2163a45c3fd985ff25acc8b32e37a05aec43d8 Mon Sep 17 00:00:00 2001 From: Philipp Stracker Date: Thu, 20 Feb 2025 12:36:21 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Make=20condition=20easier=20to?= =?UTF-8?q?=20understand?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/LocalAlternativePaymentMethodsModule.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php b/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php index 2e8105ff4..1d24b80f5 100644 --- a/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php +++ b/modules/ppcp-local-alternative-payment-methods/src/LocalAlternativePaymentMethodsModule.php @@ -90,15 +90,16 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo return $methods; } + $payment_methods = $c->get( 'ppcp-local-apms.payment-methods' ); $customer_country = WC()->customer->get_billing_country() ?: WC()->customer->get_shipping_country(); $site_currency = get_woocommerce_currency(); - $payment_methods = $c->get( 'ppcp-local-apms.payment-methods' ); + // Remove unsupported gateways from the customer's payment options. foreach ( $payment_methods as $payment_method ) { - if ( - ! in_array( $customer_country, $payment_method['countries'], true ) - || ! in_array( $site_currency, $payment_method['currencies'], true ) - ) { + $is_currency_supported = in_array( $site_currency, $payment_method['currencies'], true ); + $is_country_supported = in_array( $customer_country, $payment_method['countries'], true ); + + if ( ! $is_currency_supported || ! $is_country_supported ) { unset( $methods[ $payment_method['id'] ] ); } }