Mahmudul Hasan
Mahmudul Hasan

Reputation: 181

Change the default selected payment gateway in Woocommerce

I have two different payment gateway (stripe and bank transfer) in Woocommerce checkout page. But "Bank transfer" (bacs) is always auto selected by default.

Here is screenshot of the payment gateways on my checkout page:

enter image description here

I would like to change that and auto select stripe payment gateway intead.

How can I do it?. Any help is appreciated.

Upvotes: 18

Views: 37752

Answers (4)

TommyZG
TommyZG

Reputation: 560

Had the same issue. Rearranging the methods didn't work, this was the solution:

  1. (Arrange the methods as you would like them to be shown)
  2. Turn off all payment methods except the one you want to be selected by default and save changes.
  3. Turn on the second method and save changes.
  4. Repeat for all the remaining methods, enabling them one by one and saving in between.

Upvotes: 5

Carl Ortiz
Carl Ortiz

Reputation: 465

You can just rearrange the payment gateway according to your need (in your case Credit Card (Stripe) followed by Direct Bank Transfer) so that the top one would always be selected per new session.

WooCommerce will automatically save the currently selected payment method (ex. Direct Bank Transfer) into the current session and when you reload the page, that payment method will be selected and not the default one. You can test it in a private window browser.

Update: This answer is simply an explanation to how WooCommerce handle default gateway. If by any change it doesn't work. There might be some code (Like the code by LoicTheAztec) from your theme or from your plugins that is overwritting this functionality. If you want to force it to default to a particular gateway, you can follow LoicTheAztec answer.

Upvotes: 22

JDWeb
JDWeb

Reputation: 1

Yes, the radio button will default to the highest active gateway.

Upvotes: 0

LoicTheAztec
LoicTheAztec

Reputation: 253968

Updated

You can try to add the following code, to change the default payment gateway on checkout page. You will have to define the default desired payment gateway ID, in this code:

add_action( 'template_redirect', 'define_default_payment_gateway' );
function define_default_payment_gateway(){
    if( is_checkout() && ! is_wc_endpoint_url() ) {
        // HERE define the default payment gateway ID
        $default_payment_id = 'stripe';

        WC()->session->set( 'chosen_payment_method', $default_payment_id );
    }
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

You will always get Stripe as default now:

enter image description here


To get the needed payment gateway ID for Stripe , go in Woocommerce > Settings > Checkout and find it in the "Gateway ID" column as in this screenshot:

enter image description here

Upvotes: 31

Related Questions