212015Feb

Solved : Woocommerce Paypal Support For INR

Gateway Disabled: PayPal does not support your store currency.

When we change the currency to INR as store currency in Woocommerce settings then it will result in an error on woocommerce paypal page like this.

Paypal Error

Reason
The reason is quite simple because Paypal does not support Indian Currency and you can check in list of supported currencies by paypal.

Solution(Updated)
The solution is also quite simple. To remove this error add the following code snippet in theme functions.php.

add_filter( 'woocommerce_paypal_supported_currencies', 'add_paypal_valid_currency' ); 

function add_paypal_valid_currency( $currencies ) { 
     array_push ( $currencies , 'INR' ); /* YOUR CURRENCY */
     return $currencies; 
}

After adding INR go to paypal setting page in woocommerce plugin and you will see error is gone.

So are we done with it ????????? NO.

The Real Thing
We have just modified the woocommerce plugin to remove the error from paypal setting page. Paypal still does not support Indian Currency and we can’t also make paypal to support Indian Currency. In simple words Your online store support INR and payapl doesn’t.. The Hook Is We have to convert currency before redirecting to paypal. To do this got to your theme’s function.php file and add the below code.

Check How To Open Contact Form 7 in Pop Up in WordPress

function woocommerce_paypal_args_for_inr($paypal_args){
    if ( $paypal_args['currency_code'] == 'INR'){
		
        $convert_rate = getFromYahoo(); 

        $count = 1;
        while( isset($paypal_args['amount_' . $count]) ){
            $paypal_args['amount_' . $count] = round( $paypal_args['amount_' . $count] / $convert_rate, 2);
            $count++;
        }
	$paypal_args['tax_cart'] = round( $paypal_args['tax_cart'] / $convert_rate, 2);
    }
    return $paypal_args;
}
add_filter('woocommerce_paypal_args', 'woocommerce_paypal_args_for_inr');

function getFromYahoo()
{
	$from   = 'USD'; /*change it to your required currencies */
	$to     = 'INR';
	$url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='. $from . $to .'=X';
	$handle = @fopen($url, 'r');
	 
	if ($handle) {
		$result = fgets($handle, 4096);
		fclose($handle);
	}
	$allData = explode(',',$result); /* Get all the contents to an array */
	return $allData[1];
}

The Logic

  • First we are getting all Paypal arguments before redirecting to Paypal by using “woocommerce_paypal_args” hook.
  • After that we are fetching current INR Rate In USD using Yahoo API.
  • After getting conversion rate we are modifying the Paypal Arguments according to USD value.
  • Now all done and returning.

Note:- No support for this post as this is an old post and it’s been long time I worked on paypal. Sorry, if it doesn’t work as things might have changed.