Skip to content

Instantly share code, notes, and snippets.

@xlplugins
Created April 21, 2025 08:11
Show Gist options
  • Save xlplugins/98342d4fadc24b01cf18e884331f11e8 to your computer and use it in GitHub Desktop.
Save xlplugins/98342d4fadc24b01cf18e884331f11e8 to your computer and use it in GitHub Desktop.
2nd Radio button selected on page load
add_filter( 'woocommerce_available_payment_gateways', 'set_default_payment_gateway' );
function set_default_payment_gateway( $available_gateways ) {
// Ensure there are available payment gateways
if ( ! is_admin() && isset( $available_gateways ) && count( $available_gateways ) > 1 ) {
// Get the keys of available gateways
$gateway_keys = array_keys( $available_gateways );
// Set the second gateway (index 1) as default
if ( isset( $gateway_keys[1] ) ) {
$default_gateway = $gateway_keys[1];
// Set the selected gateway to the second one
WC()->session->set( 'chosen_payment_method', $default_gateway );
}
}
return $available_gateways;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment