♻️ Decrease nesting depth of callback code

This commit is contained in:
Philipp Stracker 2025-02-20 12:26:57 +01:00
parent 705ffbdf17
commit ff943b5041
No known key found for this signature in database

View file

@ -82,26 +82,24 @@ class LocalAlternativePaymentMethodsModule implements ServiceModule, ExtendingMo
* @psalm-suppress MissingClosureParamType * @psalm-suppress MissingClosureParamType
*/ */
function ( $methods ) use ( $c ) { function ( $methods ) use ( $c ) {
if ( ! is_array( $methods ) ) { if ( ! is_array( $methods ) || is_admin() ) {
return $methods; return $methods;
} }
if ( ! is_admin() ) { if ( ! isset( WC()->customer ) ) {
if ( ! isset( WC()->customer ) ) { return $methods;
return $methods; }
}
$customer_country = WC()->customer->get_billing_country() ?: WC()->customer->get_shipping_country(); $customer_country = WC()->customer->get_billing_country() ?: WC()->customer->get_shipping_country();
$site_currency = get_woocommerce_currency(); $site_currency = get_woocommerce_currency();
$payment_methods = $c->get( 'ppcp-local-apms.payment-methods' ); $payment_methods = $c->get( 'ppcp-local-apms.payment-methods' );
foreach ( $payment_methods as $payment_method ) { foreach ( $payment_methods as $payment_method ) {
if ( if (
! in_array( $customer_country, $payment_method['countries'], true ) ! in_array( $customer_country, $payment_method['countries'], true )
|| ! in_array( $site_currency, $payment_method['currencies'], true ) || ! in_array( $site_currency, $payment_method['currencies'], true )
) { ) {
unset( $methods[ $payment_method['id'] ] ); unset( $methods[ $payment_method['id'] ] );
}
} }
} }