Change add to cart button when sold out

Solved
Highlighted
Tourist
6 0 1

I have a buy now / add to cart button on my collections page, but when a product is out of stock it still says buy now and allows the customer to add the item to their cart. How can I change this please? It changes on the product page.

I have searched and read various threads but still can't find the answer.

I'm using the classic theme.

 

link to show what I mean 

 

I'm assuming its this bit of code that needs an if else statement adding, I just don't know how to write that code

 <form method="post" action="/cart/add">
    <input type="hidden" name="id" value="{{ product.variants.first.id }}" />
    <input type="submit" value="Buy now" class="btn" />
  </form>  
0 Likes
Highlighted
Excursionist
629 110 323

ok, i can fix this issue for free.
-add me as a staff in your store.

email: candisoft100@gmail.com
-you can trust me as i am one of the top 5 authers of shopify which you can confirm in this page at the bottom  ,where you can find my name candiSoft

 

Give me a like and mark as accepted solution.

Thank You

0 Likes
Highlighted

Success.

Shopify Partner
1197 162 323

Try this out:

 

<form method="post" action="/cart/add">
    <input type="hidden" name="id" value="{{ product.variants.first.id }}" />
    <input type="submit" value="{% if product.variants.first.available%}Buy now{% else %}Sold Out{% endif%}" class="btn" {% unless product.variants.first.available %}disabled{% endunless %} />
  </form>  
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
1 Like
Highlighted
Tourist
6 0 1

done that

0 Likes
Highlighted
Shopify Partner
1197 162 323

Looks like it worked : 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
Highlighted
Tourist
6 0 1

Thank you so much, that worked perfectly.

I was replying to the other post with my previous post, and hadn't seen your reply.

0 Likes