简体   繁体   中英

Shopify metafield product add to cart

I created a custom metafild in shopify to add a suggested product to the product page.

I have added the code to my product template and I am correctly displaying the suggested product.

I want to add the add to cart button for this suggested product so that the user can add the suggested product to the cart without entering the specific page.

 <div class = "groups-btn">
                     {% if current_variant.available%}
                      <input data-btn-addToCart type = "submit" name = "add" class = "btn" id = "product-add-to-cart" value = "add" data-form-id = "# add-to- cart-form ">
                     {% endif%}
                     </div>

With this code, however, I add the main product (the one on the page) to the cart, not the suggested product. How can I solve my problem? Thanks

Adding products to the cart requires you to POST the ID of the variant and a quantity. Wire up the add to cart button for your secondary product to be an Ajax call and you're good to go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM