I am using this script for formatting money in Shopify. The problem is that I’d need the flexibility of having multiple currencies and the current function doesn’t seem to support it.
I’ve tried including that script in a .liquid
file, and using {{ currency.symbol }}
like: Shopify.money_format = "{{ currency.symbol }}" + "{{amount}}";
or "{{ currency.symbol }}{{amount}}";
or {{ currency.symbol }} + "{{amount}}";
but that gives an error with placeholderRegex
which becomes undefined.
Thanks!
EDIT:
This is the code where I use the function:
Shopify.onItemAdded = function(line_item) {
jQuery.getJSON('/cart.js', function(cart) {
// change total price
$('#popup_total').html(Shopify.formatMoney(cart.total_price))
});
};
EDIT[2]: At the end I went with a different approach. I declared the current currency variable outside the function, and then I replace the original $ symbol, with whatever currency symbol the store has. It goes like this:
var currentCurrency = '{{ cart.currency.symbol }}'
Shopify.onItemAdded = function(line_item) {
jQuery.getJSON('/cart.js', function(cart) {
var total = Shopify.formatMoney(cart.total_price).replace('$', currentCurrency)
$('#popup_total').html(total)
})
}
3
Answers
That function doesn’t limit you to a single currency – the first parameter is the unformatted amount, and the second is the desired format, which can have whichever currency you want – e.g.
"€ {{amount}}"
EDIT:
It looks like you aren’t using the second format parameter. Could you try:
Or whatever currency you want there? Thanks for providing additional code, but it’s still difficult to understand the input and desired output, as well as other variables you have access to (you mentioned a dynamic currency, but where is that stored? Which variable?)
default for Dollar
For Pound sterling money format
For Euro money format
Just try that
and replace with