🛍️ 商品表示中級
商品ページのカートボタン
商品詳細ページ用のカートボタンコンポーネント。数量調整フィールド、カートに追加ボタン、Apple Pay などの動的決済ボタン、今すぐ購入ボタンを条件付きで表示する。
用途
商品ページの form 内でカート追加機能を提供するときに使用。ブロック設定で各ボタンの表示・非表示、色・サイズを制御できる。
設置場所
snippets/product-block-atc-button.liquid に配置し、sections/main-product.liquid または product form 内で `{% render 'product-block-atc-button', product: product, block: block, form: form %}` で呼び出す。
注意点
数量フィールドのマイナスボタンの disabled 状態は inline onclick で制御されているため、JavaScript が無効な環境では数量が 1 未満になる可能性がある。本番環境では Unobtrusive JavaScript に切り替えて disabled 制御をスクリプト側で管理することを推奨する。動的決済ボタン表示時は `form` オブジェクトが shop.payment_button_branding_include 管理画面設定を参照しているため、該当設定が有効化されていることが前提。バリアントが在庫なしの場合、ボタン全体が disabled になるため、在庫復活時に画面リロード後に再度有効化される。
コード
73 行 / liquid{% liquid
assign current_variant = product.selected_or_first_available_variant
assign pt = block.settings.pt | prepend: 'pt-'
assign pb = block.settings.pb | prepend: 'pb-'
%}
<div
class="product-block-atc {{ pt }} {{ pb }}"
{{ block.shopify_attributes }}>
<div class="d-flex">
{% if block.settings.show_qty_field %}
<div
class="qty-input-wrapper me-4"
role="group"
aria-label="{{ 'general.accessibility.quantity' | t }}">
<button
class="btn btn-qty-minus"
type="button"
onclick="--this.nextElementSibling.value, this.nextElementSibling.value == 1 ? this.disabled = true : ''"
aria-label="{{ 'general.accessibility.decrease_qty' | t }}"
disabled>
{% render 'svg-icons', icon: 'minus', size: 14 %}
</button>
<input
class="form-control {{ block.settings.atc_btn_size | replace: 'btn-', 'form-control-' }}"
name="quantity"
type="number"
value="1"
min="1"
aria-label="{{ 'product.quantity' | t }}">
<button
class="btn btn-qty-plus"
type="button"
onclick="++this.previousElementSibling.value, this.previousElementSibling.previousElementSibling.disabled = false"
aria-label="{{ 'general.accessibility.increase_qty' | t }}">
{% render 'svg-icons', icon: 'plus', size: 14 %}
</button>
</div>
{% endif %}
<button
class="btn btn-atc {{ block.settings.atc_btn_color }} {{ block.settings.atc_btn_size }}"
type="submit"
name="add"
{% unless current_variant.available %}
disabled
{% endunless %}>
{% if current_variant.available %}
{{ 'product.add_to_cart' | t }}
{% else %}
{{ 'product.sold_out' | t }}
{% endif %}
</button>
</div>
{% if block.settings.show_dynamic_buttons %}
<div class="product-dynamic-buttons mt-5 pb-2">
{{ form | payment_button }}
</div>
{% endif %}
{% if block.settings.show_buy_btn %}
<button
class="btn btn-buy mt-4 {{ block.settings.buy_btn_color }} {{ block.settings.buy_btn_size }}"
type="button"
{% unless current_variant.available %}
disabled
{% endunless %}>
{{ 'product.buy_it_now' | t }}
</button>
{% endif %}
</div>出典・ライセンス
- Repository:
- https://github.com/kondasoft/ks-bootshop
- 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 行