Liquid, JavaScript, themes, sales channels
I hope you're having a good day so far! I've been on this for a couple hours now with a good friend of mine, and regardless what we try it returns the price of the sale. It does the same thing in checkout, what I display below is only in the "View Cart" stage before Initiating Checkout.
I started by trying to enable the display discount functionality in cart-template.liquid, and though it works the striked-out price is incorrect.
As you can see, the compare price is $10 higher than the price and @ cart screen it doesn't show the correct compare at price ($89.99)
Below is the source code:
{%- assign hasDiscount = true -%}
{%- if item.original_price != item.final_price -%}
{%- assign hasDiscount = true -%}
{%- endif -%}
<div data-cart-item-price>
<dl data-cart-item-price-list>
{%- comment -%}
Markup template for discount item
{%- endcomment -%}
<div {% unless hasDiscount %}class="hide" {% endunless %}data-cart-item-discounted-price-group>
<dt>
<span class="visually-hidden">{{ 'products.product.regular_price' | t }}</span>
</dt>
<dd>
<s data-cart-item-original-price>{{ item.original_price | money }}</s>
</dd>
<dt>
<span class="visually-hidden">{{ 'products.product.sale_price' | f }}</span>
</dt>
<dd>
<span class="order-discount" data-cart-item-final-price>{{ item.final_price | money }}</span>
</dd>
</div>
{%- comment -%}
Markup template for regular price item
{%- endcomment -%}
<div {% if hasDiscount %}class="hide" {% endif %}data-cart-item-regular-price-group>
<dt>
<span class="visually-hidden">{{ 'products.product.regular_price' | t }}</span>
</dt>
<dd data-cart-item-regular-price>
{{ item.original_price | money }}
</dd>
</div>
{%- comment -%}
Markup template for unit price
{%- endcomment -%}
<div {% unless item.unit_price_measurement %}class="hide" {% endunless %}data-unit-price-group>
<dt>
<span class="visually-hidden visually-hidden--inline">{{ 'products.product.unit_price_label' | t }}</span>
</dt>
<dd>
<span class="price-unit-price">
{%- capture unit_price_separator -%}
<span aria-hidden="true">/</span><span class="visually-hidden">{{ 'general.accessibility.unit_price_separator' | t }} </span>
{%- endcapture -%}
{%- capture unit_price_base_unit -%}
{%- if item.unit_price_measurement.reference_value != 1 -%}
{{- item.unit_price_measurement.reference_value -}}
{%- endif -%}
{{ item.unit_price_measurement.reference_unit }}
{%- endcapture -%}
<span data-unit-price>{{ item.unit_price | money }}</span>{{- unit_price_separator -}}<span data-unit-price-base-unit>{{- unit_price_base_unit -}}</span>
</span>
</dd>
</div>
</dl>
</div>
Any help would be greatly appreciated!
Andrew
Solved! Go to the solution
This is an accepted solution.
compare_at is not treated as a discount in the same way that an item discounted with a discount code is. You should something like item.variant.compare_at_price, not original_price in your equation for what you are trying to do.
That said, your code is actually working, but only items using discount codes.
You can think of the compare at system as indicating that an item is 'on sale', not 'discounted'.
This is an accepted solution.
compare_at is not treated as a discount in the same way that an item discounted with a discount code is. You should something like item.variant.compare_at_price, not original_price in your equation for what you are trying to do.
That said, your code is actually working, but only items using discount codes.
You can think of the compare at system as indicating that an item is 'on sale', not 'discounted'.
Sweet, thank you, that worked! What's funny is I think I tried that, I just put it in the wrong line.
Would I be able to display the same thing in the checkout section? There it shows only the subtotal, too, and if it could work the same way it did in the cart that'd be fantastic.
Modifying checkout.liquid is only available on the plus plan, if you're on that it should be doable.
Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024Digital marketers and app developers have tracked activity in apps and websites for yea...
By Ollie Mar 13, 2024February was an exciting month with Shopify Editions, informative webinars, and more! F...
By JasonH Mar 7, 2024