Display cart attribute ONLY if a certain product type is selected

Highlighted
Tourist
11 0 2

I currently have a drop-down menu selection on the cart page which displays no matter what's in the cart.

How can I modify my code so that it only appears if a specific product type is chosen? 

Thanks so much!

0 Likes
Highlighted
Tourist
11 0 2

Ugh.. of course I finally find the solution after making a post:

 

 

 

{% for item in cart.items %} 
        {% if item.product.id == 111111111111 %}
                <p>
                    <label>Cart attribute for Product1</label>
                 
                    <input type="text" name="attributes[Favorite color]" value="{{ cart.attributes['Favorite color'] }}" />
                </p>
        {% endif %} 
{% endfor %}

 

 


The only issue now.. if I modify the code so that it works for a collection of products, then I have multiple copies of the same attribute whenever multiple different products are added. 

How can I restrict it to only 1 instance?

0 Likes
Highlighted
Tourist
11 0 2

The only issue now.. if I modify the code so that it works for a collection of products, then I have multiple copies of the same attribute whenever multiple different products are added. 

How can I restrict it to only 1 instance?


Would really love to find a solution to this!

0 Likes