Filter Payment Methods by Currency
Not all payment methods support every currency. PayPal, for instance, has specific currency limitations, and you might find yourself in a situation where your WooCommerce store accepts a currency that one of your payment gateways doesn't support. Rather than confusing customers with payment methods that will ultimately fail, you can programmatically hide incompatible payment options based on your store's currency settings.
This approach ensures customers only see payment methods that will actually work with their selected currency, creating a smoother checkout experience and reducing payment failures. When your store currency doesn't match a payment gateway's supported currencies, that gateway simply won't appear as an option.
When would you use this?
Filtering payment methods by currency is essential for merchants operating in multiple currencies or using currencies that aren't universally supported by all payment processors. You might be running a store that serves international customers with various local currencies, or perhaps you've added a regional currency that only some of your payment gateways can handle.
Common use cases include hiding PayPal for currencies it doesn't support (like certain African or Asian currencies), removing specific payment methods when operating in sanctioned countries, or ensuring compliance with regional payment regulations by only showing appropriate local payment options.
The Code
This example removes PayPal as a payment option when the store currency is set to Singapore Dollar (SGD). Even though PayPal supports SGD, a merchant might choose not to offer PayPal for SGD transactions due to business preferences, regional payment habits, or strategic partnerships with local payment providers. Add this code to your theme's functions.php
file or a custom plugin:
add_filter('woocommerce_available_payment_gateways', function($gateways){
if(is_checkout() || is_cart()){
if(get_woocommerce_currency() === 'SGD'){
unset($gateways['ppcp']);
}
}
return $gateways;
});
How the Code Works
The code hooks into WooCommerce's woocommerce_available_payment_gateways
filter, which runs every time WooCommerce determines which payment methods to show the customer. First, it checks if the current page is either the checkout or cart page using is_checkout()
and is_cart()
functions - this ensures the filter only runs where payment methods are actually displayed.
Next, it retrieves the store's base currency using get_woocommerce_currency()
, which returns the three-letter currency code set in your WooCommerce currency settings. If the currency matches 'SGD' (Singapore Dollar), the code removes the PayPal gateway by unsetting $gateways['ppcp']
from the available gateways array.
The gateway identifier ppcp
specifically targets the Payment Plugins for PayPal WooCommerce plugin's main PayPal payment method. You can replace this with any gateway ID to filter different payment methods based on currency compatibility.
Filtering Multiple Currencies
You can remove PayPal for multiple currencies where you prefer alternative payment methods:
add_filter('woocommerce_available_payment_gateways', function($gateways){
if(is_checkout() || is_cart()){
$excluded_currencies = ['SGD', 'HKD', 'MYR', 'THB'];
if(in_array(get_woocommerce_currency(), $excluded_currencies)){
unset($gateways['ppcp']);
}
}
return $gateways;
});
Showing Payment Methods for Specific Currencies Only
You can also reverse the logic to only show PayPal for your preferred currencies:
add_filter('woocommerce_available_payment_gateways', function($gateways){
if(is_checkout() || is_cart()){
$preferred_currencies = ['USD', 'EUR', 'GBP', 'CAD', 'AUD'];
if(!in_array(get_woocommerce_currency(), $preferred_currencies)){
unset($gateways['ppcp']);
}
}
return $gateways;
});
Filtering Multiple Payment Methods
Different payment gateways may have different regional preferences. You can create more complex filtering by removing different gateways based on your business strategy:
add_filter('woocommerce_available_payment_gateways', function($gateways){
if(is_checkout() || is_cart()){
$currency = get_woocommerce_currency();
// Remove PayPal for Asian currencies where you prefer local options
$paypal_excluded = ['SGD', 'HKD', 'MYR'];
if(in_array($currency, $paypal_excluded)){
unset($gateways['ppcp']);
unset($gateways['ppcp_cc']);
}
// Remove Stripe for currencies where you have better local alternatives
$stripe_excluded = ['INR', 'JPY'];
if(in_array($currency, $stripe_excluded)){
unset($gateways['stripe']);
}
}
return $gateways;
});
Important Considerations
Always research your business requirements and customer preferences before implementing currency-based filtering. Even if a payment processor supports a particular currency, you might have strategic reasons to prefer alternative payment methods for specific regions or currencies.
Remember that filtering payment methods affects the customer experience significantly. If you remove all payment methods for a particular currency, customers won't be able to complete their purchase. Always ensure at least one payment method remains available for every currency your store supports.
Testing Your Implementation
To verify the code is working correctly, temporarily change your WooCommerce currency settings to the filtered currency (like SGD in our example) and visit your checkout page. The targeted payment method should not appear in the available options.
Make sure to test with multiple currencies if you're filtering based on an array of currencies. Also verify that payment methods appear normally when using supported currencies.