通过Shopify中的Javascript将产品价格提高20%

通过Shopify中的Javascript将产品价格提高20%,javascript,shopify,Javascript,Shopify,可能有一个简单的答案,有人可以帮助我,但我不太擅长Javascript。基本上,在Shopify中,我已经设置了显示价格+20%的液体标签。除了在产品页面上,这一点非常有效,因为有一点Javascript在某个尺码缺货时禁用“添加到购物车”按钮,并将价格更改为缺货。无论如何,代码如下: <script> var selectCallback = function(variant, selector) { if (variant && variant

可能有一个简单的答案,有人可以帮助我,但我不太擅长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
      }
    };

var selectCallback=函数(变量、选择器){
如果(变量和变量可用){
//已选择有效的变量
$(“#添加到购物车”).removeClass('disabled').removeAttr('disabled').val('add to cart');//从“添加到购物车”按钮中删除不可用的类,然后重新启用按钮
if(variant.compare_at_price==0){
$('.product title.price').html('+Shopify.formatMoney(variant.price,“{{shop.money_format}}”)+'不含增值税');
}否则{
$('.product title.price').html(''+Shopify.formatMoney(variant.price,“{{shop.money\u format}}”)+'+Shopify.formatMoney(variant.compare\u at\u price,{{shop.money\u format}”)+'不包括增值税';
}
}否则{
//变体不存在
$(“#添加到购物车”).addClass('disabled').attr('disabled','disabled').val('sall Out');//将添加到购物车按钮设置为不可用类并禁用按钮
var消息=变体?“售罄”:“不可用”;
$('.product title.price')。文本(消息);//更新价格字段消息
}
};
在产品列表页面上,我可以使用以下液体标签将价格增加20%

{{product.price|u 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
  }
};

var selectCallback=函数(变量、选择器){
如果(变量和变量可用){
//已选择有效的变量
$(“#添加到购物车”).removeClass('disabled').removeAttr('disabled').val('add to cart');//从“添加到购物车”按钮中删除不可用的类,然后重新启用按钮
if(variant.compare_at_price==0){
$('.product title.price').html('+Shopify.formatMoney((variant.price*1.2),“{{shop.money_format}”)+'不含增值税');
}否则{
$('.product title.price').html(''+Shopify.formatMoney((variant.price*1.2),“{{shop.money_format}”)+'+Shopify.formatMoney(variant.compare_at_price,{{shop.money_format}}”)+'不含增值税';
}
}否则{
//变体不存在
$(“#添加到购物车”).addClass('disabled').attr('disabled','disabled').val('sall Out');//将添加到购物车按钮设置为不可用类并禁用按钮
var消息=变体?“售罄”:“不可用”;
$('.product title.price')。文本(消息);//更新价格字段消息
}
};

我会的,我得等8分钟:)我很好奇。你为什么要这样做?购物车不会识别出这种变化。。。那么,把价格提高20%或其他什么有什么意义呢?@DavidLazar,尽管这是不久前提出的问题,但我现在要回答,因为这可能会对其他人有所帮助。客户只希望在产品页面上显示1个价格,由于他们在英国注册,并且大部分在欧盟销售,他们希望显示20%的增值税,而不是在购物车上用增值税让人们惊讶。在购物车上有两个总数,一个带增值税,一个不带非欧盟客户。