Hi All!
I would like to check whether there are digital and physical products at the same time in the cart and block checkout.
I have tried to do it in main-cart-items liquid, but since it’s checked only at page load, it gives the same error message if some products are already deleted from the cart. I have tried something like this:
{% assign physical_products = 0 %}
{% assign digital_products = 0 %}
{% for item in cart.items %}
{% if item.requires_shipping %}
{% assign physical_products = physical_products | plus : 1 %}
{% else %}
{% assign digital_products = digital_products | plus : 1 %}
{% endif %}
{% endfor %}
{% if digital_products > 0 and physical_products > 0 %}
<p>Physical and digital products can be purchased in the same order!</p>
{% endif %}
So, it works, but the error is not gone if the products are deleted from the cart, only after refreshing the page.
Can I make this method work somehow?
So, I thought I add the check to cart.js and check when clicking on the checkout button, but I can’t figure out how to iterate the cart items in cart.js.
Any suggestions?
Thank you in advance!