Refactor paypal and stripe combined logic, add fallback to specified settings when previously saved settings were detected by no option present for the enabled setting.

This commit is contained in:
Gerhard 2019-05-16 15:35:29 +02:00
parent b0a831b64f
commit 99b183e5bb
1 changed files with 4 additions and 8 deletions

View File

@ -1509,6 +1509,8 @@ class WC_Admin_Setup_Wizard {
$gateways['stripe']['enabled'] = true;
$gateways['stripe']['featured'] = true;
$offered_gateways += array( 'stripe' => $gateways['stripe'] );
} elseif ( $can_paypal ) {
$gateways['ppec_paypal']['enabled'] = true;
}
if ( in_array( $spotlight, array( 'klarna_checkout', 'klarna_payments' ), true ) ) {
@ -1524,10 +1526,6 @@ class WC_Admin_Setup_Wizard {
);
}
if ( $can_paypal && ! $can_stripe ) {
$gateways['ppec_paypal']['enabled'] = true;
}
if ( $can_paypal ) {
$offered_gateways += array( 'ppec_paypal' => $gateways['ppec_paypal'] );
}
@ -1549,9 +1547,7 @@ class WC_Admin_Setup_Wizard {
$gateways['stripe']['enabled'] = true;
$gateways['stripe']['featured'] = true;
$offered_gateways += array( 'stripe' => $gateways['stripe'] );
}
if ( $can_paypal && ! $can_stripe ) {
} elseif ( $can_paypal ) {
$gateways['ppec_paypal']['enabled'] = true;
}
@ -1617,7 +1613,7 @@ class WC_Admin_Setup_Wizard {
// Show the user-saved state if it was previously saved.
// Otherwise, rely on the item info.
if ( is_array( $previously_saved_settings ) ) {
$should_enable_toggle = isset( $previously_saved_settings['enabled'] ) && 'yes' === $previously_saved_settings['enabled'];
$should_enable_toggle = ( isset( $previously_saved_settings['enabled'] ) && 'yes' === $previously_saved_settings['enabled'] ) ? true : ( isset( $item_info['enabled'] ) && $item_info['enabled'] );
} else {
$should_enable_toggle = isset( $item_info['enabled'] ) && $item_info['enabled'];
}