LogoLogo
MerchantsHelpSign in
  • Overview
    • Countries & Currencies
    • Glopal Solutions Portfolio
  • Getting started
    • Shopify
      • Glopal Duty & Tax for Shopify
      • Shopify Collaborator Access
    • BigCommerce
    • Magento (Adobe Commerce)
      • Magento 1
      • Magento 2
        • Magento Activation
        • Magento Configuration
        • Magento Database Model
    • Visualsoft
    • PrestaShop
  • Marketing Solutions
    • Acquisition channels
      • Integrate Google Ads
      • Integrate Facebook Ads
    • Feed localization
      • Read domestic items
      • Localize the items
      • Upload the localized items
    • Features / Customization
      • Google Shopping countries coverage
      • Filters
      • Free listings
      • Comparison Shopping Services (CSS)
    • Google Ads
      • Conversion tracking
      • Standard accounts structure
      • Launching and monitoring Google Ads campaigns
    • Facebook
      • Facebook & Instagram Shops
      • Catalog Based Campaigns
      • Conversion and Brand awareness campaigns
      • Facebook conversion tracking
    • Email marketing
  • Localization
    • Site localization
      • Content localization
      • Price localization
      • Site search
      • Checkout
      • User account
    • Site discovery
      • Domains and Routing
      • Search engine optimization
      • Geo-localization
      • Country selector
    • Content distribution
      • Site security
      • Domains (DNS)
      • Traffic Splitting
        • Akamai
        • Cloudflare
        • Nginx
        • Microsoft IIS
        • AWS CloudFront
        • Magento Cloud
      • Third-party CDN
        • Cloudflare
      • Site speed
    • Integrations
      • CSS customizations
      • JavaScript customizations
      • Server-side customizations
      • Exclude from localization
      • Integration examples
        • Hiding Products
        • Newsletter Signup
        • Custom Price Logic
  • Checkout
    • Localized checkout
      • Overview
      • Styling
      • Integration
        • Callback Functions
        • Confirmation Page
        • Checkout Analytics
        • Allowlisting Glopal IPs
      • Price localization
    • Order processing
      • Order creation
        • Plug & Play integration
        • Order API
        • Event webhook
        • Custom Integration
      • Cancellation & refund
      • Returns
      • Buyer's communication
      • Customer account
    • Financials
      • EU VAT
  • DUTY & TAXES
    • Product Classification
    • Duty & Tax Calculation
      • Product Pricing
      • Supported Countries
    • Compliance Checks
      • Prohibited Goods
      • Denied Party Screening
  • SHIPPING
    • Order Creation
    • Label Generation
    • Manifest
    • Tracking
  • Translations
    • Translation Editor
  • MERCHANT ACCOUNT
    • Dashboards
      • SEO dashboard
  • What's New
    • Release Notes
Powered by GitBook
On this page
  1. Localization
  2. Integrations
  3. Integration examples

Custom Price Logic

PreviousNewsletter SignupNextLocalized checkout

Last updated 4 months ago

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:

  1. Expose source / unlocalized price

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

Javascript

const priceElement = document.querySelector('div[gp-unitprice]');
if (priceElement) {
  const priceAmount = priceElement.getAttribute('gp-unitprice');
  // priceAmount: 223.35
  ...
}

  1. Parse localized price

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:

Javascript

const priceElement = document.querySelector('span.price');
if (priceElement) {
  const priceText = priceElement.textContent;
  const priceAmount = window.glopal
    ? glopal.engine.replacer.parseTargetCurrencyString(priceText)
    : parseFloat(priceText);
  // priceAmount: 1016.99
  ...
}