Skip to content

Commit

Permalink
Refactor; split the conditional branching into two
Browse files Browse the repository at this point in the history
  • Loading branch information
makotom committed Aug 2, 2024
1 parent a5a4446 commit de569d2
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions class-wc-settings-page-komoju.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit de569d2

Please sign in to comment.