我一直在试图找到最好的方法来添加一个免费的产品到购物车在Shopify,但找不到我正在寻找的文件。
如果购物车的值是10 10或更高,我需要做的是将产品添加到购物车中。我已经设法增加了产品,但是我怎样才能把价格改为零呢?此外,如何确保如果用户选择更高数量的产品,他们不会得到多个免费项目,只有一个免费项目?希望这是合理的。
这是我到目前为止所拥有的,它非常好地添加了产品。但不能改变价格。
*编辑:我意识到,如果我不能改变一个项目的价格,那么我可以在购物车的层次上应用固定的折扣代码吗?
**编辑:想想看,一个折扣代码无论如何都不会起作用,因为用户可以轻松地删除免费产品,但仍然可以获得折扣。也许我需要创建某种隐藏的产品,无法在商店中搜索,添加到购物车和禁用数量选择器。
一定有办法做到这一点,因为有应用程序可以做到这一点。
**我不想使用应用程序
<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 %}
发布于 2020-05-07 02:17:01
您可以通过使用标准的Shopify功能来实现这一点。
configuration:
- Type: **Buy X get Y**
- Customer spends: **Minimum purchase amount**
- Amount: **£10**
- Any items for: **Specific collections**
- Search and add the collection you created in the 1st step
- Customer gets:
- 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中规定的标准价格得到礼品。如果购物车符合标准,只会打折一件礼品。
https://stackoverflow.com/questions/61637231
复制相似问题