Can I Restrict a WooCommerce Gateway by Country?
Why WooCommerce Needs Custom Code Here
Most gateway plugins' own "restrict to specific countries" setting checks the customer's billing address, since that's what the gateway itself typically cares about for fraud and compliance purposes. Filtering by shipping address instead requires hooking into the same woocommerce_available_payment_gateways filter used for other conditional-payment scenarios, checking the cart's shipping destination specifically.
add_filter( 'woocommerce_available_payment_gateways', function( $gateways ) {
$shipping_country = WC()->customer ? WC()->customer->get_shipping_country() : '';
if ( isset( $gateways['local_only_gateway'] ) && $shipping_country !== 'GB' ) {
unset( $gateways['local_only_gateway'] );
}
return $gateways;
} );
Things Worth Getting Right
- The shipping address may not be set yet at certain points in the checkout flow (before the customer has entered it), so the filter needs to handle an empty/unknown shipping country gracefully rather than assuming it's always available.
- "Ship to billing address" toggles some checkout flows offer mean the shipping and billing country are sometimes identical anyway — worth confirming the actual customer behavior before assuming this distinction matters as much as it might in theory.
- Cache and AJAX refresh behavior — WooCommerce needs to re-evaluate available gateways when the shipping address changes at checkout, which usually happens automatically via the checkout's own AJAX update, but is worth testing specifically.
Implementing It
- Confirm the exact restriction logic needed (which gateway, which countries) before writing the filter.
- Use
woocommerce_available_payment_gatewayschecking shipping country viaWC()->customer->get_shipping_country(), rather than the gateway's own billing-based setting. - Test that the gateway list updates correctly when the shipping address changes at checkout, without a full page reload.
Need this built and tested properly? See custom WooCommerce development.