Hello,
I am working on a website and I have a question regarding the cart page.
In my store, we have 3 products, :
- 2 of the products are individuals with current price only NO compare price.
- the third product is a bundle and it has a before price and current price therefore it activates (compare-at-price)
Next is an image to show an example for the cart having the two types or prices:
The following image has numbering to ease my explanation for the question:
I want to dynamically display the difference between the numbers in (1), based on the above image I want to display 600 inside (3) or exactly after the text “You’re saving”.
a few notes on this before I show the codes:
- 2 is a subtotal snippet that will update on changing quantity of items in the cart, the subtotal number updates and works properly:
- I want to display the value in (3) for each item that has a compare price to it, with that said, the third product does have variants and the variants will show up as individual cart item.
With that said I will introduce the codes for all relevant sections.
1. Code for the cart itself (cart.liquid) :
{%- liquid
assign hide_quantity = 'quantity--hide'
if settings.cart_show_quantity
assign hide_quantity = ''
endif
assign ajax_disable = false
assign no_ajax_class = ''
if settings.cart_style == 'compatible'
assign ajax_disable = true
assign no_ajax_class = 'no--ajax'
endif
assign full_init = ''
assign empty_init = 'cart--hidden'
if cart.item_count == 0
assign empty_init = ''
assign full_init = 'cart--hidden'
endif
-%}
{% comment %} Cart is empty {% endcomment %}
{% render 'cart-empty' %}
{% comment %} Cart is full {% endcomment %}
2. Code for the line.item (all thiv surrounding (1)):
{%- assign pair_products_index = '' -%}
{%- assign cart_products = '' -%}
{% for line_item in cart.items %}
{{ line_item.product.title }}
{% comment %} Vendor if enabled {% endcomment %}
{% if settings.cart_vendor_enable %}
{{ line_item.vendor }}
{% endif %}
{% comment %} Variant as name/name/name {% endcomment %}
{% unless line_item.product.has_only_default_variant %}
{{ line_item.variant.title }}
{% endunless %}
{% comment %} Subscription plan name {% endcomment %}
{% if line_item.selling_plan_allocation %}
{{ line_item.selling_plan_allocation.selling_plan.name }}
{%- endif -%}
{% comment %} Line item properties, including files {% endcomment %}
{% assign property_size = line_item.properties | size %}
{%- if property_size > 0 -%}
{%- for p in line_item.properties -%}
{%- assign property_first_char = p.first | slice: 0 -%}
{%- if p.last != blank and property_first_char != '_' -%}
{{ p.first }}:
{%- if p.last contains '/uploads/' -%}
{{ p.last | split: '/' | last }}
{%- else -%}
{{ p.last }}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- assign discounted = false -%}
{%- if line_item.original_price > line_item.final_price -%}
{%- assign discounted = true -%}
{%- endif -%}
{%- assign sale = false -%}
{%- if line_item.variant.compare_at_price > line_item.variant.price -%}
{%- assign sale = true -%}
{%- endif -%}
{% assign quantity-multiplier = line_item.quantity %}
{%- if sale -%}
<del>was {{ line_item.variant.compare_at_price | times: quantity-multiplier | money}}</del>
{%- endif -%}
{%- if discounted -%}
<del>was {{ line_item.original_price | times: quantity-multiplier | money }}</del>
{%- endif -%}
{%- if sale or discounted -%}
<mark>{{ line_item.final_price | times: quantity-multiplier | money }}</mark>
{%- else -%}
{{ line_item.final_price | times: quantity-multiplier | money }}
{%- endif -%}
{% if line_item.unit_price %}
{% capture unit_price_separator %}
/{{ 'general.accessibility.unit_price_separator' | t }}
{% endcapture %}
{% capture unit_price_base_unit %}
{% if line_item.unit_price_measurement.reference_value != 1 %}
{{ line_item.unit_price_measurement.reference_value }}
{% endif %}
{{ line_item.unit_price_measurement.reference_unit }}
{% endcapture %}
{{ 'products.product.unit_price_label' | t }}
{{ line_item.unit_price | money }}{{ unit_price_separator }}{{ unit_price_base_unit }}
{% endif %}
{% assign single-prouct-price = line_item.original_price %}
{% assign multiplier = single-prouct-price | times: quantity-multiplier %}
{%- render 'icon-bin' -%}
{% render 'cart-expand', product: line_item.product %}
{% if discounted and line_item.quantity >= 1 %}
{%- for discount in line_item.line_level_discount_allocations -%}
{% render 'icon-tags' %}
{{ 'cart.general.savings' | t }}
{{ discount.amount | money_without_trailing_zeros }}
{{ 'cart.general.with' | t }}
{{ discount.discount_application.title }}
{%- endfor -%}
{% endif %}
{%- assign cart_products = cart_products | append: line_item.product.id | append: ',' -%}
{%- assign upsell = line_item.product.metafields.theme.upsell -%}
{%- if upsell.value != nil and upsell.type == 'product_reference' -%}
{%- assign pair_products_index = pair_products_index | append: forloop.index0 | append: ',' -%}
{%- endif -%}
{% endfor %}
{%- if pair_products_index != '' -%}
{%- assign pair_products_index = pair_products_index | split: ',' -%}
{%- assign cart_products = cart_products | prepend: ',' -%}
{%- for index in pair_products_index -%}
{%- assign arr_index = index | plus: 0 -%}
{%- assign upsell_product = cart.items[arr_index].product.metafields.theme.upsell.value -%}
{%- if cart_products contains upsell_product.id or upsell_product.available == false -%}
{%- continue -%}
{%- endif -%}
{%- render 'upsell-product' upsell_product: upsell_product -%}
{%- break -%}
{%- endfor -%}
{%- endif -%}
3. Code for the cart subtotal section (2):
{%- if cart.cart_level_discount_applications.size >= 0 -%}
Your cart
{{ cart.total_price | money }}
You're saving
{%- endif -%}
The aim of this is to show to the customer the amount off money they are saving just by buying the bundle product.

