【发布时间】:2020-04-08 22:11:57
【问题描述】:
我在 Shopify / Liquid 上有以下代码,用于将产品的变体添加到购物车。我想将其从带有“添加到购物车”按钮的下拉菜单更改为仅将大小添加到购物车的单个按钮。这最终会导致为每个尺寸选项添加许多按钮。我的代码如下:
<form action="/cart/add" method="post" enctype="multipart/form-data" id="AddToCartForm" class="quick-add-to-cart small--hide clearfix">
{% if product.variants.size > 1 %}
<select id="product-select-{{ product.id }}" name='id' class="text-center">
{% for variant in product.variants %}
{% if variant.available %}
<option {% if variant == product.selected_or_first_available_variant %} selected="selected" {% endif %} data-sku="{{ variant.sku }}" value="{{ variant.id }}">{{ variant.title }}</option>
{% else %}
<option disabled="disabled">
{{ variant.title }} - {{ 'products.product.sold_out' | t }}
</option>
{% endif %}
{% endfor %}
</select>
{% else %}
<input type="hidden" name="id" value="{{ product.variants.first.id }}" />
{% endif %}
{% if product.available %}
<button type="submit" name="add" id="AddToCart" class="btn btn-mini text-center" onclick="ga('send', 'event', 'Quick Add To Cart', '{{ product.type }}', '{{ product.title }}');">Add To Cart</button>
{% else %}
<h6>Out of Stock</h6>
{% endif %}
</form>
如果有人知道如何为这个请求更改上面的代码,那就太棒了!
非常感谢。
【问题讨论】:
标签: select button shopify liquid cart