php - Filter currency in wocoommerce and convert it from usd to inr for ccavenue -
i using ccavenue payment gateway on wordpress site.
plugin url https://wordpress.org/plugins/ccavenue-payment-gateway-woocommerce/
having 1 issue base currency inr , ccavenue accepts payment in inr only, when user switch currency usd ccavenue taking $40 inr40.
want convert currency before getting ccavenue page.
code snippet same is.
public function generate_ccavenue_form($order_id){ global $woocommerce; $order = new wc_order($order_id); $redirect_url = ($this -> redirect_page_id=="" || $this -> redirect_page_id==0)?get_site_url() . "/":get_permalink($this -> redirect_page_id); //for woocoomerce 2.0 $redirect_url = add_query_arg( 'wc-api', get_class( $this ), $redirect_url ); $order_id = $order_id.'_'.date("ymds"); $checksum = $this -> getchecksum($this -> merchant_id, $order->order_total, $order_id, $redirect_url, $this -> working_key); $ccavenue_args = array( 'merchant_id' => $this -> merchant_id, 'amount' => $order->order_total, 'order_id' => $order_id, 'redirect_url' => $redirect_url, 'checksum' => $checksum, 'currency_code' => get_woocommerce_currency(), 'billing_cust_name' => $order -> billing_first_name .' '. $order -> billing_last_name, 'billing_cust_address' => $order -> billing_address_1, 'billing_cust_country' => $order -> billing_country, 'billing_cust_state' => $order -> billing_state, 'billing_cust_city' => $order -> billing_city, 'billing_zip' => $order -> shipping_postcode, 'billing_cust_tel' => $order -> billing_phone, 'billing_cust_email' => $order -> billing_email, 'delivery_cust_name' => $order -> shipping_first_name .' '. $order -> shipping_last_name, 'delivery_cust_address' => $order -> shipping_address_1, 'delivery_cust_country' => $order -> shipping_country, 'delivery_cust_state' => $order -> shipping_state, 'delivery_cust_tel' => $order -> shipping_phone, 'delivery_cust_notes' => '', 'merchant_param' => '', 'billing_zip_code' => $order -> billing_postcode, 'delivery_cust_city' => $order -> shipping_city, 'delivery_zip_code' => $order -> shipping_postcode ); $ccavenue_args_array = array(); foreach($ccavenue_args $key => $value){ $ccavenue_args_array[] = "<input type='hidden' name='$key' value='$value'/>"; }
i think have add filter hook in function.php. not able made , add filter this.
you can use google api currency convert.
you have put custom functions convert currency real time in woocommcerce, ccavenue has no support inr have first convert usd , send variable amount ccavenue form.
add below code functions.php appropriate action want.
<?php $from_currency = 'usd'; $to_currency = 'inr'; $amount = 1; $results = convercurrency($from_currency,$to_currency,$amount); $regularexpression = '#\<span class=bld\>(.+?)\<\/span\>#s'; preg_match($regularexpression, $results, $finaldata); echo $finaldata[0]; function convercurrency($from,$to,$amount){ $url = "http://www.google.com/finance/converter?a=$amount&from=$from&to=$to"; $request = curl_init(); $timeout = 0; curl_setopt ($request, curlopt_url, $url); curl_setopt ($request, curlopt_returntransfer, 1); curl_setopt ($request, curlopt_useragent,"mozilla/4.0 (compatible; msie 8.0; windows nt 6.1)"); curl_setopt ($request, curlopt_connecttimeout, $timeout); $response = curl_exec($request); curl_close($request); return $response; } ?>
hope helps you. please vote if works. in advance vote up.
Comments
Post a Comment