How to limit quantity selection to available stock in Liquid?

Hi i have the code for my quantity-select.liquid file I’m wanting it so that when clicking the plus button, you can only go up to the amount of the product stock. I hope that makes sense? So basically you can only select the amount of quanitty available for that product.

If someone could help please?

{% comment %}
   context {String}
    The context, either 'product' or 'cart'

   item {Object}
    The cart item object
{% endcomment %}

{% assign quantity_increment_value = settings.quantity_increment_value %}

Hi @Dccomputers ,

Please change all code:

{% comment %}
  @param context {String}
    The context, either 'product' or 'cart'

  @param item {Object}
    The cart item object
{% endcomment %}

{% assign quantity_increment_value = settings.quantity_increment_value %}

{%- if context == 'product' -%}

{%- endif -%}

Hope it helps!

Unfortunately it still allows me to add more quantity than what’s available for example this one it’s letting me go up to 7 for example when theres only 2 in stock available.

Would I be able to let you log in?

Hi @Dccomputers ,

Please send your site and if your site is password protected, please send me the password. I will check it.