Hi there! Some of my items are being shown as ‘sold out’ when they are still available in several sizes.
So, my customers can filter on ‘in stock’ and ‘out of stock’ and products with different sizes will show up as ‘out of stock’. So for example they are still available in S and M but sold out in L.
Does anyone know if I can somehow adjust it to the items only being shown as sold out, when ALL of the sizes are sold out?
Yeah, this is possible but for that you have to copy and paste code.
To only show the “sold out” button in Shopify when all product variants are out of stock, you have to follow these steps:
Log in to your Shopify admin panel and go to the “Online Store” section.
Click on “Themes” and then click on “Actions” and select “Edit Code” from the dropdown menu.
In the left-hand menu, click on “Sections” and then find and click on “product-template.liquid” or “product.liquid”depending on your theme.
Locate the code that generates the “Add to Cart” button for the product variants. It may look something like this:
{% if product.available %}
{% else %}
Sold Out
{% endif %}
Modify the above code to check if all the product variants are out of stock, and only show the “Sold Out” message in that case. You can do this by checking the inventory levels of each variant in the product’s variant array, like so:
{% assign all_out_of_stock = true %}
{% for variant in product.variants %}
{% if variant.inventory_quantity > 0 %}
{% assign all_out_of_stock = false %}
{% endif %}
{% endfor %}
{% if all_out_of_stock %}
Sold Out
{% else %}
{% endif %}
6. Save the changes to the code, and the “Sold Out” message will now only appear when all the product variants are out of stock else it will show Add to Cart button but it will disable.
I hope you can help me. Below is the ADD TO CART button:
If you notice, I changed the SOLD OUT button to PRE-ORDER (pre_order). However, that button is disabled. I removed the disabled class, but still it didn’t work. My goal is, I want the pre-order button to be clickable just like the ADD TO CART.