How to Add Custom Currency and Conversion Rate in WooCommerce

April 20, 2016

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:



You May Also Like…


Submit a Comment

Your email address will not be published.