skip to Main Content

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.

3

Answers


  1. Chosen as BEST ANSWER

    I found a solution myself. The point was that I was using the wrong object. I was using the cart object but I'm working in the checkout page so take a look to the solution:

    {% for item in checkout.line_items %}
    

    Thanks for the help received! - Abel.


  2. You can try this instead

    {% if item.product_id contains "8223550921" %}
    

    Check this cheat for further use of line item properties

    Login or Signup to reply.
  3. 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 %}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search