Final sale verbiage on the cart page

Highlighted
Tourist
28 0 1

Hi there,

 

I'm trying to write a statement that hides/shows a "*Final Sale" <p> tag based on whether a product is on sale/tagged with "FINAL SALE" on the cart page. I'm not sure if there is a way to check the product.tags for an item in the cart, but if there is I'd like to know. 

I have tried a few different statements that have not worked so I wanted some input from all you smart people on this forum. 

{% for item in cart.items %}
            	{% if item.line_price > item.original_line_price %}
            		<div style="float: left; width: 100%;">
                               <p style="font-size: 11px; color: red;">*Final Sale</p>
            		</div>
            	{% endif %}
{% endfor %}
{% for item in cart.items %}
            	{% if product.tags contains "FINAL SALE" %}
            		<div style="float: left; width: 100%;">
                      <p style="font-size: 11px; color: red;">*Final Sale</p>
            		</div>
            	{% endif %}
{% endfor %}

Anyone have any suggestions?

0 Likes
Highlighted
Shopify Expert
1380 112 211

Hello,
Hope you are doing well.

We have gone through your requirements and we would love to help you.

in the collections template, add a Sale DIV if you have set a compare at price. LIke this:

{% if product.compare_at_price_max > product.price %}<div class="sale-badge">On Sale</div>{% endif %}*

 

So the full block looks something like this:

   <div class="gallery-image">{% if product.compare_at_price_max > product.price %}<div class="sale-badge">On Sale</div>{% endif %}<a href="{{ product.url | within: collection }}" title="{{ product.title | escape }} &mdash; {{ product.description | strip_html | truncate: 50 | escape }}">
<img src="{{ product.images.first | product_img_url: 'medium' }}" alt="{{ product.title | escape }}" /></a>
</div>


 And in your style sheet add:

.sale-badge { 
background-image:url(on-sale-badge.gif);background-position:0 0;background-repeat:no-repeat;height:70px;margin:3px;position:absolute;text-indent:-90em;width:70px;
} 

 

0 Likes
Highlighted
Tourist
28 0 1

Hi,

 

This did not work unfortunately. I believe the syntax that needs to be used starts with 'item.' instead of 'product.' since we are in the cart, but I also tried the below and that didn't work either. 

 

{% for item in cart.items %}
            	{% if item.compare_at_price_max > item.price %}
            		<div class="final-sale-note">
                              <p style="font-size: 11px; color: red;">*Final Sale</p>
            		</div>
            	{% endif %}
            {% endfor %}
0 Likes
Highlighted
Tourist
3 0 2

As you are dealing with cart line items (not products), you do not have access to product attributes directly, but what is detailed at: https://shopify.dev/docs/themes/liquid/reference/objects/line_item/

Luckily, the product for a line item can still be accessed, so what you want is:

item.product.compare_at_price_max

I know this is an old topic, but may help someone else who stumbles on to this as I had the same problem and then resolved it myself.

0 Likes