简体   繁体   中英

Send quantity of product from form to shopping cart

I am developing a form where the difference of two dates is calculated. I need this difference to be added to the shopping cart as the product quantity with id = '18 '.

在此处输入图片说明 In the image, the difference between the two dates is 23 days.

The plugin that I use to make the form in Wordpress allows me to assign the OnClick event to the button.

在此处输入图片说明

As you realize in the image, I have put:

window.location="http://localhost/travelagent/?add-to-cart=18";

This line of code what it does is add me the product but only once, what I want is that it be added according to the amount calculated previously. In this example it would be 23.

您可以这样添加数量参数:

window.location="http://localhost/travelagent/?add-to-cart=18&quantity=23";

as answered by Reigel:

http://localhost/travelagent/?add-to-cart=18&quantity=23

To redirect to the cart automatically you need to change the setting on the WooCommerce Settings page -> Products -> Redirect to cart (checkbox).

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