Hide Add to Cart Button When Inventory is 0

Solved
Vanessa_Davey
New Member
10 0 0

I have tried a few different Back In Stock apps recently, and one of them (not sure which) has changed my theme coding so that my add to cart button is no longer hidden when an item is out of stock. So when an item is out of stock it shows both the add to cart button and the Back In Stock notification sign up box. Of course each of the app developers and my theme developer are unwilling to help, with each blaming someone else. I'm guessing and hoping it's a relatively simple fix?! This is the current add to cart code:

 

{% comment %} This is the add-to-cart button {% endcomment %}
 
          <button type="submit" name="add" id="add" class="product-add">{{ 'products.product.add_to_cart_html' | t }}</button>
{% comment %}
              {% if product.variants.size == 1 %}
 
                {% if product.variants.first.inventory_management == 'shopify' and product.variants.first.inventory_quantity < 1 %}
                <div class="backorder">
                  <p><span class="selected-variant">{{ product.title }}</span> {{ 'products.product.backorder' | t }}</p>
                </div>
                {% endif %}
              {% else %}
              <div class="backorder hidden">
                <p><span class="selected-variant"></span> {{ 'products.product.backorder' | t }}</p>
              </div>
              {% endif %}
          {% endcomment %}
 
Is anyone able to help? 
 
Thanks! 
0 Likes
Ninthony
Shopify Partner
1802 261 711

This is an accepted solution.

Try to wrap an if statement around the button.

{% if product.available %}
<button type="submit" name="add" id="add" class="product-add">{{ 'products.product.add_to_cart_html' | t }}</button>
{% endif %}
If my solution helped you, please like and accept as solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes
Vanessa_Davey
New Member
10 0 0

Oh, fabulous! You're a legend. That's done the trick. Thanks.

0 Likes
Ninthony
Shopify Partner
1802 261 711
No problem, mark the post as the solution if u dont mind : D
If my solution helped you, please like and accept as solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes
Vanessa_Davey
New Member
10 0 0

Done. 

0 Likes
Ninthony
Shopify Partner
1802 261 711
Thanxzuuu!
If my solution helped you, please like and accept as solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes
Leylovemelts
New Member
4 0 0

hi , I'm trying to fix this problem but I don't know where in theme I should add this. could you please help? thank you

0 Likes