Liquid、JavaScriptなどに関する質問
割引前価格と販売価格(割引適用後価格)を商品ごとに入力したものに対して、「●%OFF」という表示が出るようにしたく、スぺニットの「product-item.liquid」内の
{%- if product.available -%} 部分に以下
{%- if product.compare_at_price > product.price -%}
<span class="ProductItem__Label ProductItem__Label--onSale Heading Text--subdued">{{ 'product.labels.on_sale' | t }}</span>
<!-- 割引率表示の追加 -->
{% assign discount = product.compare_at_price | minus: product.price %}
{% assign discount_percentage = discount | divided_by: product.price | times: 100 | round %}
<span class="ProductItem__Label ProductItem__Label--discount Heading Text--subdued">{{ discount_percentage }}% OFF</span>
{%- endif -%}
{%- else -%}
<span class="ProductItem__Label ProductItem__Label--soldOut Heading Text--subdued">{{ 'product.labels.sold_out' | t }}</span>
{%- endif -%}
というような形で<!-- 割引率表示の追加 -->以下4行を追加しました。
また、CSS部分に色の設定なども施していて、%表記まではきちんと出るのですが、0%という表示になってしまいます。
解決策をご教示いただきたいです。よろしくお願いいたします。
はじめまして、Takaseと申します。
おそらくですが、割引率の計算に問題があるように思われます。
割引率は下記の計算で出すことができます。
いつもShopifyをご利用いただき、ありがとうございます。 Shopifyは、皆様の日本語での利用体験の向上に努めております。さらなる改善のために皆様のご意見をお寄せい...
By JasonH May 9, 2025Shopify アカデミーの学習パスと認定スキルバッジExpanding Your Shopify Business Internationallyを活用して、国際的にビジネ...
By Shopify Feb 7, 2025Shopify アカデミーの学習パスB2B on Shopify:立ち上げとカスタマイズで卸売販売に進出しましょう。これら3つの無料コースは、ShopifyストアでB2B機能...
By Shopify Jan 31, 2025