Disable payment gateways based on country from woocommerce
Disable payment gateways based on country is a task that must do any commerce to sell in many countries. How we know, Woocommerce has fields like country or state in his checkout form and those will help us to do this task.
Before, we have to know the short name of each gateway to we can play with them. Here a table with the gateways more know.
| Short Code | Name Long |
|---|---|
| cod | Cash on Delivery |
| bacs | Direct bank transfer |
| cheque | Check payments |
| paypal | Paypal |
| stripe | Stripe |
| fullculqi | Culqi |
| payme | Payme |
Now we know about those short names, we can remove or add it how we want. So, we will use the woocommerce_available_payment_gateways hook to do it.
Here are 2 examples of: Disable payment gateways based on country from woocommerce
Example 1: If the country is AR, the we will remove the Paypal Gateway and if the country is the US, we will remove Culqi and Payme Gateway.
<?php
function letsgo_remove_gateways($gateways = []) {
$country = WC()->customer->get_billing_country();
switch($country) {
case 'AR' : unset( $gateways['paypal'] ); break;
case 'US' :
unset($gateways['fullculqi']);
unset($gateways['payme']);
break;
}
return $gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'letsgo_remove_gateways', 10, 1);
Example 2: If the country is the US and the state is Florida ( FL ), use Paypal as the only payment gateway
<?php
function letsgo_add_gateways($gateways = []) {
$country = WC()->customer->get_billing_country();
$state = WC()->customer->get_billing_state();
$aux_gateways = $gateways;
if( $country == 'US' && $state == 'FL' ) {
foreach( $aux_gateways as $key => $data ) {
if( $key == 'paypal' )
continue;
unset($gateways[$key]);
}
}
return $gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'letsgo_add_gateways', 10, 1);
Remember that you must put this code in your functions.php on your active theme.

Hi,
Will this work where the PayPal checkout button is on the Cart page? I ask because I have been told that having the button there bypasses the Woo address fields.
To help understand the blocking process, does the code work on the data provided directly from PP. Also, does it work if the buyer pays by bank card?
Thanks
Hi,
This snippet works only on the checkout page.
Thanks
Check how Fyrestorm Greataxe ranks across three independent tier lists on this page. You can see where Exotic Weaponry lands on the consensus tier list here. b06e1dc7.
Patience came out top for me, which surprised my friends. The result page suggests reading about the matching sin. b92fa849.
The platform section lists exactly where GTA 6 is playable. The wiki layout makes it easy to jump straight to your question. 18d9cd5f.
Beginners will find the FAQ answers most day-one questions. First and last names make character naming a bit different here. 85c779ad.
A block that cannot reach its door will end your run — plan the order. Color block jam free online — that is exactly what this page gives you. 93b7cc56.
Honestly, the mole-bonking check woke up my reflexes. Honestly, the terms of humanity are worth reading to the end. 9749d259.
Whether you play five minutes or an hour, the site helps. The core loop is train, throw, plant, earn and upgrade. d44f54fb.
The car rankings resource helps players avoid wasting time on the wrong vehicle. This GTA 6 vehicle hub explains hidden cars, early ownership and rare supercar routes. b2a4c049.
This racing sim page is a clean place to jump into LibreCorsa from search. The page answers what LibreCorsa is and lets you play it free online. 50808926.
This tool is worth bookmarking, because it makes tiny percentages less confusing. The calculator saves guesswork, because the cumulative chance is easier to interpret. c60cd252.