mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-08 21:52:55 +08:00
♻️ Decrease nesting depth of callback code
This commit is contained in:
parent
705ffbdf17
commit
ff943b5041
1 changed files with 13 additions and 15 deletions
|
@ -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'] ] );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue