BLOG

Cart page recommended product section Shopify



{%- for item in cart.items -%}
{%- assign product_rec = item.product -%}
{%- endfor -%}
{%- assign tagn = section.settings.tag_name %}
<div class="page-width">
<div class="product-recommendations__inner">
{%- if section.settings.heading != blank -%}
<div class="section-header text-center">
<h2>{{ section.settings.heading | escape }}</h2>
</div>
{%- endif -%}
<ul class="grid grid--uniform grid--view-items">
{%- for product in collections.all.products -%}
{%- assign display = true -%}

{%- for item in cart.items -%}
{%- if item.product.id == product.id or product.tags contains tagn -%}
{%- assign display = false -%}
{%- endif -%}
{%- endfor -%}
{%- if product.tags contains tagn -%}
{%- assign display = false -%}
{%- endif -%}
{%- if display == true -%}

<li class="grid__item small--one-half medium-up--one-quarter">
{% include 'product-card-grid', max_height: 250, product: product, show_vendor: section.settings.show_vendor %}
</li>
{%- endif -%}

{%- endfor -%}
</ul>
</div>
</div>

{%- if section.settings.show_product_recommendations and cart.item_count > 0 -%}
{%- if recommendations.performed -%}
{%- if recommendations.products_count > 0 -%}
{%- endif -%}
{%- else -%}
<div class="page-width hey" data-base-url="{{ routes.product_recommendations_url }}" data-product-id="{{ product_rec.id }}" data-section-id="{{ section.id }}" data-section-type="product-recommendations"></div>
{%- endif -%}
{%- endif -%}

<script>
$('.cart__remove').click(function(){
setTimeout(function(){
location.reload();
}, 1000);
});
</script>
{% schema %}
{
"name": {
"en": "Product Recommend Cart"
},
"settings": [
{
"type": "checkbox",
"id": "show_product_recommendations",
"label": {
"en": "Show dynamic recommendations"
},
"info": {
"en": "Dynamic recommendations change and improve with time. [Learn more](https://help.shopify.com/en/themes/development/recommended-products)"
},
"default": true
},
{
"type": "text",
"id": "heading",
"label": {
"en": "Heading"
},
"default": {
"en": "You may also like"
}
},
{
"type": "text",
"id": "tag_name",
"label": {
"en": "Hide specific product from the recommended product list using tag name"
},
"default": {
"en": "cart_hide"
}
},
{
"type": "checkbox",
"id": "show_vendor",
"label": {
"en": "Show vendor"
},
"default": false
}
]
}
{% endschema %}
Share:

Post a Comment!