Change add to cart button when sold out

Solved
Highlighted
Tourist
10 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
Shopify Partner
799 124 412

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

1 Like
Highlighted
Shopify Partner
1445 195 521

This is an accepted solution.

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
4 Likes
Highlighted
Tourist
10 0 1

done that

0 Likes
Highlighted
Shopify Partner
1445 195 521

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
10 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
Highlighted
New Member
2 0 0

Hello Ninthony,

 

I am new in Shopify and I am having this issue in my collection page.

 

Would you please tell me where can I add this code?

0 Likes
Highlighted
New Member
2 0 0

Solved!

0 Likes
Highlighted
New Member
1 0 0

Hi Ninthony, 

We use the Prestige theme... How do we change the "ADD TO CART" text and change to "PRE-ORDER" when product is out of stock?

Thanks!

 

0 Likes
Highlighted
New Member
1 0 0

Hey, I’ve got the same issue with a new theme can you help?

0 Likes