Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions inc/checkout/class-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -1963,12 +1963,23 @@ public function get_checkout_variables() {
/*
* Get the default gateway.
*
* Only pre-select when there is exactly one active gateway so
* the user is not surprised by branded buttons (e.g. PayPal)
* before they have made a choice.
* Restore a previously-chosen gateway from the session (multi-step
* checkout), or auto-select only when there is exactly one active
* gateway and the cart actually requires payment. This prevents
* branded buttons (e.g. PayPal) from appearing before the user has
* made a choice, and avoids pre-selecting a paid gateway on free carts.
*/
$active_gateways = array_keys(wu_get_active_gateway_as_options());
$default_gateway = count($active_gateways) === 1 ? current($active_gateways) : '';
$saved_gateway = $this->request_or_session('gateway', '');
$default_gateway = '';

if ($this->should_collect_payment()) {
if ($saved_gateway && in_array($saved_gateway, $active_gateways, true)) {
$default_gateway = $saved_gateway;
} elseif (1 === count($active_gateways)) {
$default_gateway = current($active_gateways);
}
}

$d = wu_get_site_domain_and_path('replace');

Expand Down