Search code examples
shopifye-commerceliquidcheckout

Disable checkout if products do not have same tag Shopify


I have a product (tag contains 'starter-bracelet') in my store that must be sold with another linking product (tag contains 'bracelet-link'). Is there any way to block checkout if only the starter-bracelet product is in there and then allow checkout once the linked product is added?

Thanks in advance


Solution

  • I have managed to sort it, just needed to work out the correct logic.

            {% assign starter_bracelet = false %}
            {% assign nomination_link = false %}
            {% assign allow_checkout = true %}
    
            {% for item in cart.items %} 
              {% if item.product.tags contains 'starter-bracelet'%}
                {% assign starter_bracelet = true %}
              {% endif %}
              {% if item.product.tags contains 'link' %}
                  {% assign nomination_link = true %}
              {% endif %}
            {% endfor %}
            {% if starter_bracelet == true and nomination_link != true %}
                  {% assign allow_checkout = false %}
                  {% render 'nomination-checkout-message' %}
            {% endif %}