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%
基础教程推荐
猜你喜欢
- 即使每次插入第一个输入的值不同,第二个输入仍显示相同的输入值 2022-01-01
- 从快速中间件中排除路由 2022-01-01
- 最佳动态 JavaScript/JQuery 网格 2022-01-01
- 带角度的选项卡:仅使用 $http 在单击时加载选项卡 2022-01-01
- HTML5 画布调整为父级 2022-01-01
- 使用 jQuery 在悬停时交换 DIV 类 2022-01-01
- 当木偶师打开Chrome时,不能使用Chrome扩展 2022-01-01
- 逻辑运算符 ||在 javascript 中,0 代表 Boolean false? 2022-01-01
- CORS:当凭据标志为真时,无法在 Access-Control-Allow-Origin 中使用通配符 2022-01-01
- 在 Javascript 中使用 Fetch API 上传文件并显示进度 2022-01-01
