How to prevent adding items in cart page when the available stock is exceeded

Hello,

I’d like to know how to prevent adding items when the available stock is exceeded, as it currently allows adding items beyond the stock limit but gives a warning when decreasing the quantity.

Hello,

You need to get the inventory with each product

{% if current_variant.inventory_quantity > 0 and current_variant.inventory_management == 'shopify' %}
    <p>Stock: {{ current_variant.inventory_quantity }}</p>
  {% endif %}

Now from next to it use the JS to build the logic a/to your need.

Thanks

Thanks for replying, but please where should I add this code??

is it in (main-cart-items.liquid) or other? I’m using Dawn theme.

Did you find the solution?