Categories
Shopify功能开发

shopify 产品列表页显示比较零售价,节省金额和百分比

方法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.c犀利士
ompare_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 -%}
    
      {{ sale_label_text }}
    
  {%- 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 社区

 

a1c983fc33860cfd404a964d42f28d1e-2

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

分类