How To Disable Payment Gateways For Some Country in woocommerce

How To Disable Payment Gateways For Some Country in woocommerce
420 Views
0
(0)

In today’s global marketplace, it’s common for online businesses to operate across multiple countries. However, there may be situations where you want to restrict payment options for customers in certain countries in WooCommerce. This could be due to various reasons, such as legal regulations, currency conversion issues, or high fraud rates.

Disabling payment gateways for specific countries can be a daunting task for businesses, especially when they have to manage multiple payment gateways.

Also Read: How To Disable Payment Gateways For Specific User Roles in WooCommerce

In this blog, I will guide you through the process of disabling payment gateways for specific countries programmatically in woocommerce.

So, whether you’re a small online store or a large e-commerce platform, this blog will provide you with the necessary information to disable payment gateways for specific countries in woocommerce in a few simple steps. Let’s get started!

Navigate to your website’s child theme’s root and search for the functions.php file. Scroll to the bottom and paste the Code given below.

<?php
add_filter( 'woocommerce_available_payment_gateways', 'cxc_disable_payment_gateway_by_country' );
function cxc_disable_payment_gateway_by_country( $gateways ) {
	
	if( is_admin() ) {
		return $gateways;
	}
	
	if( is_wc_endpoint_url( 'order-pay' ) ) { // Pay for order page

		$order = wc_get_order( wc_get_order_id_by_order_key( $_GET[ 'key' ] ) );
		$country = $order->get_billing_country();

	} else { // Cart page

		$country = WC()->customer->get_billing_country();

	}

	if ( 'CA' === $country ) {
		if ( isset( $gateways[ 'cod' ] ) ) {
			unset( $gateways[ 'cod' ] );
		}
	}

	return $gateways;

}
?>

Here is the country code based on the location

Country CodeLocation/Country
AFAfghanistan
AXÅland Islands
ALAlbania
DZAlgeria
ASAmerican Samoa
ADAndorra
AOAngola
AIAnguilla
AQAntarctica
AGAntigua and Barbuda
ARArgentina
AMArmenia
AWAruba
AUAustralia
ATAustria
AZAzerbaijan
BSBahamas
BHBahrain
BDBangladesh
BBBarbados
BYBelarus
PWBelau
BEBelgium
BZBelize
BJBenin
BMBermuda
BTBhutan
BOBolivia
BQBonaire, Saint Eustatius and Saba
BABosnia and Herzegovina
BWBotswana
BVBouvet Island
BRBrazil
IOBritish Indian Ocean Territory
BNBrunei
BGBulgaria
BFBurkina Faso
BIBurundi
KHCambodia
CMCameroon
CACanada
CVCape Verde
KYCayman Islands
CFCentral African Republic
TDChad
CLChile
CNChina
CXChristmas Island
CCCocos (Keeling) Islands
COColombia
KMComoros
CGCongo (Brazzaville)
CDCongo (Kinshasa)
CKCook Islands
CRCosta Rica
HRCroatia
CUCuba
CWCuraçao
CYCyprus
CZCzech Republic
DKDenmark
DJDjibouti
DMDominica
DODominican Republic
ECEcuador
EGEgypt
SVEl Salvador
GQEquatorial Guinea
EREritrea
EEEstonia
SZEswatini
ETEthiopia
FKFalkland Islands
FOFaroe Islands
FJFiji
FIFinland
FRFrance
GFFrench Guiana
PFFrench Polynesia
TFFrench Southern Territories
GAGabon
GMGambia
GEGeorgia
DEGermany
GHGhana
GIGibraltar
GRGreece
GLGreenland
GDGrenada
GPGuadeloupe
GUGuam
GTGuatemala
GGGuernsey
GNGuinea
GWGuinea-Bissau
GYGuyana
HTHaiti
HMHeard Island and McDonald Islands
HNHonduras
HKHong Kong
HUHungary
ISIceland
INIndia
IDIndonesia
IRIran
IQIraq
IEIreland
IMIsle of Man
ILIsrael
ITItaly
CIIvory Coast
JMJamaica
JPJapan
JEJersey
JOJordan
KZKazakhstan
KEKenya
KIKiribati
KWKuwait
KGKyrgyzstan
LALaos
LVLatvia
LBLebanon
LSLesotho
LRLiberia
LYLibya
LILiechtenstein
LTLithuania
LULuxembourg
MOMacao
MGMadagascar
MWMalawi
MYMalaysia
MVMaldives
MLMali
MTMalta
MHMarshall Islands
MQMartinique
MRMauritania
MUMauritius
YTMayotte
MXMexico
FMMicronesia
MDMoldova
MCMonaco
MNMongolia
MEMontenegro
MSMontserrat
MAMorocco
MZMozambique
MMMyanmar
NANamibia
NRNauru
NPNepal
NLNetherlands
NCNew Caledonia
NZNew Zealand
NINicaragua
NENiger
NGNigeria
NUNiue
NFNorfolk Island
KPNorth Korea
MKNorth Macedonia
MPNorthern Mariana Islands
NONorway
OMOman
PKPakistan
PSPalestinian Territory
PAPanama
PGPapua New Guinea
PYParaguay
PEPeru
PHPhilippines
PNPitcairn
PLPoland
PTPortugal
PRPuerto Rico
QAQatar
REReunion
RORomania
RURussia
RWRwanda
BLSaint Barthélemy
SHSaint Helena
KNSaint Kitts and Nevis
LCSaint Lucia
SXSaint Martin (Dutch part)
MFSaint Martin (French part)
PMSaint Pierre and Miquelon
VCSaint Vincent and the Grenadines
WSSamoa
SMSan Marino
STSão Tomé and Príncipe
SASaudi Arabia
SNSenegal
RSSerbia
SCSeychelles
SLSierra Leone
SGSingapore
SKSlovakia
SISlovenia
SBSolomon Islands
SOSomalia
ZASouth Africa
GSSouth Georgia/Sandwich Islands
KRSouth Korea
SSSouth Sudan
ESSpain
LKSri Lanka
SDSudan
SRSuriname
SJSvalbard and Jan Mayen
SESweden
CHSwitzerland
SYSyria
TWTaiwan
TJTajikistan
TZTanzania
THThailand
TLTimor-Leste
TGTogo
TKTokelau
TOTonga
TTTrinidad and Tobago
TNTunisia
TRTurkey
TMTurkmenistan
TCTurks and Caicos Islands
TVTuvalu
UGUganda
UAUkraine
AEUnited Arab Emirates
GBUnited Kingdom (UK)
USUnited States (US)
UMUnited States (US) Minor Outlying Islands
UYUruguay
UZUzbekistan
VUVanuatu
VAVatican
VEVenezuela
VNVietnam
VGVirgin Islands (British)
VIVirgin Islands (US)
WFWallis and Futuna
EHWestern Sahara
YEYemen
ZMZambia
ZWZimbabwe

Also Read:

How to Edit Payment Gateway Title and Description in WooCommerce

How to disable all payment methods in WooCommerce

How To Change Place Order Button Text on Checkout Page WooCommerce

Why would I want to disable payment gateways for specific countries?

There could be various reasons for disabling payment gateways for specific countries, such as legal restrictions, high fraud rates, currency conversion issues, or simply not having the resources to support transactions in certain countries.

Can I disable payment gateways for multiple countries at once?

Yes, you can disable payment gateways for multiple countries at once by using programmatic solutions such as APIs or plugins.

Is it legal to disable payment gateways in some countries?

Yes, it is legal to disable payment gateways for some countries if it complies with local laws and regulations.

How useful was this blog?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this blog.

Leave a comment

Your email address will not be published. Required fields are marked *