Add modified code
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
# README
|
# README
|
||||||
|
|
||||||
To show discounted price on the collection page, kindly reference the files below (you can navigate from the browser UI above)
|
To show discounted price on the collection page, kindly reference the files below (you can navigate from the browser UI above) , you can copy paste the code and replace the existing code on your store theme.
|
||||||
|
|
||||||
|
|
||||||
|
1. snippets/price-list.liquid
|
||||||
|
2. snippets/product-badges.liquid
|
||||||
|
|
||||||
|
|
||||||
The code below is for store specific product page widget configuration reference , you do not need to do anything with the code below.
|
The code below is for store specific product page widget configuration reference , you do not need to do anything with the code below.
|
||||||
|
|||||||
+98
-25
@@ -41,30 +41,77 @@ Supported variables
|
|||||||
-%}
|
-%}
|
||||||
|
|
||||||
<price-list class="price-list {% if size == 'lg' %}price-list--lg{% endif %} {% if text_alignment == 'center' %}justify-center{% endif %}">
|
<price-list class="price-list {% if size == 'lg' %}price-list--lg{% endif %} {% if text_alignment == 'center' %}justify-center{% endif %}">
|
||||||
|
{%- liquid
|
||||||
|
assign product_price = product.price
|
||||||
|
assign product_price_min = product.price_min
|
||||||
|
assign product_price_max = product.price_max
|
||||||
|
assign product_compare_at_price = product.compare_at_price
|
||||||
|
if product.metafields.app--168074346497.discount_percentage.value > 0.01
|
||||||
|
assign deducted_percentage = 1.0 | minus: product.metafields.app--168074346497.discount_percentage.value
|
||||||
|
assign product_price = product.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil
|
||||||
|
assign product_price_min = product_price
|
||||||
|
assign product_price_max = product.price_max | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil
|
||||||
|
assign product_compare_at_price = product.price
|
||||||
|
if product.compare_at_price > product_compare_at_price
|
||||||
|
assign product_compare_at_price = product.compare_at_price
|
||||||
|
endif
|
||||||
|
elsif product.metafields.app--168074346497.min_auto_discounted_price.value > 0.01
|
||||||
|
assign product_price = product.metafields.app--168074346497.min_auto_discounted_price.value
|
||||||
|
assign product_price_min = product_price
|
||||||
|
assign product_compare_at_price = product.price
|
||||||
|
if product.compare_at_price > product_compare_at_price
|
||||||
|
assign product_compare_at_price = product.compare_at_price
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
-%}
|
||||||
{%- if variant != blank -%}
|
{%- if variant != blank -%}
|
||||||
|
{%- liquid
|
||||||
|
assign variant_price = variant.price
|
||||||
|
assign variant_compare_at_price = variant.price
|
||||||
|
|
||||||
|
if variant.metafields.app--168074346497.discount_type.value != nil and variant.metafields.app--168074346497.discount_type.value != "fixed" and product.metafields.app--168074346497.discount_percentage.value > 0.01
|
||||||
|
assign deducted_percentage = 1.0 | minus: product.metafields.app--168074346497.discount_percentage.value
|
||||||
|
|
||||||
|
if variant.metafields.app--168074346497.discount_percentage.value > 0.01
|
||||||
|
assign deducted_percentage = 1.0 | minus: variant.metafields.app--168074346497.discount_percentage.value
|
||||||
|
endif
|
||||||
|
|
||||||
|
assign variant_price = variant.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil
|
||||||
|
assign variant_compare_at_price = variant.price
|
||||||
|
if variant.compare_at_price > variant_compare_at_price
|
||||||
|
assign variant_compare_at_price = variant.compare_at_price
|
||||||
|
endif
|
||||||
|
elsif variant.metafields.app--168074346497.discount_type.value == "fixed"
|
||||||
|
assign variant_price = variant.metafields.app--168074346497.auto_discounted_price.value
|
||||||
|
assign variant_compare_at_price = variant.price
|
||||||
|
if variant.compare_at_price > variant_compare_at_price
|
||||||
|
assign variant_compare_at_price = variant.compare_at_price
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
-%}
|
||||||
{%- comment -%}
|
{%- comment -%}
|
||||||
--------------------------------------------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------------------------------------------
|
||||||
VARIANT CASE (used on product page, quick view...)
|
VARIANT CASE (used on product page, quick view...)
|
||||||
--------------------------------------------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------------------------------------------
|
||||||
{%- endcomment -%}
|
{%- endcomment -%}
|
||||||
<sale-price class="{% if variant.compare_at_price > variant.price %}{{ on_sale_price_classes }}{% else %}{{ regular_price_classes }}{% endif %}">
|
<sale-price class="{% if variant_compare_at_price > variant_price %}{{ on_sale_price_classes }}{% else %}{{ regular_price_classes }}{% endif %}">
|
||||||
<span class="sr-only">{{ 'product.price.sale_price' | t }}</span>
|
<span class="sr-only">{{ 'product.price.sale_price' | t }}</span>
|
||||||
|
|
||||||
{%- if settings.currency_code_enabled -%}
|
{%- if settings.currency_code_enabled -%}
|
||||||
{{- variant.price | money_with_currency -}}
|
{{- variant_price | money_with_currency | replace: 'MYR', '' -}}
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
{{- variant.price | money | replace: 'MYR', '' -}}
|
{{- variant_price | money | replace: 'MYR', '' -}}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
</sale-price>
|
</sale-price>
|
||||||
|
|
||||||
{%- if variant.compare_at_price > variant.price -%}
|
{%- if variant_compare_at_price > variant_price -%}
|
||||||
<compare-at-price class="{{ compare_at_price_classes }}">
|
<compare-at-price class="{{ compare_at_price_classes }}">
|
||||||
<span class="sr-only">{{ 'product.price.regular_price' | t }}</span>
|
<span class="sr-only">{{ 'product.price.regular_price' | t }}</span>
|
||||||
|
|
||||||
{%- if settings.currency_code_enabled -%}
|
{%- if settings.currency_code_enabled -%}
|
||||||
{{- variant.compare_at_price | money_with_currency -}}
|
{{- variant_compare_at_price | money_with_currency | replace: 'MYR', '' -}}
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
{{- variant.compare_at_price | money | replace: 'MYR', '' -}}
|
{{- variant_compare_at_price | money | replace: 'MYR', '' -}}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
</compare-at-price>
|
</compare-at-price>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
@@ -78,7 +125,7 @@ Supported variables
|
|||||||
<span class="sr-only">{{ 'product.price.sale_price' | t }}</span>
|
<span class="sr-only">{{ 'product.price.sale_price' | t }}</span>
|
||||||
|
|
||||||
{%- if settings.currency_code_enabled -%}
|
{%- if settings.currency_code_enabled -%}
|
||||||
{{- line_item.final_line_price | money_with_currency -}}
|
{{- line_item.final_line_price | money_with_currency | replace: 'MYR', '' -}}
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
{{- line_item.final_line_price | money | replace: 'MYR', '' -}}
|
{{- line_item.final_line_price | money | replace: 'MYR', '' -}}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
@@ -89,7 +136,7 @@ Supported variables
|
|||||||
<span class="sr-only">{{ 'product.price.regular_price' | t }}</span>
|
<span class="sr-only">{{ 'product.price.regular_price' | t }}</span>
|
||||||
|
|
||||||
{%- if settings.currency_code_enabled -%}
|
{%- if settings.currency_code_enabled -%}
|
||||||
{{- line_item.original_line_price | money_with_currency -}}
|
{{- line_item.original_line_price | money_with_currency | replace: 'MYR', '' -}}
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
{{- line_item.original_line_price | money | replace: 'MYR', '' -}}
|
{{- line_item.original_line_price | money | replace: 'MYR', '' -}}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
@@ -104,22 +151,48 @@ Supported variables
|
|||||||
{%- if product.price_varies and product.compare_at_price -%}
|
{%- if product.price_varies and product.compare_at_price -%}
|
||||||
{%- assign cheapest_variant = product.variants | sort: 'price' | first -%}
|
{%- assign cheapest_variant = product.variants | sort: 'price' | first -%}
|
||||||
|
|
||||||
|
{%- liquid
|
||||||
|
assign cheapest_variant_price = cheapest_variant.price
|
||||||
|
assign cheapest_variant_compare_at_price = cheapest_variant.price
|
||||||
|
|
||||||
|
if cheapest_variant.metafields.app--168074346497.discount_type.value != nil and cheapest_variant.metafields.app--168074346497.discount_type.value != "fixed" and product.metafields.app--168074346497.discount_percentage.value > 0.01
|
||||||
|
assign deducted_percentage = 1.0 | minus: product.metafields.app--168074346497.discount_percentage.value
|
||||||
|
|
||||||
|
if cheapest_variant.metafields.app--168074346497.discount_percentage.value > 0.01
|
||||||
|
assign deducted_percentage = 1.0 | minus: cheapest_variant.metafields.app--168074346497.discount_percentage.value
|
||||||
|
endif
|
||||||
|
|
||||||
|
assign cheapest_variant_price = cheapest_variant.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil
|
||||||
|
assign cheapest_variant_compare_at_price = cheapest_variant.price
|
||||||
|
if cheapest_variant.compare_at_price > cheapest_variant_compare_at_price
|
||||||
|
assign cheapest_variant_compare_at_price = cheapest_variant.compare_at_price
|
||||||
|
endif
|
||||||
|
elsif cheapest_variant.metafields.app--168074346497.discount_type.value == "fixed"
|
||||||
|
assign cheapest_variant_price = cheapest_variant.metafields.app--168074346497.auto_discounted_price.value
|
||||||
|
assign cheapest_variant_compare_at_price = cheapest_variant.price
|
||||||
|
if cheapest_variant.compare_at_price > cheapest_variant_compare_at_price
|
||||||
|
assign cheapest_variant_compare_at_price = cheapest_variant.compare_at_price
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
-%}
|
||||||
|
|
||||||
{%- capture price_min -%}
|
{%- capture price_min -%}
|
||||||
{%- if settings.currency_code_enabled -%}
|
{%- if settings.currency_code_enabled -%}
|
||||||
{{- cheapest_variant.price | money_with_currency -}}
|
{{- cheapest_variant_price | money_with_currency | replace: 'MYR', '' -}}
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
{{- cheapest_variant.price | money | replace: 'MYR', '' -}}
|
{{- cheapest_variant_price | money | replace: 'MYR', '' -}}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{%- endcapture -%}
|
{%- endcapture -%}
|
||||||
|
|
||||||
{%- if cheapest_variant.price < cheapest_variant.compare_at_price -%}
|
{%- if cheapest_variant_price < cheapest_variant_compare_at_price -%}
|
||||||
|
|
||||||
<compare-at-price class="{{ compare_at_price_classes }}">
|
<compare-at-price class="{{ compare_at_price_classes }}">
|
||||||
<span class="sr-only">{{ 'product.price.regular_price' | t }}</span>
|
<span class="sr-only">{{ 'product.price.regular_price' | t }}</span>
|
||||||
|
|
||||||
{%- if settings.currency_code_enabled -%}
|
{%- if settings.currency_code_enabled -%}
|
||||||
{{- cheapest_variant.compare_at_price | money_with_currency -}}
|
{{- cheapest_variant_compare_at_price | money_with_currency | replace: 'MYR', '' -}}
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
{{- cheapest_variant.compare_at_price | money | replace: 'MYR', '' -}}
|
{{- cheapest_variant_compare_at_price | money | replace: 'MYR', '' -}}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
</compare-at-price>
|
</compare-at-price>
|
||||||
|
|
||||||
@@ -133,41 +206,41 @@ Supported variables
|
|||||||
{{- 'product.price.from_price_html' | t: price_min: price_min -}}
|
{{- 'product.price.from_price_html' | t: price_min: price_min -}}
|
||||||
</sale-price>
|
</sale-price>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{%- elsif product.price < product.compare_at_price -%}
|
{%- elsif product_price < product_compare_at_price -%}
|
||||||
<compare-at-price class="{{ compare_at_price_classes }}">
|
<compare-at-price class="{{ compare_at_price_classes }}">
|
||||||
<span class="sr-only">{{ 'product.price.regular_price' | t }}</span>
|
<span class="sr-only">{{ 'product.price.regular_price' | t }}</span>
|
||||||
|
|
||||||
{%- if settings.currency_code_enabled -%}
|
{%- if settings.currency_code_enabled -%}
|
||||||
{{- product.compare_at_price | money_with_currency -}}
|
{{- product_compare_at_price | money_with_currency | replace: 'MYR', '' -}}
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
{{- product.compare_at_price | money | replace: 'MYR', '' -}}
|
{{- product_compare_at_price | money | replace: 'MYR', '' -}}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
</compare-at-price>
|
</compare-at-price>
|
||||||
|
|
||||||
<sale-price class="{{ on_sale_price_classes }}">
|
<sale-price class="{{ on_sale_price_classes }}">
|
||||||
<span class="sr-only">{{ 'product.price.sale_price' | t }}</span>
|
<span class="sr-only">{{ 'product.price.sale_price' | t }}</span>
|
||||||
|
|
||||||
{%- if settings.currency_code_enabled -%}
|
{%- if settings.currency_code_enabled -%}
|
||||||
{{- product.price | money_with_currency -}}
|
{{- product_price | money_with_currency | replace: 'MYR', '' -}}
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
{{- product.price | money | replace: 'MYR', '' -}}
|
{{- product_price | money | replace: 'MYR', '' -}}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
</sale-price>
|
</sale-price>
|
||||||
|
|
||||||
|
|
||||||
{%- elsif product.price_varies -%}
|
{%- elsif product.price_varies -%}
|
||||||
{%- capture price_min -%}
|
{%- capture price_min -%}
|
||||||
{%- if settings.currency_code_enabled -%}
|
{%- if settings.currency_code_enabled -%}
|
||||||
{{ product.price_min | money_with_currency | replace: 'MYR', ''}}
|
{{ product_price_min | money_with_currency | replace: 'MYR', '' }}
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
{{ product.price_min | money | replace: 'MYR', '' }}
|
{{ product_price_min | money | replace: 'MYR', '' }}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{%- endcapture -%}
|
{%- endcapture -%}
|
||||||
|
|
||||||
{%- capture price_max -%}
|
{%- capture price_max -%}
|
||||||
{%- if settings.currency_code_enabled -%}
|
{%- if settings.currency_code_enabled -%}
|
||||||
{{- product.price_max | money_with_currency -}}
|
{{- product_price_max | money_with_currency | replace: 'MYR', '' -}}
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
{{- product.price_max | money | replace: 'MYR', '' -}}
|
{{- product_price_max | money | replace: 'MYR', '' -}}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
{%- endcapture -%}
|
{%- endcapture -%}
|
||||||
|
|
||||||
@@ -180,9 +253,9 @@ Supported variables
|
|||||||
<span class="sr-only">{{ 'product.price.sale_price' | t }}</span>
|
<span class="sr-only">{{ 'product.price.sale_price' | t }}</span>
|
||||||
|
|
||||||
{%- if settings.currency_code_enabled -%}
|
{%- if settings.currency_code_enabled -%}
|
||||||
{{- product.price | money_with_currency -}}
|
{{- product_price | money_with_currency | replace: 'MYR', '' -}}
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
{{- product.price | money | replace: 'MYR', '' -}}
|
{{- product_price | money | replace: 'MYR', '' -}}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
</sale-price>
|
</sale-price>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
|
|||||||
@@ -46,25 +46,59 @@ Supported variables
|
|||||||
|
|
||||||
{%- when 'discount' -%}
|
{%- when 'discount' -%}
|
||||||
{%- if settings.show_discount -%}
|
{%- if settings.show_discount -%}
|
||||||
|
{%- liquid
|
||||||
|
assign variant_price = variant.metafields.app--168074346497.auto_discounted_price.value | default: variant.price
|
||||||
|
|
||||||
|
if variant.metafields.app--168074346497.discount_type.value != nil and variant.metafields.app--168074346497.discount_type.value != "fixed" and product.metafields.app--168074346497.discount_percentage.value > 0.01
|
||||||
|
assign deducted_percentage = 1.0 | minus: product.metafields.app--168074346497.discount_percentage.value
|
||||||
|
|
||||||
|
if variant.metafields.app--168074346497.discount_percentage.value > 0.01
|
||||||
|
assign deducted_percentage = 1.0 | minus: variant.metafields.app--168074346497.discount_percentage.value
|
||||||
|
endif
|
||||||
|
|
||||||
|
assign variant_price = variant.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil
|
||||||
|
|
||||||
|
assign variant_compare_at_price = variant.price
|
||||||
|
|
||||||
|
if variant.compare_at_price > variant_compare_at_price
|
||||||
|
assign variant_compare_at_price = variant.compare_at_price
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
assign product_price = product.metafields.app--168074346497.min_auto_discounted_price.value | default: product.price
|
||||||
|
|
||||||
|
if product.metafields.app--168074346497.discount_percentage.value > 0.01
|
||||||
|
assign deducted_percentage = 1.0 | minus: product.metafields.app--168074346497.discount_percentage.value
|
||||||
|
|
||||||
|
assign product_price = product.price | divided_by: 100.0 | times: deducted_percentage | times: 100.0 | ceil
|
||||||
|
|
||||||
|
assign product_compare_at_price = product.price
|
||||||
|
|
||||||
|
if product.compare_at_price > product_compare_at_price
|
||||||
|
assign product_compare_at_price = product.compare_at_price
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
-%}
|
||||||
|
|
||||||
{%- liquid
|
{%- liquid
|
||||||
assign show_on_sale_badge = false
|
assign show_on_sale_badge = false
|
||||||
|
|
||||||
if context == 'product'
|
if context == 'product'
|
||||||
if variant.compare_at_price > variant.price
|
if variant_compare_at_price > variant_price
|
||||||
assign show_on_sale_badge = true
|
assign show_on_sale_badge = true
|
||||||
endif
|
endif
|
||||||
elsif context == 'card'
|
elsif context == 'card'
|
||||||
if product.compare_at_price > product.price
|
if product_compare_at_price > product_price
|
||||||
assign show_on_sale_badge = true
|
assign show_on_sale_badge = true
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
-%}
|
-%}
|
||||||
|
|
||||||
{%- if product.compare_at_price > product.price -%}
|
{%- if product_compare_at_price > product_price -%}
|
||||||
{%- if settings.discount_mode == 'percentage' -%}
|
{%- if settings.discount_mode == 'percentage' -%}
|
||||||
{%- assign savings = variant.compare_at_price | minus: variant.price | times: 100.0 | divided_by: variant.compare_at_price | round | append: '%' -%}
|
{%- assign savings = variant_compare_at_price | minus: variant_price | times: 100.0 | divided_by: variant_compare_at_price | round | append: '%' -%}
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
{%- capture savings -%}{{ variant.compare_at_price | minus: variant.price | money }}{%- endcapture -%}
|
{%- capture savings -%}{{ variant_compare_at_price | minus: variant_price | money }}{%- endcapture -%}
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
|
|
||||||
{%- if show_on_sale_badge -%}
|
{%- if show_on_sale_badge -%}
|
||||||
@@ -73,7 +107,7 @@ Supported variables
|
|||||||
if context == 'product'
|
if context == 'product'
|
||||||
echo 'product.general.discount_badge_html' | t: savings: savings
|
echo 'product.general.discount_badge_html' | t: savings: savings
|
||||||
elsif context == 'card'
|
elsif context == 'card'
|
||||||
if product.compare_at_price_varies or variant.compare_at_price == blank
|
if product.compare_at_price_varies or variant_compare_at_price == blank
|
||||||
echo 'product.general.on_sale_badge' | t
|
echo 'product.general.on_sale_badge' | t
|
||||||
else
|
else
|
||||||
echo 'product.general.discount_badge_html' | t: savings: savings
|
echo 'product.general.discount_badge_html' | t: savings: savings
|
||||||
|
|||||||
Reference in New Issue
Block a user