/**
* @snippet WooCommerce Disable Payment Gateway for a Specific Country
* @how-to Watch tutorial @ https://shop.wanderlust-webdesign.com/?p=2887
* @sourcecode https://shop.wanderlust-webdesign.com/?p=2887
* @author Conrado Galli
* @compatible WooCommerce 3.6.0
* @donate https://www.mercadopago.com/mla/checkout/start?pref_id=86419360-6ddd9244-06ca-4692-8cff-706b98a94a2b
*/

add_filter( 'woocommerce_available_payment_gateways', 'wanderlust_payment_gateway_disable_country' );

function wanderlust_payment_gateway_disable_country( $available_gateways ) {
if ( is_admin() ) return $available_gateways;
if ( isset( $available_gateways['paypal'] ) && WC()->customer->get_billing_country() <> 'US' ) {
unset( $available_gateways['paypal'] );
} else {
if ( isset( $available_gateways['woo-mercado-pago-basic'] ) && WC()->customer->get_billing_state() == 'X' ) {
unset( $available_gateways['woo-mercado-pago-basic'] );
}
}
return $available_gateways;
}