Liquid Snippets by ALSEL
🛍️ 商品表示中級

商品カード

コレクションページや商品リストで使う商品カード。商品画像、タイトル、評価、価格、SALE・売切バッジを表示し、オプションで「カートに追加」ボタンも表示できる。

用途
コレクションページ、関連商品セクション、検索結果など商品一覧を表示するあらゆる場面で使用する。
設置場所
snippets/product-card.liquid に配置し、コレクションテンプレートやセクション内で `{% render 'product-card', product: product %}` で呼び出す。
注意点
SALE バッジはストア管理画面で各バリアントに比較価格を入力していることが前提。割引表示のタイプ(パーセンテージ or 金額)はテーマカスタマイザーの設定値を参照するため、先にテーマ設定で `product_card_badge_discount_type` を定義しておく。評価・価格・カートフォームは別スニペット(product-rating-badge、product-card-price、product-card-form)に依存しているため、これら3つのスニペットが別途存在することが必要。
タグ:productcardbadgesalecollection

コード

49 行 / liquid
{% comment %}
  Renders a product card within a product list. Usually within a collection template or the Product list section

  Accepts:
  - product: {object} The product object - https://shopify.dev/docs/api/liquid/objects/product

  Usage:
  {% render 'product-card' product: product  %}
{% endcomment %}

<div class="product-card {{ settings.product_card_text_align }}">
  <a 
    href="{{ product.url | within: collection }}" 
    class="product-card-link">
    <div class="product-card-img-wrapper mb-4">      
      {% if product.available == false %}
        <span class="product-sold-out-badge badge"
          {% if current_variant.available %}hidden{% endif %}>
          {{ 'product.sold_out' | t }}
        </span>  
      {% elsif product.compare_at_price > product.price %}
        <span 
          class="product-sale-badge badge"
          data-discount-type="{{ settings.product_card_badge_discount_type }}"> 
          {% if product.compare_at_price > 0 %}
            {% if settings.product_card_badge_discount_type == 'percentage' %} 
              <span class="visually-hidden">
                {{ 'product.save' | t }} 
              </span>
              {{ product.compare_at_price | minus: product.price | times: 100 | divided_by: product.compare_at_price | round | prepend: '-' | append: '%' }}
            {% else %}
              {{ 'product.save' | t }} 
              {{ product.compare_at_price | minus: product.price | money_without_trailing_zeros }}
            {% endif %}
          {% endif %}
        </span>
      {% endif %}
      {% render 'image-url', img: product.featured_image, orientation: settings.product_card_img_orientation, class: settings.product_card_img_border %}
    </div>
    <h3 class="product-card-title product-title {{ settings.product_card_title_font_size }}">
      {{ product.title }}
    </h3>
    {% render 'product-rating-badge', product: product %}
    {% render 'product-card-price', product: product %}
  </a>
  {% if settings.product_card_show_atc_form %}
    {% render 'product-card-form', product: product %}
  {% endif %}
</div>

出典・ライセンス

License:
MIT

このコードは kondasoft 著作の MIT ライセンスソースです。 原本の著作権は kondasoft が保有します。日本語訳は ALSEL によるものです。

関連項目

🛍️ 商品表示上級

商品ブロック内のLiquid実行

セクションブロック内で管理画面から入力した Liquid コードを直接実行し、パディング設定で上下の余白を制御するスニペット。テーマカスタマイザーでコード記述が可能。

📁 ks-bootshop·MIT·8
🛍️ 商品表示初級

商品ページの見出し

商品詳細ページの商品名を h1 見出しで表示するブロック。テーマカスタマイザーから見出しサイズと上下の余白(padding)を調整できる。

📁 ks-bootshop·MIT·8
🛍️ 商品表示中級

商品レビューバッジの表示

Loox と JudgeMe 両方のレビュー集約アプリに対応したレーティングバッジを商品ページに埋め込む。メタフィールドから平均評価とレビュー数を取得し、各アプリの UI コンポーネントを描画する。

📁 ks-bootshop·MIT·9
🛍️ 商品表示中級

定期販売プランのデータ属性を動的に生成

商品の定期販売プラン(Selling Plans)をループで取得し、data 属性として HTML に埋め込むスニペット。JavaScript で定期販売オプションを制御するためのデータ基盤として機能する。

📁 theme-tools·MIT·10
🛍️ 商品表示初級

商品ページの区切り線

商品詳細ページで、セクション間に区切り線を挿入するブロック。パディング、高さ、背景色、透明度をカスタマイズできる。

📁 ks-bootshop·MIT·15
🛍️ 商品表示初級

商品画像のプリロード出力

商品オブジェクトから image_tag フィルターを使い、preload 属性付きで画像を出力するスニペット。複数商品のループ内でも使える基本的なパターン。

📁 theme-tools·MIT·16