对此可能有一个简单的答案,有人可以帮助我,但我对Javascript并不是那么好。基本上在Shopify中,我设置的价格是用他们的一个液体标签显示+ 20%。除了产品页面之外,这样做很有效,因为如果大小缺货并且价格也变得缺货,有一些Javascript会禁用添加到购物车按钮。无论如何这里是代码:
<script>
var selectCallback = function(variant, selector) {
if (variant && variant.available) {
// valid variant selected
$('#add-to-cart').removeClass('disabled').removeAttr('disabled').val('Add to Cart'); // remove unavailable class from add-to-cart button, and re-enable button
if (variant.compare_at_price == 0){
$('.product-title .price').html(''+Shopify.formatMoney(variant.price, "{{shop.money_format}}")+' Excluding VAT');
} else {
$('.product-title .price').html('<span>'+Shopify.formatMoney(variant.price, "{{shop.money_format}}") + '</span> <del>' + Shopify.formatMoney(variant.compare_at_price, "{{shop.money_format}}") + ' Excluding VAT</del>');
}
} else {
// variant doesn't exist
$('#add-to-cart').addClass('disabled').attr('disabled', 'disabled').val('Sold Out'); // set add-to-cart button to unavailable class and disable button
var message = variant ? "Sold Out" : "Unavailable";
$('.product-title .price').text(message); // update price-field message
}
};
在产品详情页面上,我可以使用以下液体标签添加价格的20%
{{ product.price_min | times:1.20 | money }}
我需要做的就是修改Javascript,使其输出的价格乘以1.20。有谁知道这样做的方法?感谢。
答案 0 :(得分:6)
试试这个
<script>
var selectCallback = function(variant, selector) {
if (variant && variant.available) {
// valid variant selected
$('#add-to-cart').removeClass('disabled').removeAttr('disabled').val('Add to Cart'); // remove unavailable class from add-to-cart button, and re-enable button
if (variant.compare_at_price == 0){
$('.product-title .price').html(''+Shopify.formatMoney((variant.price*1.2), "{{shop.money_format}}")+' Excluding VAT');
} else {
$('.product-title .price').html('<span>'+Shopify.formatMoney((variant.price*1.2), "{{shop.money_format}}") + '</span> <del>' + Shopify.formatMoney(variant.compare_at_price, "{{shop.money_format}}") + ' Excluding VAT</del>');
}
} else {
// variant doesn't exist
$('#add-to-cart').addClass('disabled').attr('disabled', 'disabled').val('Sold Out'); // set add-to-cart button to unavailable class and disable button
var message = variant ? "Sold Out" : "Unavailable";
$('.product-title .price').text(message); // update price-field message
}
};