【发布时间】:2021-04-06 19:40:30
【问题描述】:
我正在使用 this 脚本在 Shopify 中格式化货币。问题是我需要拥有多种货币的灵活性,而当前的功能似乎不支持它。
我尝试将该脚本包含在 .liquid 文件中,并使用 {{ currency.symbol }} 之类的:Shopify.money_format = "{{ currency.symbol }}" + "{{amount}}"; 或 "{{ currency.symbol }}{{amount}}"; 或 {{ currency.symbol }} + "{{amount}}"; 但这会导致 placeholderRegex 出现错误,该错误将变为未定义。
谢谢!
编辑: 这是我使用该函数的代码:
Shopify.onItemAdded = function(line_item) {
jQuery.getJSON('/cart.js', function(cart) {
// change total price
$('#popup_total').html(Shopify.formatMoney(cart.total_price))
});
};
编辑[2]:最后我采用了不同的方法。我在函数外部声明了当前货币变量,然后将原始 $ 符号替换为商店拥有的任何货币符号。它是这样的:
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)
})
}
【问题讨论】:
标签: javascript shopify