Change currency symbol on button and everywhere automatically

Change currency symbol on button and everywhere automatically

hem0903
Explorer
60 0 11

Hi, I have mentioned price in GBP on a button attaching image for that, now I want it to change automatically if the user in USA. It should change its price to USD and its value as well, I have mentioned price in some texts as well, I want it to get change automatically, how can I do that.

 

Store Url - https://www.abimax.com/

hem0903_0-1742215525551.png

 

Reply 1 (1)

Dotsquares
Shopify Partner
370 22 51

hi @hem0903 

To automatically fluctuate the price depending on where the user is located, you can utilize Shopify's Geolocation API or use a currency exchange app. This is how to do it:

Solution 1: Utilize Shopify Markets (If Enabled)
In case Shopify Markets is activated, Shopify automatically picks up where the user is and adjusts the price according to their currency setting.


Navigate to Settings > Markets within your Shopify admin.
Enable international pricing and configure currency conversion for various regions.
Make sure you have a currency selector activated in your theme.


Solution 2: Dynamic Currency Conversion using JavaScript
If you prefer to implement currency conversion manually on buttons and text, you can use JavaScript with an exchange rate API (such as Shopify's currency data or Open Exchange Rates).

fetch('https://ipapi.co/json/')  
  .then(response => response.json())  
  .then(data => {  
    let userCountry = data.country_code;  
    let priceElement = document.getElementById("price-button");  

    if (userCountry === "US") {  
      let priceInGBP = 50; // Example GBP price  
      let exchangeRate = 1.25; // Example GBP to USD rate  
      let priceInUSD = (priceInGBP * exchangeRate).toFixed(2);  

      priceElement.innerText = `$${priceInUSD} USD`;  
    }  
  });  

Steps to Use:
Substitute "price-button" with the actual ID/class of the button where the price is shown.
You can 
use this script for all fields where the price is stated.

 

Dotsquares Ltd


Problem Solved? ✔ Accept and Like solution to help future merchants.


Shopify Partner Directory | Trustpilot | Portfolio