You might want to disable PayPal for non-local customers or enable a specific gateway for only one country… Either way, this is a very common requirement for all of those who trade internationally.
Here’s a simple snippet you can further customize to achieve your objective. Simply pick the payment gateway “slug” you want to disable/enable (“paypal”, “authorize”, “stripe”, etc.) and the country code (US, ES, IE, etc.) and then apply your conditional rules in the plugin below.
PHP Snippet: Disable Payment Gateway for Specific Billing Country
/**
* @snippet WooCommerce Disable Payment Gateway for a Specific Country
* @how-to Get tutoraspire.com FREE
* @author Tutor Aspire
* @compatible WooCommerce 6
* @donate $9 https://tutoraspire.com
*/
add_filter( 'woocommerce_available_payment_gateways', 'tutoraspire_payment_gateway_disable_country' );
function tutoraspire_payment_gateway_disable_country( $available_gateways ) {
if ( is_admin() ) return $available_gateways;
if ( isset( $available_gateways['authorize'] ) && WC()->customer && WC()->customer->get_billing_country() 'US' ) {
unset( $available_gateways['authorize'] );
} else {
if ( isset( $available_gateways['paypal'] ) && WC()->customer && WC()->customer->get_billing_country() == 'US' ) {
unset( $available_gateways['paypal'] );
}
}
return $available_gateways;
}
Is There a WooCommerce “Payment Gateways by Country” Plugin?
If you don’t feel 100% confident with coding, I decided to look for a reliable plugin that achieves the same result of this snippet (and more).
In this case, I found the WooCommerce Conditional Payment Gateways plugin to be the most complete when you need to enable/disable payment gateways based on certain criteria. You can create unlimited “rules” and use, for example, cart totals, billing country, shipping country, user role and much more to define which payment gateway shows and which not.
But in case you don’t want to use plugins and wish to code (or wish to try that), then keep reading 🙂