用于显示销售百分比的 Shopify 功能不起作用



>我有一个函数,它应该显示价格偏离了多少个百分点,而是显示-0 %

到目前为止,我所拥有的是这个

{% if settings.use_saleoff and variant_tmp.compare_at_price > variant_tmp.price %}
<span>{{'products.product.sale' | t}}</span>
<span class="price_percentage">-{{ variant_tmp.compare_at_price | minus: variant_tmp.price | times: 100.0 | divided_by: variant_tmp.compare_at_price | money_without_currency | times: 100 | remove: '.0'}}%</span>
{% endif %}

知道这里出了什么问题吗?

这是正确的方法:

{% if settings.use_saleoff and variant_tmp.compare_at_price > variant_tmp.price %}
<span>{{'products.product.sale' | t}}</span>
<span class="price_percentage">{{ 1.00 | times: variant_tmp.price | divided_by: variant_tmp.compare_at_price | times: 100 | round | minus: 100 }}%</span>
{% endif %}

在第一点,您必须显示该数字将具有小数点。

此外,您还有money_without_currency,它将添加类似$100 USD的内容,之后字母将破坏数学逻辑。

最新更新