Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author RealMag777

    (@realmag777)

    First off, great plugin.

    Anyway, I anticipated some problems when hiding the gateway via CSS, the radio button of the hidden gateway is present but not visible. It is still possible to select the hidden gateway, without even knowing.

    Sticking this in the functions.php may be more foolproof.

    add_filter( 'woocommerce_available_payment_gateways', 'gateway_filter', 1);
    function gateway_filter( $gateway_list )
    {
      global $woocommerce;
      global $WOOCS;
    
      if ( isset( $gateway_list['paypal'] ) && $WOOCS->current_currency <> 'EUR' )
      {
        unset(  $gateway_list['paypal'] );
      }
    
      return $gateway_list;
    }

    Critiques/improvements would be welcome.

    Plugin Author RealMag777

    (@realmag777)

    @histersis

    Hello

    With CSS it is the simplest way, but your idea is the best!

    I changed your script a little:

    add_filter('woocommerce_available_payment_gateways', 'woocs_filtere_gateway', 1);
    
    function woocs_filtere_gateway($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;
    }

    https://currency-switcher.com/how-to-hide-payment-gateway-on-checkout/

    Thank you for idea!

    del

    • This reply was modified 7 years, 10 months ago by ADvi.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Switch payment gateway when currency switched’ is closed to new replies.