0

I am displaying a price for a product in USD dollars as default, this never changes so I know that it is always in USD.

I need to convert that price including the currency symbol to the user's browsers locale, this means that if that user lives in Israel, and then moves with his computer to USA, the price will still display in Israeli New Shekel.

Is there a way to do such thing that does not base the currency off the user's country by IP?

Shiladitya
  • 12,003
  • 15
  • 25
  • 38
Ben Beri
  • 1,101
  • 4
  • 23
  • 64
  • JS won't provide you with the locale currency symbol or the "USD to locale currency" conversion rates. That you'd would to arrange yourself or use some 3rd party. The formatting of price and currency can be done though. See: https://stackoverflow.com/a/33561563/2652134 – Brahma Dev Oct 14 '17 at 21:01

1 Answers1

0

You can use geoplugin library from here geoplugin.com

and do something like following code:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script language="JavaScript" src="http://www.geoplugin.net/javascript.gp" type="text/javascript"></script>

$(document).ready(function () {
    var currencyCode = geoplugin_currencyCode();
});
Farhad Bagherlo
  • 6,725
  • 3
  • 25
  • 47