I am trying to change meta for all the bookable products which are already in cart, more specifically - end_date and duration, but with no result for several days already... I need to do it in woocommerce_before_calculate_totals action. I have tried this code:
if ( $my_condition ) {
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
if ( isset( $cart_item['booking'] ) ) {
$cart_item['booking']->set_duration( $my_new_duration );
}
}
}
And thousands of other ways, which were unsuccessful.
A similar method works well with set_price(), it changes the price, but bookable product meta like duration and end date seems impossible to change for products already in cart! Google seems to be helpless on this as while searching for days I could only find how to change the price itself, not the duration or other meta.
Could anyone help me out? Thanks!
EDIT: Simply put, here's what Im trying to achieve - Let's say I have these items in my cart:
- Product1 booked from 2018-05-10 10:00 to 2018-05-10 16:00
- Product2 booked from 2018-05-10 10:00 to 2018-05-10 17:00
and when my function triggers, both of these products booking range in my cart should change to 2018-05-10 10:00 to 2018-05-10 13:30