I need to take data from this URL: https://e453eb.myshopify.com/products/chakananecklace.json
and I write a code: // Now, make the AJAX request
$.ajax({
url: 'https://e453eb.myshopify.com/products/chakananecklace.json',
type: 'GET',
success: function(data) {
// Handle success
console.log(data);
},
error: function(xhr, textStatus, errorThrown) {
// Handle error
}
});
all is fine just I get data.variant[0].price
in user's local currency and not the default currency. How I can fix that? Can I send a header with user locale to get the correct results to can I set the user cookie['cart_currency'] to USD
Also if not possible to set the desired currency, how I can get the response cookie ['cart_currency']
The problem is that I got prices but I don't know which currency is that, because Shopify gives prices based on user locale
To ensure that you receive the prices in the default currency regardless of the user's locale, you can try adding a currency parameter ( as a query param) to the URL when making the AJAX request. This parameter specifies the currency in which you want the prices to be returned. In this case, you want the prices in USD. Here's how you can modify your code:
// Now, make the AJAX request
$.ajax({
url: 'https://e453eb.myshopify.com/products/chakananecklace.json?currency=USD',
type: 'GET',
success: function(data) {
// Handle success
console.log(data);
},
error: function(xhr, textStatus, errorThrown) {
// Handle error
}
});
You can directly hit this URL in browser and play with currency.
https://e453eb.myshopify.com/products/chakananecklace.json?currency=USD