16

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.

4 Answers 4

30

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

1
  • I have done this as per your instruction. But still, it is selected bank transfer gateway by default when I refresh the checkout page. I want to select credit card by default. Commented May 9, 2018 at 15:48
20

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.

8
  • 4
    Great comment! Best solutions are the easiest Commented Nov 30, 2018 at 15:14
  • Thank you so much! :) Happy to help.
    – Carl Ortiz
    Commented Nov 30, 2018 at 16:58
  • Nice find there, the cookie sessions can be very troublesome sometimes. You think your code changes are not working, when it's all because they conditionally depend on the set cookie options. Can be frustrating sometimes, lol. Thanks again. Commented Oct 12, 2019 at 7:15
  • 1
    it may be higher but is the radio button selected by default too?
    – landed
    Commented Apr 1, 2020 at 19:28
  • Not working! Just checked. Above solution by LoicTheAztec is working fine.
    – Courage
    Commented Jul 12, 2021 at 3:24
4

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.
1
  • At step 2, click on switch to turn it on (even if it's grayed out with "finish setup" button enabled, don't click that one), then save.
    – s-t
    Commented Mar 26 at 14:44
0

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.