shopify 产品列表页显示-优惠价格,节省金额和优惠百分比
如果优惠金额大于10显示金额,小于10显示百分比
{% assign savings_amount = product.compare_at_price | minus: product.price %}
{%- if savings_amount > 1000 -%}
{{ product.compare_at_price | minus: product.price | money }}<span style="padding-left:3px;">OFF</span>
{%- else -%}
{{ product.compare_at_price | minus: product.price | times: 100.0 | divided_by: product.compare_at_price | round }}%<span style="padding-left:3px;">OFF</span>
{%- endif -%}
方法1、直接输出
{{ product.compare_at_price | minus: product.price | money }}
{{ product.compare_at_price | minus: product.price | times: 100.0 | divided_by: product.compare_at_price | round }}%
方法2、或者如下,先声明字段,再引用
{%- liquid
assign savings_percentage = compare_at_price | minus: price | times: 100 | divided_by: compare_at_price
assign savings_amount = compare_at_price | minus: price | money
%}
{{ savings_percentage }}%
{{ savings_amount }}
方法3、先判断选择再输出
{%- liquid
if label_count < 2 and settings.prod_reduction_show and cheapest_variant.compare_at_price > cheapest_variant.price
if settings.prod_reduction_type == 'percent'
assign amount = 1.0 | times: cheapest_variant.price | divided_by: cheapest_variant.compare_at_price
assign amount = 1.0 | minus: amount
assign amount = amount | times: 100.0 | round
assign sale_label_text = 'products.labels.percent_reduction' | t: amount: amount
else
assign amount = cheapest_variant.compare_at_price | minus: cheapest_variant.price | money
assign sale_label_text = 'products.labels.value_reduction_html' | t: amount: amount
endif
assign label_count = label_count | plus: 1
endif
-%}
{%- if sale_label_text -%}
<span class="product-label product-label--sale">
<span>{{ sale_label_text }}</span>
</span>
{%- endif -%}
下面的代码来自shopify社区,计算有错误
Product Price: {{ product.price | money }}
Compare Retail Price: {{ product.compare_at_price_max | money }}
You save: {{ product.compare_at_price_max | minus:product.price | difference:product.compare_at_price_max | money }}
You save: {{ product.compare_at_price_max | minus:product.price | times:100 | divided_by:product.compare_at_price_max }}%
显示价格,比较零售价格,节省金额和百分比 – Shopify 社区