# Hide a Payment Method for Certain Countries

> Removes a payment method from checkout when the customer's billing country is on your list, for example to offer cash on delivery only at home.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, payments, checkout, countries
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-hide-gateway-by-country/

## Code

```php
add_filter( 'woocommerce_available_payment_gateways', function ( $gateways ) {
    $gateway   = 'cod';                // Payment method ID to hide.
    $countries = array( 'CA', 'MX' );  // Billing countries where it is hidden.

    if ( is_admin() || ! WC()->customer || ! isset( $gateways[ $gateway ] ) ) {
        return $gateways;
    }

    if ( in_array( WC()->customer->get_billing_country(), $countries, true ) ) {
        unset( $gateways[ $gateway ] );
    }

    return $gateways;
} );
```

## Notes

Set $gateway to the payment method ID and list two-letter country codes in $countries.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Hide a Payment Method for Certain Countries" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
