No worries!
It was pretty straightforward in the end. I followed Snipcarts video on adding multicurrency which meant removing the reference to currency in the div, adding a currency selector drop-down and adding the following script:
<script>
document.addEventListener('snipcart.ready', () => {
const select = document.getElementById('currencies');
select.addEventListener('change', () => {
Snipcart.api.session.setCurrency(select.value);
});
Snipcart.store.subscribe(updateSelectedCurrency);
});
function updateSelectedCurrency () {
const state = Snipcart.store.getState();
const currency = state.cart.currency;
document.getElementById('currencies').value = currency;
}
</script>
To get the prices working I checked your github files for your Snipcart plugin to make sure the price field was a string instead of number and then changed my airtable to a concatenate formula taking the different currency prices from other fields
CONCATENATE('{"gbp": ',{Small Price (GBP)},', ', '"usd": ',{Price (USD)},', ', '"cad": ',{Price (CAD)},', ', '"eur": ',{Price (EUR)},', ', '"aud": ',{Price (AUD)},'}')
and returning a string like this: {“gbp”: 7.4, “usd”: 11.1, “cad”: 14.4, “eur”: 10.4, “aud”: 15.5}
to reference in the price field and which is readable by Snipcart.
I figure the easiest way to make the display prices change according to the selected currency is to have different divs with the prices taken from airtable all set to hidden and add to the Snipcart script to show and hide the divs according to the selected currency from the drop down… Charles from Snipcart also suggested this could be used to get the currently selected currency on their forum const currency = Snipcart.store.getState().cart.currency;
but my Javascript knowledge isn’t strong enough to figure out how to put it together, but I’m guessing that would be a similar script, but without needing to reference the drop down select.
If it can be done in a way where any divs with a class of “currency-usd” would show when USD (for example) is selected then I can also display country specific info to users beyond just the correct price.
I’m also trying to figure out if I can work Geotargetly into it somehow so I can have the correct currency displayed based in the users IP location automatically.