Usama Siddiqui
Forum Replies Created
-
Forum: Plugins
In reply to: [WooCommerce] PayPal Standard redirects to Paypal homepageI am getting the same problem…. It was working fine before. Kindly suggest if anyone has find the way to fix it. Thanks
Forum: Plugins
In reply to: [2Checkout Payment Gateway for WooCommerce] CurrencyHi,
The problem is that 2co does not support my local currency but my store currency has to be local, the simple way out is to convert the unsupported currency into supported currency at the time of checkout. Is there is any way out ? to convert PKR (store Currency) to USD at checkout?i tried the following code but still its only converting PKR symbol to USD symbol the amount isn’t converting.
Code in function.php :
add_filter( ‘woocommerce_currencies’, ‘add_pkr_currency’ );function add_pkr_currency( $currencies ) {
$currencies[‘PKR’] = __( ‘Pakistani Rupee’, ‘woocommerce’ );
return $currencies;
}add_filter(‘woocommerce_currency_symbol’, ‘add_pkr_currency_symbol’, 10, 2);
function add_pkr_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case ‘PKR’: $currency_symbol = ‘PKR’; break;
}
return $currency_symbol;
}/*conversion for 2checkout:*/
add_filter( ‘woocommerce_twoco_supported_currencies’, ‘add_pkr_twoco_valid_currency’ );
function add_pkr_twoco_valid_currency( $currencies ) {
array_push ( $currencies , ‘PKR’ );
return $currencies;
}
/*Step 3 – Code to change ‘PKR’ currency to ‘USD’ before checking out with 2co through Woocommerce:*/add_filter(‘woocommerce_twoco_args’, ‘convert_pkr_to_usd’);
function get_currency($from_Currency=’USD’, $to_Currency=’PKR’) {
$url = “https://www.google.com/finance/converter?a=1&from=$from_Currency&to=$to_Currency”;$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt ($ch, CURLOPT_USERAGENT,
“Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)”);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$rawdata = curl_exec($ch);
curl_close($ch);
$data = explode(‘bld>’, $rawdata);
$data = explode($to_Currency, $data[1]);return round($data[0], 2);
}function convert_pkr_to_usd($twoco_args){
if ( $twoco_args[‘currency_code’] == ‘PKR’){
$convert_rate = get_currency(); //Set converting rate
$twoco_args[‘currency_code’] = ‘USD’; //change PKR to USD
$i = 1;while (isset($twoco_args[‘amount_’ . $i])) {
$twoco_args[‘amount_’ . $i] = round( $twoco_args[‘amount_’ . $i] / $convert_rate, 2);
++$i;
}if ( $twoco_args[‘discount_amount_cart’] > 0 ) {
$twoco_args[‘discount_amount_cart’] = round( $twoco_args[‘discount_amount_cart’] / $convert_rate, 2);
}
}return $twoco_args;
}