我需要制作很多自定义按钮来将产品添加到购物车:
<button type="button" class="button add_to_cart" data-product_id="998" data-quantity="1">
Add to cart
</button>
带有链接的方法非常糟糕并且无法正常工作:
https://site-link/?add-to-cart=998&quantity=1
我尝试了很多其他选择,但没有任何效果。
对于简单的产品类型,要显示添加到购物车按钮,有多种方法。
使用 Ajax 添加到购物车按钮:
<a href="#" class="button add_to_cart_button ajax_add_to_cart" data-product_id="998" data-quantity="1" rel="nofollow">Add to cart</a>
使用 POST 方法和需要周围表单的提交按钮:
<form class="cart-custom" method="post">
<input type="hidden" class="qty" name="quantity" value="1">
<button type="submit" name="add-to-cart" value="998" class="single_add_to_cart_button button">Add to cart</button>
</form>
使用带有链接按钮的 GET 方法(但它在 URL 中显示查询字符串):
<a href="?add-to-cart=998&quantity=1" class="button add_to_cart_button" rel="nofollow">Add to cart</a>