I would like to add a bookable product to the cart programatically, with a date set so the slot is reserved — just as if the user used the booking calendar on the single product page.

I have been able to achieve the functionality with the solution proposed here [https://stackoverflow.com/questions/47741066/how-to-add-a-bookable-product-to-woocommerce-cart-programmatically] with having a form that submits to the same page but this is not an ideal solution.

I have searched through the plugin files to find out how the booking calendar adds the cart item but cannot work out how.

It does not work by doing WC()->cart->add_to_cart($id) sadly.

This is using WooCommerce with the WooCommerce Bookings plugin.


This is the correct method

  • I meant to do that, have edited my question. This is not working for me with a bookable product. – Clayton Jones Mar 7 '19 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.