Disable WooCommerce payment gateway for specific countries
A WooCommerce payment gateway should not always be visible to every shopper. If a store sells across borders, the checkout screen can quickly become a place where payment rules, shipping limits, fraud risk, and transaction fees collide.

So let us build this in a controlled way: we will restrict a WooCommerce payment gateway by the customer’s billing country, either with a small WordPress code snippet or with a dedicated plugin if you prefer a settings panel. The goal is not to make checkout clever for its own sake. The goal is to keep the customer’s visible payment options honest, regional, and maintainable.
Why country-based payment restrictions belong in checkout logic
Firstly, it helps to separate two different ideas: whether you can accept an order from a country, and whether every payment method should be available there. WooCommerce often lets us configure broad selling locations, shipping zones, tax settings, and payment gateways separately. That is useful, but it also means the checkout can accidentally show a payment method that does not match the real-world order process.
For example, you might want to:
- Hide cash on delivery outside your domestic market because collection is unreliable or impossible.
- Disable bank transfer for countries where manual reconciliation becomes too slow.
- Remove a card gateway in regions where the provider’s fees are too high.
- Show a local payment method only to shoppers from the country where that method is recognized.
- Keep PayPal available in one region but hide it in another because of account, settlement, or compliance constraints.
This is especially common in stores selling physical products with uneven fulfillment rules. A shop selling audio gear, refurbished devices, or collector products may have different risk levels by destination; I have seen similar operational thinking in niche commerce around analog audio, film photography, and restored retro equipment, where the item itself can be delicate, expensive to ship, and awkward to recover if payment or delivery fails.
The clean place to make payment visibility decisions is checkout. More precisely, it is the moment WooCommerce prepares the list of available payment gateways.
We are not changing the order after it is placed; we are shaping the choices before the shopper can choose the wrong one.
That distinction matters. A hidden payment gateway is easier for customers to understand than an order that later needs to be cancelled, manually corrected, or explained by support.
The two practical routes: code snippet or plugin
There are two reliable ways to disable a WooCommerce payment gateway for specific countries.
The first route is custom logic using the WooCommerce filter woocommerce_available_payment_gateways. This is the standard hook for adjusting which payment gateways are available during checkout. We check the customer’s billing country, then remove one or more gateways from the available list.
The second route is a plugin such as Conditional Payments for WooCommerce. This gives us a visual interface where we can create rules without editing PHP. For many store owners, that is the better route because the rule is visible in the WordPress admin area and easier to hand over to another person.
Here is the practical comparison.
| Approach | Best for | Main advantage | Main caution |
|---|---|---|---|
Custom snippet with woocommerce_available_payment_gateways | Stores with one or two stable rules | Lightweight and precise | Needs safe placement in a child theme or site-specific plugin |
| Conditional payments plugin | Stores with many rules or non-developer admins | Clear settings panel and easier maintenance | Adds plugin dependency and may vary by gateway compatibility |
| Gateway-specific settings | Payment plugins that already include country rules | No extra code or plugin needed | Not every gateway plugin includes this feature |
| Shipping or selling location settings | Blocking countries entirely | Good for broad store policy | Too blunt if you only want to hide one payment method |
Notice the final row. Selling locations and shipping zones are not the same as payment restrictions. If you block a country from selling locations, you are saying the store does not sell there. If you hide one payment gateway for that country, you are saying the store sells there but only through appropriate payment methods.
That is the narrower, cleaner fix we want here.
Using the WooCommerce filter for gateway restrictions
WooCommerce exposes the available payment methods through the woocommerce_available_payment_gateways filter. When checkout loads, WooCommerce builds an array of gateway objects. The filter lets us inspect that array and remove a gateway before the customer sees it.
The basic shape is:
1. Hook a custom function into woocommerce_available_payment_gateways.
2. Confirm WooCommerce has a customer object available.
3. Read the billing country using WC()->customer->get_billing_country().
4. Compare that country to the country code we want to restrict.
5. Remove the gateway from the available gateways array.
6. Return the modified array back to WooCommerce.
WooCommerce country values use ISO 3166-1 alpha-2 country codes. That means we work with codes such as US, GB, CA, AU, DE, FR, and so on. This is a small detail, but it prevents many frustrating mistakes. Writing “Germany” will not match the stored billing country. Writing DE will.
Let us make the logic concrete without burying the page in a wall of PHP. If we wanted to disable cash on delivery for customers whose billing country is outside the United States, the function would read the billing country, check whether the value is not US, and then remove the gateway with the ID cod.
In WooCommerce, common gateway IDs include:
codfor Cash on Delivery.bacsfor Direct Bank Transfer.chequefor Check Payments.- Gateway IDs from payment plugins, such as Stripe, PayPal, or local payment methods, depending on the plugin.
The exact ID matters. Look at the payment method’s settings page in WooCommerce, inspect your gateway plugin documentation, or temporarily log the available gateway keys in a staging environment. Do not guess if the store is live.
Where to place the snippet safely
We should not edit the parent theme’s functions.php file directly. A parent theme update can overwrite the file, which means your payment restriction disappears at exactly the wrong time: quietly, after routine maintenance.
Use one of these safer locations instead:
- A child theme’s
functions.phpfile, if the rule is tied to the current site build and you already use a child theme. - A small site-specific plugin, if you want the rule to survive theme changes.
- A code snippets plugin, if your team already manages small PHP snippets through the WordPress admin area.
For long-term stores, I prefer a site-specific plugin because payment rules are business logic, not theme design. A checkout restriction should not vanish just because we changed the storefront layout.
Payment gateway rules are part of store operations, not decoration. Keep them somewhere that survives a theme redesign.
Before adding the rule on a production store, test it on a staging copy. Then test checkout as a customer from both an allowed country and a restricted country.
Reading the customer’s billing country correctly
The key method is WC()->customer->get_billing_country(). This returns the billing country code currently known to WooCommerce for the customer session.
There is one small behavior to understand: early in checkout, WooCommerce may not know the billing country yet. The customer may have just arrived at the checkout page, and the country field may still be empty or set to the store default. Once the shopper selects or changes the billing country, WooCommerce updates checkout fragments and recalculates available methods.
That means our rule should be written defensively. We should account for an empty country value and avoid breaking checkout if the customer object is not ready.
A sensible flow looks like this:
1. If the request is inside the WordPress admin area, return the gateways unchanged unless it is an AJAX checkout update.
2. If the WooCommerce customer object is missing, return the gateways unchanged.
3. Get the billing country with WC()->customer->get_billing_country().
4. If the billing country is empty, decide whether to keep gateways visible until the shopper chooses a country.
5. If the country matches the restricted country, remove the target gateway.
That fourth point is more important than it looks. Some store owners want a payment method hidden until a supported country is selected. Others prefer to show all methods until WooCommerce knows the customer’s country. The better choice depends on your checkout design.
For example, if your store sells mostly to one country and only occasionally internationally, showing the normal payment methods first may feel smoother. However, if you have strict regional payment rules, hiding unsupported gateways until the billing country is known can reduce confusion.
Example scenarios for country logic
Let us walk through common patterns.
| Business rule | Country condition | Gateway action |
|---|---|---|
| Cash on delivery only in one country | Billing country is not US | Remove cod |
| Bank transfer unavailable in Canada | Billing country is CA | Remove bacs |
| PayPal hidden for two countries | Billing country is FR or DE | Remove the PayPal gateway ID |
| Local payment method only in the Netherlands | Billing country is not NL | Remove that local gateway |
| High-fee gateway disabled in several regions | Billing country is in a restricted list | Remove the card or wallet gateway |
If you need several countries, do not write the same condition repeatedly. Use a list of country codes, then check whether the billing country is in that list. This keeps the rule readable. Six months from now, when you need to add one more country, you will thank yourself.
A clean country list might include BR, AR, and CL for a Latin America-specific rule, or DE, AT, and CH for a DACH-region rule. The names can be explained in comments, but the values WooCommerce checks should remain the two-letter country codes.
Finding the correct WooCommerce payment gateway ID
This is where many otherwise correct restrictions fail. The country logic works, the hook runs, the customer’s billing country is detected, and yet the gateway remains visible. Most of the time, the gateway ID is wrong.
WooCommerce core gateways are predictable: cod, bacs, and cheque are familiar. Third-party payment plugins can use IDs that are less obvious. A Stripe gateway might not be identified by the display name “Credit Card.” A PayPal plugin may expose several separate gateway IDs for standard PayPal, Pay Later, card fields, or express checkout buttons.
Use these clues:
- In WooCommerce admin, go to WooCommerce → Settings → Payments and open the payment method. Look at the URL and settings fields for hints.
- Read the gateway plugin’s documentation for its gateway ID.
- On a staging site, inspect the available gateway keys during checkout using temporary logging.
- If a plugin provides multiple payment buttons or express methods, confirm whether each one has a separate gateway ID.
Be patient here. The gateway title shown to shoppers is not always the gateway ID used in code. The visible label may say “Credit or debit card,” while the internal ID is something else entirely.
Also remember that some express payment buttons may appear in the cart, mini-cart, or product page rather than only at checkout. The woocommerce_available_payment_gateways filter is the standard tool for checkout availability, but gateway-specific buttons can have their own display logic. If a wallet button still appears outside checkout, look inside that gateway plugin’s settings for product page, cart page, or express checkout toggles.
Using a plugin for country-based payment rules
If you would rather not maintain PHP, a conditional payment plugin is a very reasonable option. Plugins like Conditional Payments for WooCommerce provide a WordPress admin interface for hiding or showing payment methods based on country and other conditions.
The usual workflow is:
1. Install and activate the conditional payments plugin.
2. Open its rules panel from the WooCommerce settings area.
3. Create a new rule for the payment method you want to control.
4. Choose the billing country condition.
5. Select the country or countries where the method should be hidden or allowed.
6. Save the rule.
7. Test checkout with different billing countries.
The panel wording differs by plugin, but the logic is usually one of two styles:
- “Disable this payment method when billing country is X.”
- “Enable this payment method only when billing country is X.”
Those are not identical. If you select “disable when country is Canada,” the gateway remains available everywhere else. If you select “enable only when country is United States,” the gateway is hidden for every non-US billing country. Read the condition label slowly before saving.
A plugin is often the right choice when rules become layered. For example, if you want to disable bank transfer for some countries, hide cash on delivery above a certain cart total, and show a local payment method only for a specific shipping zone, a visual rule builder can be easier to audit than several custom snippets.
However, do not install a conditional payments plugin just to avoid understanding the rule. You still need to know which countries, which gateways, and which customer field should drive the decision. The plugin gives us a panel; it does not define the business policy.
Billing country or shipping country?
Most stores should start with billing country because payment methods are usually tied to the payer and payment provider rules. The WooCommerce method from the standard approach is WC()->customer->get_billing_country(), and that is the right fit for many payment restrictions.
However, some stores think in terms of delivery risk. For example, cash on delivery is usually more connected to the shipping destination than to the billing address. If a shopper bills to one country but ships to another, which country should control the rule?
Here is the practical way to decide.
| Payment rule type | Usually use | Reason |
|---|---|---|
| Card processor availability | Billing country | Payment provider rules often relate to the payer |
| Cash on delivery | Shipping country | The collection happens at delivery |
| Bank transfer instructions | Billing or store policy | Depends on accounting workflow |
| Local wallet or regional payment method | Billing country | Method availability is usually customer-region based |
| Fraud or fulfillment risk | Shipping country | Risk often follows the destination |
For the specific filter we are discussing, the confirmed standard pattern is checking billing_country through the WooCommerce customer object. If your business rule should follow shipping country instead, adapt carefully and test more thoroughly, especially on checkouts where billing and shipping addresses can differ.
Testing the restriction before customers find it
Once the rule is in place, look at the checkout like a customer, not like the person who built it. Open a private browser window or use a clean test account. Add a normal product to the cart. Go to checkout.
Now test these paths:
1. Select an allowed billing country and confirm the gateway appears.
2. Select a restricted billing country and confirm the gateway disappears.
3. Change the billing country back and confirm the gateway returns.
4. Try a logged-out customer session.
5. Try a logged-in customer with a saved address.
6. Test on mobile width, where payment sections may collapse differently.
7. If you use caching or checkout optimization plugins, test with those active.
Checkout pages should generally be excluded from full-page caching, but optimization plugins can still affect scripts, fragments, or AJAX behavior. If the gateway does not update when the country changes, look at checkout update behavior before blaming the country condition itself.
Also place a test order with an allowed method. We are not only checking visibility. We are checking that the remaining gateway still processes the order correctly.
Common mistakes that make the rule unreliable
Country-based payment restrictions are not complicated, but a few small mistakes can make them feel unpredictable.
The first mistake is using full country names instead of two-letter country codes. WooCommerce stores country selections as codes such as US, GB, and DE. If your condition checks for “United States,” it will not match the billing country value returned by WooCommerce.
The second mistake is editing the parent theme. It may work today, but it is not durable. Use a child theme, site-specific plugin, or managed snippets tool.
The third mistake is targeting the wrong gateway ID. If the internal ID does not match, WooCommerce has nothing to remove. This is especially common with third-party gateways that display a friendly title at checkout but use a different internal key.
The fourth mistake is forgetting about saved customer data. A logged-in customer may already have a billing country in their account. That can make the payment method appear or disappear before they touch the country field. This is normal, but it can surprise you during testing.
The fifth mistake is confusing legal compliance with checkout visibility. Hiding a payment gateway may support your operational policy, but it is not a complete legal, tax, or trade compliance solution. If your store has regulated products, restricted territories, or tax obligations, the payment rule is only one piece of the system.
Maintaining the rule as the store grows
A WooCommerce payment gateway restriction should be documented somewhere your team can find it. Not in a long forgotten chat thread. Not only inside a developer’s memory. Add a short note in your internal store documentation that says which gateway is restricted, which countries are affected, where the rule lives, and why it exists.
For example:
- “Cash on delivery is available only for
USbilling/shipping because our courier collection agreement is domestic.” - “Bank transfer is disabled for
CAandAUbecause manual reconciliation created support delays.” - “Local wallet gateway is enabled only for
NLbecause the provider supports Dutch customers only.”
That tiny note prevents future confusion. If a support person receives a message saying “PayPal is missing,” they can check whether the customer’s billing country is part of the rule before escalating it as a bug.
When you add a new payment plugin, revisit the restriction. Some gateway plugins introduce multiple methods. Others replace an old gateway ID with a new one. After major WooCommerce or payment plugin updates, run a quick checkout test for your restricted countries.
This is also a good moment to keep the rule narrow. If one gateway is the problem, hide that gateway. Do not block an entire country from checkout unless that is truly the business decision.
The cleanest path for most stores
If you need one or two stable rules and you are comfortable maintaining a small snippet, use woocommerce_available_payment_gateways with WC()->customer->get_billing_country(). Put the code in a child theme or site-specific plugin, use ISO two-letter country codes, and remove the correct gateway ID from the available gateways array.
If your rules are more complex, or if non-developers need to manage them, use a conditional payments plugin and configure the country restrictions in the WooCommerce admin panel. The result should be the same from the customer’s point of view: only the payment methods that make sense for their billing country appear at checkout.
What we have built is a quieter checkout. Fewer wrong options. Fewer manual corrections. Fewer support conversations that begin with “I chose this payment method, but now my order cannot be processed.” From here, the next useful step is to test the same logic against your shipping zones, checkout fields, and any express payment buttons, so the entire purchase path follows one clear regional policy.