We have an app that renders a widget on stores and has to show the price of the currently viewed product. The issue is that we show the price in wrong format as we don’t localize the price.
Here are some options I tried:
There is a meta tag in the DOM which has a localized price. Eg. on an European store (comma means decimal) → . This was perfect solution until I realized that it always shows the product price, not the current variant price.
There is a native JS function to get localized formatted currency, but that requires the locale. And we don’t have the locale info on the shopify store website.
Is there a way to the store’s locale in JavaScript?
@EphraimMulilo I tried, but it only gives values like “en”, “de” etc. Whereas any locale function in JavaScript or elsewhere accepts full locale as “en-US”, “ar-EG” etc.
@kushagrapushowl Ah OK, I see. Yeah, I don’t know any way to get that information. Hopefully, someone else in the community will be able to help you out.
Second, check out @shopify/theme-currency on NPM. Installing this module exposes a JavaScript function, formatMoney, which accepts a price and a money format (which you’ve obtained from shop.money_format in Liquid) and outputs the correct, localised price.