FOX - Currency Switcher for WooCommerce

How to Hide a Payment Gateway by Currency at Checkout

Not every payment gateway can settle in every currency. Hiding the ones that cannot is what keeps a multi currency checkout from ending in a failed payment.

Sometimes it is necessary hide payment gate on the checkout page in multiple mode dependently of the current currency. From version 2.2.7/1.1.7 use options in tab "Payments Rules" of the plugin settings page:
From version 2.1.4/1.1.4 additional css class implemented in tag <body>. Example: currency-usd,  where usd there is the current currency. So it is very easy from now to hide any gates on checkout by your logic just using CSS.
Way with code-> in your site current wp theme functions.php file add next PHP script:
add_filter('woocommerce_available_payment_gateways', 'woocs_filter_gateways', 1);

function woocs_filter_gateways($gateway_list)
{
    global $WOOCS;
    $exclude = array(
        'paypal' => array('EUR', 'GBP'), //do not show paypal gate if current currency is EUR or GBP
        'stripe' => array('USD')//do not show stripe gate if current currency is USD
    );
    //***
    foreach ($exclude as $gateway_key => $currencies)
    {
        if (isset($gateway_list[$gateway_key]) AND in_array($WOOCS->current_currency, $currencies))
        {
            unset($gateway_list[$gateway_key]);
        }
    }

    return $gateway_list;
}

More examples:

  • add_filter('woocommerce_available_payment_gateways', 'woocs_filter_gateways', 1);
     
    function woocs_filter_gateways($gateway_list)
    {
        if (WC()->cart->subtotal > 1000)
        {
            unset($gateway_list['cod']);
        }
     
        return $gateway_list;
    }
  • _