首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Shopify -如何在更新时更新产品价格

Shopify -如何在更新时更新产品价格
EN

Stack Overflow用户
提问于 2020-05-06 14:04:57
回答 1查看 4.4K关注 0票数 1

我一直在试图找到最好的方法来添加一个免费的产品到购物车在Shopify,但找不到我正在寻找的文件。

如果购物车的值是10 10或更高,我需要做的是将产品添加到购物车中。我已经设法增加了产品,但是我怎样才能把价格改为零呢?此外,如何确保如果用户选择更高数量的产品,他们不会得到多个免费项目,只有一个免费项目?希望这是合理的。

这是我到目前为止所拥有的,它非常好地添加了产品。但不能改变价格。

*编辑:我意识到,如果我不能改变一个项目的价格,那么我可以在购物车的层次上应用固定的折扣代码吗?

**编辑:想想看,一个折扣代码无论如何都不会起作用,因为用户可以轻松地删除免费产品,但仍然可以获得折扣。也许我需要创建某种隐藏的产品,无法在商店中搜索,添加到购物车和禁用数量选择器。

一定有办法做到这一点,因为有应用程序可以做到这一点。

**我不想使用应用程序

代码语言:javascript
运行
复制
<script>
$(".cart__qty-input").blur(function() {

    location.reload();
})(jQuery);
</script>

{% assign product = all_products['free-gift'] %}

{% unless cart.item_count == 0 or product.empty? or product.variants.first.available == false %}
{% if cart.total_price >= 1000 %}
  {% assign variant_id = product.variants.first.id %}

  <script>
  (function($) {

    var cartItems = {{ cart.items | json }},
        qtyInTheCart = 0,
    cartUpdates = {};

for (var i=0; i<cartItems.length; i++) {
  if ( cartItems[i].id === {{ variant_id }} ) {
    qtyInTheCart = cartItems[i].quantity;
    break;
  }
}

if ( ( cartItems.length === 1 ) && ( qtyInTheCart > 0 ) ) {
  cartUpdates = { {{ variant_id }}: 0 }
}
else if ( ( cartItems.length >= 1 ) && ( qtyInTheCart !== 1 ) ) {
  cartUpdates = { {{ variant_id }}: 1 }
}
else {
  return;
}

var params = {
  type: 'POST',
  url: '/cart/update.js',
  data: { updates: cartUpdates },
  dataType: 'json',
  success: function(stuff) { 
    window.location.href = '/cart';
  }
};

$.ajax(params);

  })(jQuery);
  </script>
{% endif %}
{% endunless %}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-07 02:17:01

您可以通过使用标准的Shopify功能来实现这一点。

configuration:

  1. 创建一个集合,其中包含除礼品产品之外的所有产品。

代码语言:javascript
运行
复制
- Type: **Buy X get Y**
- Customer spends: **Minimum purchase amount**
代码语言:javascript
运行
复制
    - Amount: **£10**
    - Any items for: **Specific collections**
    - Search and add the collection you created in the 1st step

代码语言:javascript
运行
复制
- Customer gets:
代码语言:javascript
运行
复制
    - Quantity: **1**
    - Any items from: **Specific products**
    - Search and add the product you want to use as a gift (the one that doesn't belong to the collection created in the 1st step)
    - At a discounted value: **Free**
    - Set a maximum number of uses per order: **enable** it and set the value to **1**

以上必须符合您的规格。

然后,您仍然可以使用您已经创建的脚本自动添加/删除礼品产品到购物车基于购物车总计(如果这是必要的)。如果顾客将礼品的数量改为2件或2件以上,他将按Shopify中规定的标准价格得到礼品。如果购物车符合标准,只会打折一件礼品。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61637231

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档