Can I Restrict a WooCommerce Gateway by Country?

A payment method becoming available or unavailable based on the shipping destination rather than the billing address

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

  1. Confirm the exact restriction logic needed (which gateway, which countries) before writing the filter.
  2. Use woocommerce_available_payment_gateways checking shipping country via WC()->customer->get_shipping_country(), rather than the gateway's own billing-based setting.
  3. 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.

Available for new projects

NEXT STEP

Rather have it fixed than keep reading?

Based in Bangladesh — serving clients worldwide. Tell me what's happening and you'll have a reply within one working day.

  • Reply within one working day
  • Fixed quote before work starts
  • UK, EU and US hours covered