in

Easily Hide WooCommerce Payment Methods by Billing Country with This Simple Snippet

Want to control which payment options customers see? This simple WooCommerce snippet hides selected gateways based on the billing country entered at checkout. Learn how WooCommerce identifies that country, where to add the code safely, and how to test and customize your rules for multiple countries and payment methods.

Need to offer different payment options to customers in different countries? WooCommerce makes it possible to tailor checkout, and a small snippet can help you control which gateways shoppers see based on their billing address.

In this guide, you’ll learn how to use WooCommerce hide payment method by billing country code to hide selected payment methods for specific countries. It’s a simple way to make checkout more relevant for your customers while keeping your payment options organized.

How WooCommerce Hide Payment Method by Billing Country Works

Checkout is more than a final confirmation screen: WooCommerce can refresh its available payment options as a customer enters an address. Understanding when that happens—and which country value is used—makes it easier to see why a country-based snippet works.

What the snippet checks during checkout

A typical snippet hooks into WooCommerce’s woocommerceavailablepaymentgateways filter. This filter runs when WooCommerce builds the list of available gateways, giving the code a chance to remove selected methods before they appear at checkout.

The code compares the customer’s billing-country code with the conditions you set, then checks the gateway’s internal ID. For example, you might hide a particular gateway for customers billing from the United States while leaving other methods available. Keep in mind:

  • Use a gateway’s technical ID, not necessarily the label shoppers see.
  • Remove only the gateways you intend to restrict; the rest remain available.
  • The snippet affects checkout availability, not the gateway’s settings or the customer’s ability to pay through other channels.

Because checkout can refresh dynamically when address details change, the callback may run more than once during a purchase. That helps keep the displayed options in sync with the latest billing information.

That comparison depends on WooCommerce having a country value to work with. The important detail is that billing and shipping addresses are separate, so a rule based on billing country follows the billing field specifically.

How WooCommerce identifies a customer’s billing country

WooCommerce stores a customer’s billing country as a two-letter country code, such as US, GB, or CA. A snippet can read this value from the current customer object, commonly with WC()->customer->getbillingcountry().

For a returning customer, the value may already be saved in their account. A guest can enter it during checkout; when the address is updated, WooCommerce refreshes checkout data and the payment-method list can be recalculated. If the billing country is still blank, a well-planned rule should avoid hiding gateways unexpectedly until a usable country code is available.

  • Billing country determines which country-based condition the snippet evaluates.
  • Shipping country does not replace it unless the code is specifically written to check shipping details.
  • Country codes should match WooCommerce’s stored values, rather than full country names.

This distinction is useful when a customer is buying a gift or shipping to another country: the rule can still follow the billing address, as intended.

Add the Country-Based Payment Method Snippet

Once you’ve chosen which checkout options should appear in each market, the next step is putting that rule into practice. A small, targeted snippet can do the job without changing a gateway’s settings for every customer.

Before adding code, decide which gateway IDs and country codes you’ll use. These choices determine exactly when the filter removes a payment option.

Choose the payment methods and countries to target

Start with the countries where a payment method should be unavailable, then identify the gateway’s technical ID. The ID may differ from the friendly name shown to shoppers.

You can usually find gateway IDs in WooCommerce’s payment settings or by checking the gateway’s documentation. For instance, the built-in Cash on Delivery gateway commonly uses cod, while direct bank transfer commonly uses bacs. Confirm the ID on your own site, especially if you use a third-party gateway.

Use WooCommerce’s two-letter country codes, such as US or CA. Keep a short list of your intended rules before coding; it makes the result easier to review later.

With those details in hand, choose a place for the snippet that won’t be overwritten during routine updates. A staging site is also a good place to check the behavior before customers encounter it.

Where to add the code safely

A snippets manager or your child theme’s functions.php file is generally safer than editing a parent theme. If you use a snippets plugin, follow its instructions about whether to include the opening PHP tag.

Back up your site before making changes, and test checkout with billing addresses from both targeted and unaffected countries. Also verify the result with your checkout type and payment extensions, since custom checkout setups can handle gateways differently.

Here’s a basic example of the WooCommerce hide payment method by billing country approach. It hides Cash on Delivery for US billing addresses and leaves other gateways untouched.

Example snippet to hide payment methods by billing country

The callback reads the billing country, checks that a country is available, and removes the selected gateway only when the condition matches. If the billing country is blank, it makes no changes.

addfilter( 'woocommerceavailablepaymentgateways', 'myhidegatewaybybillingcountry' );
function myhidegatewaybybillingcountry( $availablegateways ) {
    if ( ! functionexists( 'WC' ) || ! WC()->customer ) {
        return $availablegateways;
    }
    $country = WC()->customer->getbillingcountry();
    if ( 'US' === $country && isset( $availablegateways['cod'] ) ) {
        unset( $availablegateways['cod'] );
    }
    return $availablegateways;
}

For a broader reference to WooCommerce’s gateway filtering, see its code reference for hooks.

As your rules grow, grouping them in one place helps prevent scattered conditions and makes future edits simpler. You can map each country to one or more gateway IDs.

Customize the snippet for multiple countries or gateways

For example, replace the single condition with a rules array such as ['US' => ['cod'], 'CA' => ['bacs', 'cod']]. Loop through the gateway IDs assigned to the matching country and unset each one only if it exists in $availablegateways.

Keep country codes and gateway IDs consistent, and test every rule after editing. That way, adding a new market won’t accidentally remove a payment option from customers elsewhere.

Test and Troubleshoot Your Checkout Settings

A rule can look correct in the code and still behave differently once a shopper changes their address or uses a different checkout layout. A few focused tests will help confirm that the right options appear for each customer before the change goes live.

Start by checking the country conditions themselves, then move on to gateway IDs and compatibility if anything looks off.

Testing a small set of billing addresses can reveal whether each country rule works as intended. Include both countries where a method should be hidden and countries where it should remain available.

Verify the rules for each billing country

Use a private browser window or a guest checkout session to avoid relying on saved account details. Change the billing country and let checkout refresh before reviewing the available payment methods.

Check a simple test matrix, including the blank-country case, so you can confirm the snippet does not remove a gateway before WooCommerce has a usable billing value.

  • Targeted country: confirm the selected gateway is absent.
  • Unaffected country: confirm that gateway and other methods remain available.
  • Different shipping country: confirm the rule still follows billing country.
  • Blank billing country: confirm the snippet leaves the gateway list unchanged.

If possible, place a test order using your payment provider’s test mode. This checks not only what appears on screen, but also whether the remaining method completes checkout correctly.

If a result does not match the matrix, check the values the code actually compares. A label such as “Cash on delivery” is not a substitute for the gateway’s technical ID.

Fix common issues with hidden payment methods

When a method remains visible, first verify the country code and gateway ID against your store’s configuration. A spelling mismatch or a plugin-specific ID can prevent the condition from matching.

If methods disappear for every country, review the condition and make sure the callback returns $available_gateways in all cases. Also check that the snippet is active and has no PHP errors; your host or debugging tools may record errors in a log.

Checkout caching can also show stale options. Exclude checkout-related pages from caching, then retest in a fresh session. Avoid sharing logs that contain customer or payment details.

Even a correct rule depends on how the store handles checkout and payment integrations. Confirm compatibility in the setup your customers actually use, especially after WooCommerce or gateway updates.

Keep the snippet compatible with your WooCommerce setup

Test the rule with your active checkout type, theme, and payment extensions. The classic checkout and Checkout Block can use different integration paths, so verify the behavior rather than assuming a filter works identically in both.

After updates, repeat the country test matrix and check the gateway provider’s compatibility notes. WooCommerce’s Cart and Checkout Blocks documentation can help you identify considerations for block-based checkout.

Keep the snippet in a maintainable location, document each country-to-gateway rule, and retest after changing payment plugins. That makes future edits easier—and helps keep checkout predictable for shoppers.

Make Checkout More Relevant for Every Market

Hiding payment methods by billing country gives you a straightforward way to tailor WooCommerce checkout without changing the options available to everyone. The key is to match the customer’s billing-country code with the correct gateway ID, then keep those rules organized as your needs grow.

Add the snippet in a maintainable place, and test both targeted and unaffected countries—including how your checkout behaves with its active theme and payment extensions. A little testing helps catch mismatches or compatibility issues before they affect customers.

With clear rules and occasional checks after updates, you can keep checkout focused, predictable, and better suited to the markets you serve.

Leave a Reply

Your email address will not be published. Required fields are marked *

      Written by Maeve Rodriguez

      Maeve is a Business Content Writer and Front-End Developer. She's a versatile professional with a talent for captivating writing and eye-catching design.