Personalized checkout and custom promotions with Shopify Scripts
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!
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024