Ad

Check If Specific Product Is In My Cart

- 1 answer

I created a script that will check if an specific product is in my cart for do something but is not working... If anybody can tell me what is wrong in my code will be very helpful...

{% for item in cart.items %}

{% if item.product.id == "8223550921" %}
    <div><h1>Some text here!</h1></div><br> 

{% endif %}

{% endfor %}

Note: I tested this a lot of time using the product.title and many other options and doesn't work neither.

Ad

Answer

As product id is integer so you should use it as (removing quotes from product-id):-

{% for item in cart.items %}
    {% if item.product.id == 8223550921 %}
        <div><h1>Some text here!</h1></div><br> 
    {% endif %} 
{% endfor %}
Ad
source: stackoverflow.com
Ad