-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShow Free Gift Option on Cart Template in Shopify
57 lines (48 loc) · 2.01 KB
/
Show Free Gift Option on Cart Template in Shopify
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Paste this below code in Shopify > Section > New Section > enter any name of your choice-
{% assign section_collection = section.settings.collection %}
{% unless cart.item_count == 0 %}
{% assign product_collection_qty = 0 %}
{% for line_item in cart.items %}
{% for line_item_product_collection in line_item.product.collections %}
{% if line_item_product_collection.title == section_collection.title %}
{% assign product_collection_qty = product_collection_qty | plus: line_item.quantity %}
{% if product_collection_qty >= 3 %}
{% assign show_gifting_product = true %}
{% endif %}
{% endif %}
{% endfor %}
{% if show_gifting_product %}
<div class="wrapper page-margin">
<h2 class="free-gift-title">Choose Free Gift of your choice</h2>
<div class="cart-gift-flex">
{% for product in section_collection.products %}
<div class="cart-gift-flex-item">
<a href="{{ product.url }}"><img src="{{ product.featured_image | img_url: "medium" }}"></a>
<h3 class="h5--accent strong name_wrapper" style="text-align: center">{{ product.title }}</h3>
<p style="text-align: center;">{{ product.price | money }}</p>
<form method="post" action="/cart/add" style="text-align: center">
<input type="hidden" name="id" value="{{ product.variants.first.id }}">
<!-- <input min="1" type="number" id="quantity" name="quantity" value="1"/> -->
<input type="submit" value="ADD TO CART" class="btn">
</form>
</div>
{% endfor %}
</div>
</div>
{% endif %}
{% endfor %}
{% endunless %}
{% schema %}
{
"name": "Cart Free Gift",
"settings": [
{
"type": "collection",
"id": "collection",
"label": "Select Free Gift Collection"
}
]
}
{% endschema %}
Add this section in your cart-template.liquid file.
Make sure for automatic discount you have to create automatic BOGO discount in Shopify.