How to Add Custom Currency and Conversion Rate in WooCommerce

Recently We have developed an WooCommerce store where we needed to use store currency as Indonesia Rupiah. Though the currency is in the list but when we tried to activate Paypal checkout, we saw an error appeared “Gateway Disabled: PayPal does not support your store currency“.  So we had to add custom currency and conversion rate in WooCommerce to resolve this issue. Lets see how you can do this.

At first If we don’t find the desired currency in the drop down list in WooCommerce, then we need to add it and it’s unit as follows:

add_filter( ‘woocommerce_currencies’, ‘add_inr_currency’ ); add_filter( ‘woocommerce_currency_symbol’, ‘add_inr_currency_symbol’ ); function add_inr_currency( $currencies ) { $currencies[‘IDR’] = ‘Indonesia Rupiah’; return $currencies; } function add_inr_currency_symbol( $symbol ) { $currency = get_option( ‘woocommerce_currency’ ); switch( $currency ) { case ‘IDR’: $symbol = ‘Rp ‘; break; } return $symbol; }

In here IDR is the universal symbol for  Indonesia Rupiah. Next we have to add IDR to paypal valid currencies array:

add_filter( ‘woocommerce_paypal_supported_currencies’, ‘add_bgn_paypal_valid_currency’ ); function add_bgn_paypal_valid_currency( $currencies ) { array_push ( $currencies , ‘IDR’ ); return $currencies; }

Finally we need to convert the amount to Paypal supported currency. We have converted it to USD as follows:

add_filter(‘woocommerce_paypal_args’, ‘convert_bgn_to_usd’); function convert_bgn_to_usd($paypal_args){ if ( $paypal_args[‘currency_code’] == ‘IDR’){ $convert_rate = 13125; //set the converting rate $paypal_args[‘currency_code’] = ‘USD’; $i = 1; while (isset($paypal_args[‘amount_’ . $i])) { $paypal_args[‘amount_’ . $i] = round( $paypal_args[‘amount_’ . $i] / $convert_rate, 2); ++$i; } } return $paypal_args; }

where we set the conversion rate 13125. And here is the outcome:



Author: mytutorialguru

Share This Post On

1 Comment

  1. Great Guys! thanks!! but, may i ask, where exactly do i add that lines??? my currency does appear and my country´s symbol is universal symbol for money, so whats lef for me to do is to add the convertion to USD? if that is in the case, where to add the code is my question.
    Thanks great tips by the way!!

    Post a Reply

Submit a Comment

Your email address will not be published. Required fields are marked *