[英]Add to cart - change from a dropdown variant select with add to cart button to single add to cart button for each variant on Shopify / Liquid
[英]Shopify Liquid: Assign Variant to Quick Add Button
我正在嘗試使用 Shopify 液體在自定義頁面模板上為產品創建快速添加按鈕。 該產品有多個變體,我想為該產品分配一個特定的變體; 即第二種變體。
例如,假設我的變體 ID 是456
。 所以,基本上,我希望能夠顯示 id 為123
的產品,如下所示。 我希望將快速添加分配給變體 id 456
。 有沒有辦法使用變體 ID 來做到這一點? 下面是我的循環示例。
任何幫助,將不勝感激!
{%- assign my_products = collections['collection-handle'] -%}
{%- for product in my_products.products -%}
{%- if product.id == 123 -%}
{%- assign product_form_id = 'quick-add-' | append: section_id | append: product.id -%}
{%- if product.variants.size > 1 -%}
{%- form 'product', product, id: product_form_id, class: 'actions__form', novalidate: 'novalidate', data-type: 'add-to-cart-form' -%}
<input type="hidden" name="id" value="{{ product.selected_or_first_available_variant.id }}" disabled />
<button
id="{{ product_form_id }}-submit"
type="submit"
name="add"
class="add__button"
data-variant_id="{{ product.selected_or_first_available_variant.id }}"
aria-label="Add to cart - {{ product.title | escape }}"
>
<span>Add</span>
</button>
{%- endform -%}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
在您的產品循環中,您可以獲得這樣的變體並根據變體 ID 或標簽過濾變體。
{% for variant in product.variants %}
{% if variant.id == 456 %}
{% else %}
{% endif %}
{% endfor %}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.