Add Avaliability Rules In WooCommerce Bookings Programatically

Hi there,

I am using WooCommerce Bookings https://woocommerce.com/products/woocommerce-bookings/ and I have a product which is basically a parent to three products. What I would like to achieve is that when the main parent product is booked, it then sets an availability rule on the 3 sub products to make them unavailable.

To do this, I looked at the following from Adding availabilities programmatically to a bookable product on Woocommerce Bookings and then made a couple of amendments to then make the following:

add_action('woocommerce_new_booking', 'modify_woocommerce_booking_date');

function modify_woocommerce_booking_date($booking_id)
{

    $booking = get_wc_booking($booking_id);

    $product_id = $booking->get_product_id();

    //If the bundle is being booked
    if ($product_id == 69096) {
        //This is the array that will contain all the availabilities
        $availabilities = array();

        //Formatting the start and end date of the bookings to be Y-m-d format
        $time = strtotime($booking->get_start_date());
        $startdate = date('Y-m-d', $time);
        $time = strtotime($booking->get_end_date());
        $enddate = date('Y-m-d', $time);

        //Create an array that contains the required fields (from_date and to_date are not necessary in some types of availabilities)
        $availability = array(
            'type' => 'custom', //I'm doing full day bookings rather than hours.
            'bookable' => 'no',
            'priority' => 10,
            'from_date' => wc_clean($startdate),
            'to_date' => wc_clean($enddate)
        );

        //If you need to add more than one availability, make a loop and push them all into an array
        array_push($availabilities, $availability);
        add_post_meta(69047, '_wc_booking_availability', $availabilities); //Individual Product One
        add_post_meta(69093, '_wc_booking_availability', $availabilities); //Individual Product Two
        add_post_meta(69094, '_wc_booking_availability', $availabilities); //Individual Product Three

    }
}

However, this doesn’t seem to work. Is there anything I’m missing? Do I need to include the time in my availability as well as the date?

Thanks!