简体   繁体   English

Woocommerce - 如何将数量传递到“添加到购物车”按钮

[英]Woocommerce - How to pass quantity into Add to cart button

How can i make add-to-cart button with custom quantity attribute?如何使用自定义数量属性制作添加到购物车按钮?

I can add:我可以添加:

?add-to-cart=335,338,339&quantity=3,2,1

to my page link and it works well, but i want to make button with those attributes.到我的页面链接并且效果很好,但我想制作具有这些属性的按钮。

Default one:默认一个:

<button type="submit" name="add-to-cart" value="332,333,338&quantity=3,2,1"  class="single_add_to_cart_button button alt">Add to cart</button> 

adds products, but always 1, quantity field don't work.添加产品,但始终为 1,数量字段不起作用。

I know i can pass those attributes by <a href="..."> but i want to do it proper way.我知道我可以通过<a href="...">传递这些属性,但我想以正确的方式进行。

You need to use the attribute data-quantity in ur <a> tag.您需要在您的<a>标记中使用属性data-quantity
Example - add 3 units from Product with ID 332: <button type="submit" name="add-to-cart" value="332" class="single_add_to_cart_button" data-quantity="3">Add to cart</button>示例 - 从 ID 为 332 的产品中添加 3 个单位: <button type="submit" name="add-to-cart" value="332" class="single_add_to_cart_button" data-quantity="3">Add to cart</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 自定义添加到购物车按钮,将多个产品添加到购物车中,数量:woocommerce - Custom add to cart button to add multiple product into cart with quantity :woocommerce 如何在 woocommerce 中的购物车数量旁边添加文本 - How to add text next to the quantity on the cart in woocommerce 将数量字段添加到 WooCommerce 商店页面上的 Ajax 添加到购物车按钮 - Add a quantity field to Ajax add to cart button on WooCommerce shop page WooCommerce商店页面:添加到购物车按钮上的数量输入 - WooCommerce Shop page: Quantity input on add to cart button 在woocommerce单个产品页面中添加固定数量的添加到购物车按钮 - additional add to cart button with fixed quantity in woocommerce single product pages 如果数量增加,则使用jQuery更改WooCommerce的“添加到购物车”按钮文本 - WooCommerce Add To Cart Button text change using jQuery if Quantity increase 如何在woocommerce中使用buynow按钮添加动态数量 - how to add the dynamically quantity with buynow button in woocommerce 如何根据商品数量在购物车中为woocommerce添加消息 - How to add a message in cart for woocommerce based on item quantity 将数量选择添加到 woocommerce 购物车小部件 - add quantity select to woocommerce shopping cart widget 如何在自定义模板中添加数量字段并添加到购物车按钮? - How to add quantity field and add to cart button in a custom template?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM