Search code examples
wordpresswoocommercepayment-gateway

Hide payment methods in Woocommerce, according to selected currency


On the checkout page, we've a currency switcher for USD, EUR, INR, GBP currencies.

However, out of 3, only 1 gateway supports all currencies, & 2 supports INR.

So, I need to hide other two gateways, if someone selects USD, EUR & GBP

Can we use selected currency & do the needed function?

TIA


Solution

  • Okay. found a solution. Giving details below, if anyone stumbles here.

    The "WooCommerce Currency Switcher" plugin changes the shop currency & stores using session / transient method. Not just that, it also adds a body class for each selected currency.

    e.g.: currency-usd or currency-eur or currency-gbp

    This is what is possible simply using CSS

    .currency-usd .payment_method_instamojo, .currency-usd .payment_method_paynimo, .currency-eur .payment_method_instamojo, .currency-eur .payment_method_paynimo, .currency-gbp .payment_method_instamojo, .currency-gbp .payment_method_paynimo {display:none}

    This works as expected w/o writing a separate function. Hope this helps.