Check if your product in cart is in a specific collection, if no then hide checkout?

Highlighted
New Member
1 0 0

Hi,

 

I'm trying to hide my 'checkout' button on cart page and display the message "You must select a delivery slot, click here" if a product from the "sample" collection is not in the basket.

 

To help I found this on Stack overflow, it works at displaying the message if a product IS in the basket, but I need it to display if the product IS NOT in the basket, and then if it is not found, hide the checkout button.

 

Any help would be greatly appreciated!!

 

{% for item in cart.items %}  
  {% assign found_collection = false %}
  {% for collection in item.product.collections %}
    {% if found_collection == false and collection.title == 'SampleProduct' %}
      {% assign found_collection = true %}
    {% endif %}
  {% endfor %}
  {% if found_collection %}
    <p>Enjoy your Product</p>
  {% endif %}
{% endfor %}

 (https://stackoverflow.com/questions/20102726/shopify-how-would-i-see-if-a-product-in-my-cart-had-a-s...)

0 Likes