Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 593 Vote(s) - 3.62 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change the default selected payment gateway in Woocommerce

#1
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][1]][1]

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

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


[1]:
Reply

#2
**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][1]][1]

-----

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][2]][2]


[1]:

[2]:
Reply

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

#4
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.
Reply

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

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



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through