Custom Price Logic
Last updated
Last updated
On your localized sites, prices may appear in different formats depending on the given country and currency. While Glopal can automatically localize prices, if your site has custom JavaScript code that is doing dynamic calculation with prices in the page, this code should be prepared to also handle localized prices in other formats and currencies than the one used on your domestic site.
Common places for this problem to appear are cross-sell and upsell popups or dynamic discount promotions, reading prices from the cart section of the page.
If your site has code that is reading prices directly from the page, and Glopal is localizing prices, code should be updated to recognize localized price format and currency.
Most dynamic features on e-commerce websites are not extracting prices from the visible parts of the page, but use structured data in JSON format or else. These will not be affected by Glopal website localization.
In case you must do calculation based on extracted prices, there are two recommended ways for developers on how to avoid any potential problems:
This option requires modification of site HTML template by adding source content price in additional price element attribute. This way source price is preserved in the attribute regardless of the visible price, which will be localized.
Note: Using this method you can make calculations using source price on every localized site.
See example below:
Add source content price in price element attribute
Query attribute value instead textContent when doing calculations
Glopal provides an easy interface to parse localized prices back to the numeric amount that can be used in calculations.
Note: Using this method you can make calculations using localized price on every localized site.
See example below:
Let’s assume we want to make calculations using the localized price:
We can write code to extract the price and parsing its value: