Show information in cart if cart contains a product with a certain type

Highlighted
New Member
1 0 0

I am trying to add certain text to the cart page, if the customer has a product in their cart with a specific product type. What am I missing?

 

{% for item in cart.items %}
                      {% if item.product.type == 'Corporate Meals' %}
                     
        <p>Some text for corporate</p>
        {% endif %}
                    
{% endfor %}
                     
 
{% endfor %}
0 Likes
Highlighted
Shopify Staff
Shopify Staff
754 42 151

Hi, @michellepaulhus !

 

Katy here from Shopify. I hope all is well with you, and indeed welcome to our Community here!

 

It does appear that you have an additional {% endfor %} tag added here. (I am not sure if this is a typo ?) Otherwise however, it looks good! I do have some additional questions which may help: 

 

  • Have you added this to the cart-template.liquid file? This would be the best place to customize the cart page.
  • Also, I know this may seem like an obvious question, but have you ensured to apply the correct 'type' to the relevant products in the admin > products section of your admin? We have a guide to help apply this in bulk here.

Once you have ensured the above, I would suggest to clear your cache.  After doing so if you still don't notice any changes, if you could then share a link to your store here that would be great.


Cheers,
Katy

Katy | Social Care @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

0 Likes
Highlighted
New Member
8 0 0

Hello,

I'm trying to adapt this so that if a product isn't in the cart, it will show a button to link to that product page.

However the button keeps appearing for each item in the cart (so if I have 3 other products, it shows the button 3 times).

I'm using the customer notes box to add a message inside the greetings card. So I'd like this to not be visible until a Greetings card is in the cart.

Example:

If "Greetings Card" isn't in the cart, the notes box won't appear. But it will show a button to go to the Greetings Cards product page.

If "Greetings Card" is in the cart, then it won't show the button, but will show the notes box.

 

Code:

{% for item in cart.items %}
                      {% if item.product.type != 'Greetings Card' %}
                     
 <input type="submit" name="view greetings cards"
class="cart__submit btn btn--small-wide"
value="/products/greetings-cards">
  
      {% endif %}
0 Likes