I am using Woocommerce and Woocommerce bookings plugins and I would like to add Date Range with time throught a custom code.

I want to add :

  • Date from => to
  • Time from => to
  • Bookable : Yes

I know how to add a lot of other fields like price, name, description etc … ex.

add_post_meta( $product_ID, '_wc_booking_has_persons', 'yes' );

but I can’t figure out how to do it for the Range because it’s dynamic and needs a click of button… Any help is much appreciated, thx.

1
1

I just figure out how to do it with a bit of reverse engineering, hopefuly this helps someone :

    $availability = array();
    $availability[0]['type'] = 'time:range';
    $availability[0]['bookable'] = 'yes';
    //Default priority
    $availability[0]['priority'] = 10;

    //case 'time:range'
    $availability[0]['from'] = wc_booking_sanitize_time( $hours );
    $availability[0]['to']   = wc_booking_sanitize_time( $hours );
    $availability[0]['from_date'] = wc_clean( $date );
    $availability[0]['to_date']   = wc_clean( $date );

    add_post_meta( $product_ID, '_wc_booking_availability', $availability );

Leave a Reply

Your email address will not be published. Required fields are marked *