Hi guys,
I have a question. I would like to add a price tag that says how much people save when they add a product to their cart that’s on sale. I have attached an example, which is actually an ‘automatic discount’ that applied to the cart. I just want to implement this for every product that people add to their cart when it is on sale.
Besides that, I would like to create a:
And then the CHECK OUT button right underneath.
Is there someone that understands my request and wants to help me with this?
FYI I am using the refresh theme.
Hi @theoofys
If you have already had a regular subtotal variable, create a variable save price = regular subtotal - original subtotal and then put it in the HTML tag displayed on the storefront:
//save_total_price represents the saving price, regular_total_price represents the price that has not decreased,
cart.total_price is usually the subtotal price variable on Shopify
{%- assign save_total_price = regular_total_price | minus cart.total_price -%}
// display on storefront
Saving price: {{ save_total_price | money_with_currency }}
If you’re running a B2B business, then you can consider using B2B/Wholesales Solution app to customize prices with the Custom Pricing module.
I hope that it’s useful to you.
Hello,
Unfortunately I dont quite understand your feedback.
This is how my add to cart page currently looks
Hi @theoofys
You can handle it in the following way:
- Find the file containing the cart page template (usually cart-template.liquid main-cart.liquid), then find the code:
{%- for item in cart.items -%}
or with some other theme is:
{%- for line_item ...
Then, you add this code:
// the code below creates a regular price variable (total_cart_compare_price)
// if the theme uses the line_item variable instead of the item, just change the item variable in the code below to line_item
{%- assign total_cart_compare_price = 0 -%}
{%- for item in cart.items -%}
{%- if item.product.selected_or_first_available_variant.compare_at_price > item.original_price -%}
{% assign item_final_price = item.product.selected_or_first_available_variant.compare_at_price | times: item.quantity %}
{% assign total_cart_compare_price = total_cart_compare_price | plus: item_final_price %}
{%- else -%}
{% assign item_final_price = item.original_price | times: item.quantity %}
{% assign total_cart_compare_price = total_cart_compare_price | plus: item_final_price %}
{%- endif -%}
Display the regular price and saving price, put the following code anywhere on the cart page that you want to display (you can put the class name in the tag to style it as you like):
Regular Price: {{ total_cart_compare_price | money_with_currency }}
Saving Price: {{ total_cart_compare_price | minus: cart.total_price | money_with_currency }}
The result is:
I hope that it works for you.
1 Like