From de569d22c2b21d82c92e2e475ad6db8ea8a318b0 Mon Sep 17 00:00:00 2001 From: Makoto Mizukami Date: Fri, 2 Aug 2024 13:25:41 +0900 Subject: [PATCH] Refactor; split the conditional branching into two --- class-wc-settings-page-komoju.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/class-wc-settings-page-komoju.php b/class-wc-settings-page-komoju.php index 0c88099..93ef418 100644 --- a/class-wc-settings-page-komoju.php +++ b/class-wc-settings-page-komoju.php @@ -371,14 +371,15 @@ private function fetch_all_payment_methods() $slug = $payment_method['type_slug']; $pm_currency = $payment_method['currency']; - // If the payment method satisfies both of these two conditions, reject it: - // 1. There is an alternative payment method with the same slug (possibly with a more preferable currency) - // 2. The currency for the payment method defers from the default currency for the WooCommerce configuration - // That means, we accept payment methods if and only if - // 1. there is no alternative payment method with the same slug, OR - // 2. an alternative payment method with the same slug exists, but the currency for the payment method matches to the currency for the WooCommerce configuration and thus preferred - if (isset($methods_by_slug[$slug]) && $pm_currency !== $wc_currency) { - continue; + // If $slug is not set, register + if (!isset($methods_by_slug[$slug])) { + $methods_by_slug[$slug] = $payment_method; + } else { + // If $slug is already registered and + // the payment currency matches the WooCommerce currency then override it + if ($pm_currency === $wc_currency) { + $methods_by_slug[$slug] = $payment_method; + } } $methods_by_slug[$slug] = $payment_method;