The site I am developing is using the WooCommerce Booking & Appointment Plugin (http://www.tychesoftwares.com/store/premium-plugins/woocommerce-booking-plugin), I create a custom form to add mutiple products to cart at one time. Here is the code:
function booking_add_to_cart() {
if ($_POST && is_post_type_archive('product')) {
global $woocommerce;
if(is_array($_POST['qty']) && !empty($_POST['qty'])) {
$woocommerce->cart->empty_cart(); //Clear the cart
foreach ($_POST['qty'] as $product_id => $qty) {
$qty = intval($qty);
$product_id = intval($product_id);
if ($qty > 0 && $product_id > 0) {
$woocommerce->cart->add_to_cart($product_id, $qty); // Add product to cart individually.
}
}
$checkout_url = $woocommerce->cart->get_checkout_url();
wp_redirect( $checkout_url ); //Redirect to checkout page
}
}
}
add_action( 'template_redirect', 'booking_add_to_cart');
But there are something wrong with the prices on checkout page. Some of them are correct and some aren’t.
The plugin is using three filters to modify the prices:
add_filter('woocommerce_add_cart_item_data', array('bkap_cart', 'bkap_add_cart_item_data'), 25, 2);
add_filter('woocommerce_get_cart_item_from_session', array('bkap_cart', 'bkap_get_cart_item_from_session'), 25, 2);
add_filter( 'woocommerce_get_item_data', array('bkap_cart', 'bkap_get_item_data_booking'), 25, 2 );
However it’s not working correctly in the custom form I created. Can anyone help me with this? Thanks in advance.