0
我想在我的集合頁面上有添加到購物車按鈕(例如 - example.com/collections/collection-name)在每個產品旁邊。所以如果我在頁面上有20種產品,我想要在他們各自的產品旁邊有20個加入購物車按鈕。Shopify:添加到購物車按鈕只在集合頁面上添加最後一個產品
我編輯產品card.liquid下列要求:
<select name="product-form-{{ product.variants.first.id }}" id="product-form-{{ product.variants.first.id }}" class="product-form__variants">
{% for variant in product.variants %}
<option {% if variant == current_variant %} selected="selected" {% endif %} data-sku="{{ variant.sku }}" value="{{ variant.id }}" {% unless variant.available %} disabled="disabled" {% endunless %}>
{% if variant.available %}
{{ variant.title }} - {{ variant.price | money_with_currency }}
{% else %}
{{ variant.title }} - {{ 'products.product.sold_out' | t }}
{% endif %}
</option>
{% endfor %}
</select>
<div class="product-form__item product-form__item--quantity">
<label for="Quantity">{{ 'products.product.quantity' | t }}</label>
<input type="number" id="Quantity-{{ product.variants.first.id }}" name="quantity" value="1" min="1" class="product-form__input">
</div>
<div class="product-form__item product-form__item--submit">
<button name="add" class="btn btn--full product-form__cart-submit">
<span id="AddToCartText-{{ product.variants.first.id }}">{{ 'products.product.add_to_cart' | t }}</span>
</button>
</div>
</form>
的問題是,當我點擊加入購物車1號產品的頁面,最後的產品。在頁面上被添加到購物車。
添加到購物車的現有onclick事件是否可以找到頁面上的最後一個產品ID並將其添加到購物車?我正在使用Venture主題。
我錯過了什麼?