preselect default payment gateway based on country
-
Hello, I got different Payment Gateways to different countrys, the country is set with GeoIP but is a few cases the customer must change that. What I need is a preselected default payment gateway based on country, because of this issue:
Example:
Country Netherlands has 2 payment options: Klarna Checkout(default) and PayPal
Country Spain has 1 option: PayPal
So if a customer checks out with Spain selected, PayPal will be preselected, this is correct,
but when the customer changes the country to Netherlands, it will still have PayPal selected while showing Klarna Checkout as an option to select.
But what I need is Klarna Checkout to be preselected once you choose Netherlands (since that’s a iframe payment window)
Note, the checkout is reloading when changing shipping country, as I use Aelia Currency Switcher to set the correct currency aswell, so I got the country selector on top.
I did try this snippet:add_action( 'template_redirect', 'define_default_payment_gateway' ); function define_default_payment_gateway(){ if( is_checkout() && ! is_wc_endpoint_url() ) { $default_payment_id = 'kco'; WC()->session->set( 'chosen_payment_method', $default_payment_id ); } }
This only work halfway, it sets the Klarna Checkout as default if present, but when trying to select PayPal then it reloads the page setting Klarna Checkout as default again.
Any input and help would be great. Thanks
- You must be logged in to reply to this topic.