Products are showing as sold out when the 1st option is out of stock but there is availability for the others. How do I change it so that it only displays sold out when all variants are sold out?
I have found similar questions on the community, but I don’t seem to have the same code as any of these so haven’t been able to implement any of the suggestions.
I am using Dawn theme and the only file I have found that mentions the sold out message is card-product.liquid and this is what it contains that I think is relevant?
The product card is checking for availability using card_product.selected_or_first_available_variant.available, which means it’s only checking if the first variant is available.
Here’s the solution:
{% comment %}
Step 1: Find the card-product.liquid file in your theme's snippets directory
Step 2: Locate the current logic that determines if a product is sold out
Step 3: Replace it with this improved version that checks all variants
{% endcomment %}
{% comment %}
Add this code at the top of your card-product.liquid file, before the product card markup
{% endcomment %}
{% assign all_variants_sold_out = true %}
{% for variant in card_product.variants %}
{% if variant.available %}
{% assign all_variants_sold_out = false %}
{% break %}
{% endif %}
{% endfor %}
{% comment %}
Then, find any instances where it checks for product availability like this:
card_product.selected_or_first_available_variant.available
And replace them with your new all_variants_sold_out variable (with inverted logic since it's tracking if ALL are sold out)
{% endcomment %}
{% comment %}
For example, replace this code:
{% endcomment %}
{% else %}
{% render 'quantity-input', variant: card_product.selected_or_first_available_variant, min: 0 %}
{% endif %}
The solution works by:
Creating a variable all_variants_sold_out that starts as true
Looping through all product variants to check if any are available
If at least one variant is available, setting the variable to false
Using this variable instead of just checking the first variant’s availability
This way, the “Sold Out” label and button state will only appear when all variants are truly unavailable, not just when the first variant is out of stock.
After making these changes, save the file and your product cards should now properly show “Sold Out” only when all variants are unavailable.
Feel free to reach out if you’ve any more questions for me.
Thank you for your suggestion. I tried your code but it didn’t seem to change anything. I’ve attached the entire card-product incase you can see anything else to suggest
Thank you so much for taking the time to explain. I’ve tried all of the above but it doesn’t seem to change anything. I’m attaching the entire card-product code incase you have any other suggestions