How to display out of stock variants as unavailable on product variants collection page?

Topic summary

Issue: A user wanted to display out-of-stock product variants as unavailable on Shopify collection pages, specifically showing crossed-out prices and titles in a variant table.

Solution Provided:

  • Replace code in snippets/card-product.liquid to create a table displaying all variants with their titles and prices
  • Add CSS to strike through sold-out variant titles and prices using .variant-available--false class
  • For products without variants, modify the product title display logic in card-product.liquid (lines 123 and 160 in Dawn theme)
  • Apply CSS rule .price--sold-out * to cross out prices of unavailable items

Key Technical Details:

  • Original implementation followed a Klinkode tutorial for displaying variants on collection pages
  • CSS targeting required careful scoping to avoid crossing out all products instead of only sold-out ones

Outcome: User successfully implemented both the variant table strikethrough and the single-product strikethrough by combining the liquid code changes with custom CSS additions. Issue resolved.

Summarized with AI on November 4. AI used: claude-sonnet-4-5-20250929.

How can I change the variant table to show that the variants are also unavailable? is there a way to show the variants and prices crossed out?

Hi @asmenu - is the table a custom code that you made?

I followed this :

https://klinkode.com/displaying-product-variants-on-collection-pages-in-shopify/

Then replace lines 12 ad 13 with this:

{% if variant.available %}
  {{ variant.title }}
  {{ variant.price | money }}
{% else %}
  ~~{{ variant.title }}~~
  ~~{{ variant.price | money }}~~
{% endif %}
1 Like

Hey @asmenu ,

Thanks for sharing the doc you used. To display the prices and variant titles of the variants that are sold out please make the below code changes:

  1. Replace the code that you added to the snippets/card-product.liquid with the below code:
{% if template.name == 'collection' and card_product.variants.size > 1 %}
  
      {% for variant in card_product.variants %}
        
      {% endfor %}
    

| Variant | Price |
| - | - |
| {{ variant.title }} | {{ variant.price | money }} |

{% endif %}
  1. Add the below CSS to cross out the titles and prices of the sold-out variants in addition to the CSS you added for the design of the variant table.
.variant-available--false {
  text-decoration: line-through;
}
  1. Once you have made these changes, save the files and try previewing the collection pages. The title and price of the variants that are sold out will be crossed out on the variants table as shown in the screenshot below:

I hope this helps!

If my response helped you, please consider giving it a like ( :+1: ) and marking it as an accepted solution if it resolved your issue. Your feedback helps other community members with similar questions.

Regards,

Abhishek from Swym

this seemed to work! thank you so much!

couldn’t figure out how to make this one work :disappointed_face:

1 Like

how can I get the product with no variants to have the strike through also when sold out?

To cross the title you need to do similar edits.

For Dawn, these lines:

https://github.com/Shopify/dawn/blob/main/snippets/card-product.liquid#L123 and

https://github.com/Shopify/dawn/blob/main/snippets/card-product.liquid#L160

{{ card_product.title | escape }}

change to

{% if product.available %}
    {{ card_product.title | escape }}
{% else %}
  ~~{{ card_product.title | escape }}~~
{% endif %}

To cross out the price it’s better to use CSS. You can add this to “Custom CSS” under theme settings:

.price--sold-out * {
  text-decoration: line-through;
}

Also, you can use CSS for product title too instead of liquid edit above:

.card__content:has(.price--sold-out) a {
  text-decoration: line-through;
}
1 Like

sorry don’t understand where to add the

.price–sold-out * {
text-decoration: line-through;
}

the CSS works but the cross out is crossing all titles out instead of just the sold out ones.

got what I wanted by adding both the CSS codes to Custom CSS. thanks so much!

1 Like