Adding 20% to product price via Javascript in Shopify(在Shopify中通过Javascript将产品价格提高20%)
本文介绍了在Shopify中通过Javascript将产品价格提高20%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个问题可能有一个简单的答案,有人可以帮助我,但我对Javascript不是很在行。基本上在Shopify,我用他们的一个液体标签设置了要显示的价格+20%。除了在产品页面上,这个功能非常有效,因为有一些Javascript可以在某个尺码脱销时禁用Add to Cart按钮,并将价格更改为脱销。不管怎样,下面是代码:
<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。有谁知道做这件事的方法吗?谢谢。
推荐答案
试试
<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
}
};
这篇关于在Shopify中通过Javascript将产品价格提高20%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:在Shopify中通过Javascript将产品价格提高20%


基础教程推荐
猜你喜欢
- 在for循环中使用setTimeout 2022-01-01
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- 响应更改 div 大小保持纵横比 2022-01-01
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 我什么时候应该在导入时使用方括号 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01
- 动态更新多个选择框 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06