WooCommerce How To Disable Payment Gateways For Some Country

WooCommerce How To Disable Payment Gateways For Some Country
142 Views

Disable Payment Gateways For Some Countries

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
<?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;

}
?>

Was this article helpful?
YesNo

Leave a comment

Your email address will not be published.