How to do *USD to INR* currency conversion on-the-fly? - WooCommerce How to do *USD to INR* currency conversion on-the-fly? - WooCommerce wordpress wordpress

How to do *USD to INR* currency conversion on-the-fly? - WooCommerce


Use a currency conversion API provided by a third party agency and wrap it into wordpress function.

open exchange rates

XE Datafeed

Please see the below example code using the google finance API.

//get the exchange rate from google financefunction get_exchange_rate($from='USD', $to='INR') {    $url = "http://www.google.com/ig/calculator?hl=en&q=1%s=?%s";   //url for the currency convertor    $result = wp_remote_retrieve_body($response = wp_remote_get(sprintf($url, $from, $to))); // fetches the result from the url    if(is_wp_error( $response )) {        return FALSE;    }    $result = explode('"',$result);    $result = str_replace(chr(160), '', substr( $result[3], 0, strpos($result[3], ' ') ) );    return ( $result == 0 ) ? FALSE : $result;}