Last active
November 9, 2017 12:49
-
-
Save vikas5914/a13181b0647c2f911d2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('woocommerce_paypal_supported_currencies', 'add_aed_paypal_valid_currency'); | |
function add_aed_paypal_valid_currency($currencies) | |
{ | |
array_push($currencies, 'INR'); /* YOUR CURRENCY */ | |
return $currencies; | |
} | |
add_filter('woocommerce_paypal_args', 'woocommerce_paypal_args_for_inr'); | |
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++; | |
} | |
if (isset($paypal_args['tax_cart'])) { | |
$paypal_args['tax_cart'] = round($paypal_args['tax_cart'] / $convert_rate, 2); | |
} | |
if (isset($paypal_args['shipping_1'])) { | |
$paypal_args['shipping_1'] = round($paypal_args['shipping_1'] / $convert_rate, 2); | |
} | |
if (isset($paypal_args['currency_code'])) { | |
$paypal_args['currency_code'] = 'USD'; | |
} | |
} | |
return $paypal_args; | |
} | |
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]; | |
} |
Updated to work with Woocommerce 3.2.3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PayPal payment not working for new update of Woocommerce 3.1.2