1

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.

1 Answer 1

1

This is the correct method

    WC()->cart->add_to_cart($id);
1
  • 1
    I meant to do that, have edited my question. This is not working for me with a bookable product. Mar 7, 2019 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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