![セール商品割引率(%OFF)を表示](http://tomohearts-web.com/cdn/shop/articles/OFF.jpg?v=1719327468&width=1100)
![](http://tomohearts-web.com/cdn/shop/files/108_20240326232013.png?v=1711463710&width=300)
セール中の商品、割引前後の価格が書いてあるけど、どれくらい安いかわかりにくいな...
「%OFF」とか割引率が書いてあるとよいな!割引率を表示させるカスタマイズ方法を教えよう!
![](http://tomohearts-web.com/cdn/shop/files/10_20231215135218.png?v=1702619060&width=300)
目次
最終のコード
{% if per_off %}
{%- liquid
assign float_compare_at_price = cheapest_variant.compare_at_price | times: 1.0
assign per_sale = cheapest_variant.price | divided_by: float_compare_at_price
assign float_per_off = 1 | minus: per_sale
assign per_off = float_per_off | times: 100 | round
-%}
<span class="theme-money" style="margin-left: 5px;">
{{ per_off }}%OFF
</span>
{% endif %}
やりたいこと
表示したい場所を探す
コードの解説
まとめ
参考にしたサイト