25% off ProSNIPC25OFF

Set the Default Payment Gateway

Pre-selects a specific payment gateway on the checkout page by moving it to the top of the available methods list.

PHPby SnipCraft
php
<?php
if ( ! class_exists( 'WooCommerce' ) ) {
    return;
}

/**
 * Make a specific gateway appear first (pre-selected) on checkout.
 * Replace 'stripe' with the ID of your preferred gateway
 * (e.g. 'paypal', 'bacs', 'cheque', 'cod').
 */
add_filter( 'woocommerce_available_payment_gateways', 'scseed_set_default_payment_gateway' );
function scseed_set_default_payment_gateway( $gateways ) {
    if ( is_admin() ) {
        return $gateways;
    }

    $preferred = 'stripe'; // Change to your gateway ID

    if ( isset( $gateways[ $preferred ] ) ) {
        $first    = array( $preferred => $gateways[ $preferred ] );
        unset( $gateways[ $preferred ] );
        $gateways = $first + $gateways;
    }

    return $gateways;
}
#checkout#gateway#payment#ux#woocommerce