Remove quantity selector when only one item in stock

Hi there,

I would like to remove the quantity selector box from my product pages when there is only one item in stock. I found this thread about the topic:

https://community.shopify.com/c/technical-q-a/remove-quantity-selector-if-stock-1/m-p/715971#M22975

I tried to follow it but the code on my product file looks different. I found it under Sections>main-product.liquid. And the code for the quantity part looks like this:

{%- when 'quantity_selector' -%}
            
              

              
            

It’s different from the thread I linked above so I tried it and it didn’t work. How can I make this happen? I want the quantity box gone only when there is just one item in stock to make the navigation make more sense. I am using the Studio theme, it’s a 2.0 store if that helps resolve this.

Thank you for your help!

Hi @roundthings

This is pretty simple if your product has no variants, add the following code right under the “when” statement:

{% if current_variant.inventory_quantity > 1 %}

Then add the following right after the last

{% endif %}

This will only display your quantity selector if the inventory is greater than 1.

Let us know if that works!

Hi there, thank you for replying! None of my products have variants at the moment. But I just tried adding these two lines where you instructed and it didn’t work unfortunately. The quantity box still shows on the product pages of all products (including the ones that only have one item in stock). Any other suggestions?

Hi @roundthings - I came across this thread, and the reason the code above did not work, is because it should have been this:

{% if product.selected_or_first_available_variant.inventory_quantity > 1 %}

and not:

{% if current_variant.inventory_quantity > 1 %}

So your full code shoyuld have looked like this (I am also using the STUDIO Theme), and it worked for me correctly as follows:

{%- when 'quantity_selector' -%}
 {% if product.selected_or_first_available_variant.inventory_quantity > 1 %}             
            
              

              
            

{%- endif -%}

Hope that helps someone!

Can thank ChatGPT for that one!

Hi I’m looking for the same fix for the Spotlight theme and this isn’t working. Is there something different I could do?