The commerce (kickstart) site has default prices in USD. Site should convert the price to local currency for international visitors, based off IP or other means.


Widget Price - $2 (USD).

Australians see: A$2.15

Canadians see: C$2.18

Japanese see: ¥204.70

So the functions needed are

  1. Detect country from IP
  2. Lookup visitor's currency
  3. Lookup conversion rate from USD
  4. Convert + format price
  5. Display wherever price field is called.

There doesn't seem to be a single module to do this (I wish there is!) and bits and pieces of advice here and there which involve rules etc, which I'm not familiar with.

I hope I can find a guru here who can show the way. Thanks!

  • Take a look at this Sandbox project, maybe it would work well for you...
    – mixerowsky
    Aug 17, 2014 at 13:08
  • Thanks for the suggestion. It doesn't do conversion though, just formatting only, and it's a sandbox module which I'm hesitant to use on production. If there's no other choice I'd try to hacking the module to add on the functionality I need - it's most of the way there already. Also I think this is a valid answer too, why don't you post it as an answer, might help someone else later ;)
    – a20
    Aug 17, 2014 at 16:16

2 Answers 2


I don't think there is any module provides this functionality.. The best way is to use some third party services to get data and display it..

I'd do such things to acheive this:

  • get user ip by ip_address()`
  • get user info by this service: http://www.geoplugin.net.

here is an example:

$countryInfo = drupal_http_request('http://www.geoplugin.net/json.gp?ip=' . $user_ip);
$countryInfoData = json_decode($countryInfo->data);
$userCurrencyCode = $countryInfoData->geoplugin_currencyCode;
  • and use google converter to get result:

some sample code:

  $amount = urlencode($amount);
  $from_Currency = urlencode($from_Currency);
  $to_Currency = urlencode($userCurrencyCode);
  $get = file_get_contents('https://www.google.com/finance/converter?a=' . $amount . '&from=' . $from_Currency . '&to=' . $to_Currency);
  $get = explode("<span class=bld>",$get);
  $get = explode("</span>",$get[1]);  
  $converted_amount = preg_replace("/[^0-9\.]/", null, $get[0]);

this piece of code's gotten from this post :)

and, so, it's up to you to display the results...

I don't think this is a real solution to your problem and also I can't guarantee this will work:) .. but you can play around it to find better solution..

  • Hey I like your suggestion, would you mind elaborating why it's not a real solution or can't be guaranteed to work? If nothing else, I might go down this path, so more info would be great :)
    – a20
    Aug 17, 2014 at 16:20
  • @a20 I don't have any working drupal project at this time to test it or create module for it, that's why said that I can't guarentee.. But you can try to test this solution (it can be done maximum in 1 hour:))
    – xurshid29
    Aug 17, 2014 at 16:31

Yes you can do it with modules, I did.

Using a conbination of rules, commerce_multicurrency https://www.drupal.org/project/commerce_multicurrency and smartip https://www.drupal.org/project/smart_ip.

  1. Activate the modules.
  2. Configure smart_ip external service in /admin/config/people/smart_ip FYI https://IPInfoDB.com free version worked right away for me (you need to register and get an API key though).
  3. Go to /admin/commerce/config/currency choose your default currency and activate the currencies you need.
  4. Got to /admin/commerce/config/currency/handling add the currencies you want to the products types you want (but don't add the default currency).
  5. Now to /admin/commerce/config/product-pricing you need to create the rules that will convert the price for each currencies. Here is an exported example rules that convert a price in USD if the user IP is from the US:

    { "rules_set_price_in_usd" : { "LABEL" : "Set price in USD", "PLUGIN" : "reaction rule", "OWNER" : "rules", "TAGS" : [ "price conversion" ], "REQUIRES" : [ "smart_ip", "commerce_multicurrency", "rules", "commerce_product_reference" ], "ON" : { "commerce_product_calculate_sell_price" : [] }, "IF" : [ { "smart_ip_condition_in_country" : { "country" : { "value" : { "US" : "US" } } } } ], "DO" : [ { "commerce_multicurrency_set_user_currency_code" : { "currency_code" : "USD" } }, { "component_commerce_multicurrency_use_usd" : { "commerce_line_item" : [ "commerce_line_item" ] } } ] } }

Once the rules for each currencies have been established, you only have to go to each products and enter the prices (use the price field four your default currency, and the dedicated fields for the others).

You may use the debug mode in /admin/config/people/smart_ip to make tests.

  • Back in 2014, when I asked the question, I couldn't find a solution. I also eventually found Drupal to be bloated, slow and expensive (dev time spent) and moved away. Good luck to you. I hope Drupal is better but I doubt it. It's not easy to change the direction of air-craft carrier.
    – a20
    Jan 29, 2019 at 4:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.