How to Hide WooCommerce Payment Methods by Shipping Zone

Hide Cash on Delivery or another WooCommerce payment gateway for a specific shipping zone while keeping payment options available in other delivery areas.

Last updated:

Reviewed for accuracy by Jesse Nickles

Try the built-in Cash on Delivery restriction first

If you only want to restrict Cash on Delivery (COD), open WooCommerce → Settings → Payments → Take offline payments → Cash on Delivery → Manage. Under Enable for shipping methods, select the shipping methods or rates where COD should remain available, then save. This avoids PHP when those methods are specific to the areas you serve. The setting does not select a shipping zone ID directly, so it may not work when the same shipping method is available in both permitted and restricted zones. See WooCommerce's Cash on Delivery instructions.

For a restriction tied to an exact zone, WooCommerce matches the customer's shipping address to the first applicable shipping zone. Put more specific zones above broader ones, as explained in its shipping zone documentation. Payment gateways cannot be assigned directly to a zone through the standard settings.

  1. Go to WooCommerce → Settings → Shipping → Shipping zones. Edit the zone to restrict and note the number in zone_id in the admin URL. A zone ID identifies the delivery area; it is not the ID of a shipping-method instance.
  2. In WooCommerce → Settings → Payments, identify the payment gateway you want to hide. The PHP filter uses its internal gateway ID, not the customer-facing checkout label.

WooCommerce's built-in offline payment methods have these gateway IDs:

Payment method Gateway ID
Cash on Delivery cod
Direct Bank Transfer bacs
Check Payments cheque

For payment extensions such as Stripe, PayPal, or WooPayments, verify the gateway ID in that extension's documentation or source before using it in the code.

Hide the gateway for that zone

Back up your store and test the change on staging. Add the following snippet inside the existing PHP code in your active child theme's functions.php, without adding another <?php tag. HoverCraft's child theme instructions explain how to avoid editing the parent theme. Replace 3 with the target zone ID, cod with the internal gateway ID, and myshop in both places with a prefix unique to your site.

function myshop_hide_gateway_by_zone( $gateways ) {
	if ( ! function_exists( 'WC' ) || ! WC()->cart || ! class_exists( 'WC_Shipping_Zones' ) ) {
		return $gateways;
	}

	foreach ( WC()->cart->get_shipping_packages() as $package ) {
		$zone = WC_Shipping_Zones::get_zone_matching_package( $package );

		if ( (int) $zone->get_id() === 3 ) {
			unset( $gateways['cod'] );
			break;
		}
	}

	return $gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'myshop_hide_gateway_by_zone', 20 );

The woocommerce_available_payment_gateways filter checks every shipping package using WooCommerce's shipping zone API. If any package matches zone 3, it removes cod from the payment options for the entire checkout, not just that package. Carts containing only virtual products may have no shipping packages, so this code does not restrict those orders. Stores that split orders into several shipping packages must account for this whole-order behavior.

Test the restriction in checkout

  1. Add a shippable product to the cart. Enter an address in the restricted zone and confirm the selected gateway disappears after checkout updates.
  2. Enter an address in another zone. The gateway should remain available if its normal WooCommerce settings allow it. Check the first matching zone when the result differs.
  3. Test as a guest and a signed-in customer, and confirm at least one usable payment method remains. If your store sells virtual-only products or splits shipping into multiple packages, check those cases separately.

The PHP woocommerce_available_payment_gateways filter can hide payment options in both classic checkout and the Checkout Block. WooCommerce's updated Checkout Block guidance explicitly confirms that removing a gateway through PHP works. Its hook compatibility table still calls the filter partially supported because other gateway manipulations may require block integration. Additional JavaScript is not normally needed simply to unset a gateway, but test your actual payment extension and checkout layout.

If the restriction does not work

Use a restriction plugin instead

WooCommerce's Conditional Shipping and Payments extension offers restrictions under WooCommerce → Settings → Restrictions → Payment Gateways. Choose the gateway under Exclude Gateways and add conditions such as Shipping Method or shipping destination.

Those conditions do not directly match a numeric shipping zone ID. A Shipping Method condition may produce the result you want when that method is unique to the zone; otherwise, use the PHP example for an exact zone-ID check. Verify the extension's compatibility with your checkout and payment gateway before using the restriction for live orders.