A Shopify theme is public code. Anything you put in it, including an API key, is readable by every visitor. That is the main constraint when you want exchange rates in a store: showing a visitor an approximate price in their own currency, adding a converter, or setting fixed prices for another market from a rate you control.
First, check whether you need any of this. If you use Shopify Payments with Shopify Markets, Shopify already converts checkout prices at its own rates, and you can set a manual rate per market in Settings → Markets. The options below are for what Markets doesn't do: estimated local prices on a store that sells in one currency, a converter on product pages, or fixed market prices set from a rate and rounding rule you choose.
The rates here are mid-market rates from AllRatesToday's /api/v1/rates endpoint, not the rate Shopify applies at checkout. The full guide is at allratestoday.com/docs/integrations/shopify/.
Option 1: Embed a converter
The simplest option is a Custom Liquid block on the product template. It shows a converter pre-filled with the product's price, using the daily ECB reference rates (30+ major currencies):
<div class="art-currency-widget"
data-base="{{ cart.currency.iso_code }}"
data-target="EUR"
data-amount="{{ product.selected_or_first_available_variant.price | divided_by: 100.0 }}"></div>
<script async src="https://allratestoday.com/widget.js"></script>
Don't add data-api-key here, for the reason above: theme code is public. For live rates in 160+ currencies, use Option 2. The widget reference has the other attributes.
Option 2: An estimated price in the visitor's currency
This takes two pieces: detect the visitor's currency from their IP, then fetch the rate through a small proxy that holds the key.
Step 1: a rate proxy on Cloudflare Workers
Create a Worker with this code. Add your API key as the secret ALLRATES_KEY and your store's URL as STORE_ORIGIN:
// Cloudflare Worker (free plan is enough): holds your key, caches each rate 15 min.
export default {
async fetch(req, env, ctx) {
const url = new URL(req.url);
const from = (url.searchParams.get('from') || '').toUpperCase();
const to = (url.searchParams.get('to') || '').toUpperCase();
if (!/^[A-Z]{3}$/.test(from) || !/^[A-Z]{3}$/.test(to)) {
return new Response('{"error":"from and to must be ISO 4217 codes"}', { status: 400 });
}
const cacheKey = new Request(`https://rates.internal/${from}-${to}`);
let res = await caches.default.match(cacheKey);
if (!res) {
const r = await fetch(
`https://allratestoday.com/api/v1/rates?source=${from}&target=${to}`,
{ headers: { Authorization: `Bearer ${env.ALLRATES_KEY}` } }
);
if (!r.ok) return new Response('{"error":"rate unavailable"}', { status: 502 });
const [{ rate }] = await r.json();
res = new Response(JSON.stringify({ from, to, rate }), {
headers: { 'Content-Type': 'application/json', 'Cache-Control': 'max-age=900' },
});
ctx.waitUntil(caches.default.put(cacheKey, res.clone()));
}
const out = new Response(res.body, res);
out.headers.set('Access-Control-Allow-Origin', env.STORE_ORIGIN); // e.g. https://yourstore.com
return out;
},
};
The cache is what keeps usage flat. Each Cloudflare location fetches a currency pair at most once every 15 minutes, however much traffic the store gets, so a busy store still uses only a few thousand calls a month. The input check stops the proxy from being used to fetch arbitrary strings, and the CORS header limits browser use to your store's origin.
Step 2: the theme snippet
In Online Store → Themes → Edit code, add this under the price in your product section (or in a Custom Liquid block):
{%- comment -%} sections/main-product.liquid, under the price {%- endcomment -%}
<p class="approx-local-price" hidden
data-amount="{{ product.selected_or_first_available_variant.price | divided_by: 100.0 }}"
data-currency="{{ cart.currency.iso_code }}"></p>
<script>
(async () => {
const el = document.querySelector('.approx-local-price');
if (!el) return;
try {
// 1. Visitor's currency from their IP
const { currency } = await fetch('https://allratestoday.com/api/open/geo').then(r => r.json());
if (!currency || currency === el.dataset.currency) return;
// 2. Rate through your Worker, so the key stays private
const { rate } = await fetch(
'https://rates.yourname.workers.dev/?from=' + el.dataset.currency + '&to=' + currency
).then(r => r.json());
const local = new Intl.NumberFormat(undefined, { style: 'currency', currency })
.format(el.dataset.amount * rate);
el.textContent = 'About ' + local + ' (estimate, you pay in ' + el.dataset.currency + ')';
el.hidden = false;
} catch (e) { /* leave the shop price on its own */ }
})();
</script>
Two details. product.price is in cents in the cart's currency, which is why the snippet divides by 100 and converts from cart.currency.iso_code. And if you still charge in your own currency, label the result as an estimate, as the snippet does. Any failure leaves the shop price on its own.
Option 3: Sync fixed market prices every night
If you sell in several currencies, Markets can use fixed prices from a price list instead of automatic conversion. A nightly job can recompute those prices from the day's mid-market rate and apply your own rounding, so your EUR prices follow the dollar without converting at checkout.
You need an Admin API access token from a custom app and the ID of the market's price list. Fixed-price availability depends on your Shopify plan, so check Shopify's Markets documentation.
// sync-market-prices.mjs: run nightly (cron, GitHub Actions, a Worker cron).
// Sets fixed EUR prices on a market's price list from today's USD->EUR rate.
const SHOP = 'yourstore.myshopify.com';
const PRICE_LIST_ID = 'gid://shopify/PriceList/123456789';
const VARIANTS = [
{ id: 'gid://shopify/ProductVariant/111', usd: 49.0 },
{ id: 'gid://shopify/ProductVariant/222', usd: 129.0 },
];
const [{ rate }] = await fetch(
'https://allratestoday.com/api/v1/rates?source=USD&target=EUR',
{ headers: { Authorization: `Bearer ${process.env.ALLRATES_KEY}` } }
).then(r => r.json());
// Charm pricing: round up to the next whole euro, minus one cent.
const charm = (x) => (Math.ceil(x) - 0.01).toFixed(2);
const prices = VARIANTS.map(v => ({
variantId: v.id,
price: { amount: charm(v.usd * rate), currencyCode: 'EUR' },
}));
const res = await fetch(`https://${SHOP}/admin/api/2025-10/graphql.json`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Shopify-Access-Token': process.env.SHOPIFY_ADMIN_TOKEN,
},
body: JSON.stringify({
query: `mutation($id: ID!, $prices: [PriceListPriceInput!]!) {
priceListFixedPricesAdd(priceListId: $id, prices: $prices) {
prices { variant { id } price { amount currencyCode } }
userErrors { field message }
}
}`,
variables: { id: PRICE_LIST_ID, prices },
}),
}).then(r => r.json());
console.log(`USD->EUR ${rate}`, JSON.stringify(res.data.priceListFixedPricesAdd));
One run costs a single rate call. For many currencies, request them together (target=EUR,GBP,CAD) and loop over the rows.
What changes for the customer
- Options 1 and 2 only display information, so checkout is unchanged.
- Option 3 changes the fixed prices in a market's price list, which customers in that market then pay.
- Shopify's automatic conversion still uses Shopify's own rates, plus its conversion fee where it applies. None of this changes that; Option 3 sets fixed prices that replace automatic conversion for a market.
A store is commercial use, so Options 2 and 3 need a paid plan; build and test on a free key first. Plans are on the pricing page.
Links
- Guide: https://allratestoday.com/docs/integrations/shopify/
- Exchange rate API: https://allratestoday.com/exchange-rate-api/
- Other integration guides: https://allratestoday.com/docs/integrations/
- API key: https://allratestoday.com/register/
Rates are mid-market rates for display and pricing. They are indicative, not dealing quotes, and not the rate Shopify applies at checkout.
Top comments (1)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.