Change Sold Out button with if-rule on collection (studio theme)

Solved

Change Sold Out button with if-rule on collection (studio theme)

lsvvintage
Excursionist
42 2 4

Hi!

 

I've been struggling with finding a solution for this for a while now, so hopefully you can help me!

 

I want to add an if-rule to the sold out button, that when a product has the tag 'archive', the 'sold out' button changes to 'ARCHIVE'. Preferably on the collection page only, if that's not possible, then on both collection as well as the product page.

 

If somebody could please share how to create this, that would be amazing!!!

 

Thanks a lot,

- L

Accepted Solution (1)
WalkYourStyle
Navigator
473 57 78

This is an accepted solution.

Follow the below instructions:
1) In your theme's code in the snippets folder open the file 'card-product.liquid'

2) In the above file search for this piece of code that is located at around line 130 and it's below a <span> element with id that starts with
'NoMediaStandardBadge'

{{- 'products.product.sold_out' | t -}}

3) Replace the above code with this one:

{% assign archive_found = false %}
    {% for tag in card_product.tags %}
         {% if archive_found == false and tag contains 'ARCHIVE'%}
              ARCHIVE
              {% assign archive_found = true %}
         {% endif %}
    {% endfor %}
{% if archive_found == false %}
    {{- 'products.product.sold_out' | t -}}
{% endif %}

View solution in original post

Replies 8 (8)

WalkYourStyle
Navigator
473 57 78

Could you please share your store's URL ?

lsvvintage
Excursionist
42 2 4
WalkYourStyle
Navigator
473 57 78

So you want to change the card badge from Sold out to ARCHIVE if that product has a tag of ARCHIVE?

lsvvintage
Excursionist
42 2 4

Yes, correct!

WalkYourStyle
Navigator
473 57 78

This is an accepted solution.

Follow the below instructions:
1) In your theme's code in the snippets folder open the file 'card-product.liquid'

2) In the above file search for this piece of code that is located at around line 130 and it's below a <span> element with id that starts with
'NoMediaStandardBadge'

{{- 'products.product.sold_out' | t -}}

3) Replace the above code with this one:

{% assign archive_found = false %}
    {% for tag in card_product.tags %}
         {% if archive_found == false and tag contains 'ARCHIVE'%}
              ARCHIVE
              {% assign archive_found = true %}
         {% endif %}
    {% endfor %}
{% if archive_found == false %}
    {{- 'products.product.sold_out' | t -}}
{% endif %}
lsvvintage
Excursionist
42 2 4

Hi!

 

Thanks for your reply! I've tried, but do not see a difference yet. Here is a screenshot of my code:

Did I do something wrong?

Scherm­afbeelding 2025-01-22 om 18.47.43.png

WalkYourStyle
Navigator
473 57 78

Make sure that you indeed have 'ARCHIVE' as a tag in those products all uppercase

lsvvintage
Excursionist
42 2 4

ah, that was the problem! now it works!! thank you very very much, you're a lifesaver!