What's your biggest current challenge? Have your say in Community Polls along the right column.

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

Solved

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

asmenu
Tourist
12 0 2

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? 

Screenshot 2024-11-14 at 4.32.10 PM.png

Accepted Solution (1)
tim
Shopify Partner
3911 394 1435

This is an accepted solution.

Then replace lines 12 ad 13 with this:

{% if variant.available %}
  <td>{{ variant.title }}</td>
  <td>{{ variant.price | money }}</td>
{% else %}
  <td><s>{{ variant.title }}</s></td>
  <td><s>{{ variant.price | money }}</s></td>
{% endif %}

 

If my post is helpful, consider liking it -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com

View solution in original post

Replies 11 (11)

kraftivsoftware
Shopify Partner
3 0 0

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

Kraftiv Software | We help small businesses kickstart their E-Commerce journey
tim
Shopify Partner
3911 394 1435

This is an accepted solution.

Then replace lines 12 ad 13 with this:

{% if variant.available %}
  <td>{{ variant.title }}</td>
  <td>{{ variant.price | money }}</td>
{% else %}
  <td><s>{{ variant.title }}</s></td>
  <td><s>{{ variant.price | money }}</s></td>
{% endif %}

 

If my post is helpful, consider liking it -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com
asmenu
Tourist
12 0 2

this seemed to work! thank you so much! 

asmenu
Tourist
12 0 2

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

Screenshot 2024-11-15 at 1.05.52 AM.png

tim
Shopify Partner
3911 394 1435

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 %}
  <s>{{ card_product.title | escape }}</s>
{% 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;
}

 

If my post is helpful, consider liking it -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com
asmenu
Tourist
12 0 2

sorry don't understand where to add the 

 

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

asmenu
Tourist
12 0 2

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

asmenu
Tourist
12 0 2

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

swym
Trailblazer
157 33 73

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 %}
  <table class="variants-table">
    <thead>
      <tr>
        <th>Variant</th>
        <th>Price</th>
      </tr>
    </thead>
    <tbody>
      {% for variant in card_product.variants %}
        <tr class="variant-available--{{ variant.available }}">
          <td>{{ variant.title }}</td>
          <td>{{ variant.price | money }}</td>
        </tr>
      {% endfor %}
    </tbody>
  </table>
{% endif %}

 

2. 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;
}

 

3. 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: 

swym_0-1731649312280.png

 

I hope this helps! 

 

If my response helped you, please consider giving it a like (👍) 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

- Appreciate the assistance. Show your approval with a Like! And when your question finds its answer, seal the deal by marking it as an Accepted Solution!
- Our Solutions: Wishlist Plus | Swym Back in Stock Alerts | Swym Gift Lists and Registries
asmenu
Tourist
12 0 2

couldn't figure out how to make this one work 😞