Search code examples
shopifyshopify-appshopify-template

How check if product exist in cart in Shopify


I want to show recommended products in the cart window.

Below is the code -

{%- if cart.item_count > 0 -%}
  {%- assign product_image_size = '800x1026' -%}
  {% for product in collections[settings.product_upsell_collection].products limit:settings.product_upsell_limit %}
     {%- for item in cart.items -%}
         {%- if item.product.handle != product.handle -%}
             {%- assign product_show = 'no' -%}

             //Other html product markup

         {%- endif -%}
     {% endfor %}
  {% endfor %}       
{%- endif -%}

The issue I'm facing is that the products already in the cart are also showing up in the recommended.


Solution

  • I'd prefer to:

    {%- unless item.product_id == product.id -%}
             //Other html product markup
    {%- endunless -%}