I am using Woothemes Woocommerce Bookings. I want users to be able to enter a date in the product booking date picker and have the system make the booking three weeks prior to that date. e.g. customer uses the date picker to select 28/04/2018 (28th April 2018) but the booking is made for 07/04/2018 (7th April 2018).
All bookings are made in blocks of 5 weeks (35 days) but they enter in a date that results in their booking being 3 weeks (21 days) before that date, and 2 weeks (14 days) after. Customers only select one date, there is no start and end date for them to select.
The documentation references a hook called woocommerce_new_booking
that you can use in order to modify the booking date before it's saved to the database. This code will modify the booking start and end date to 3 weeks prior to the date they select. Add this code to your functions.php file.
add_action( 'woocommerce_new_booking', 'modify_woocommerce_booking_date');
function modify_woocommerce_booking_date( $booking_id ) {
$booking = new WC_Booking( $booking_id );
$booking_start = $booking->get_start();
$booking_end = $booking->get_end();
$new_booking_start = strtotime ( '-3 week' , $booking_start ) ;
$new_booking_end = strtotime ( '-3 week' , $booking_end ) ;
$booking->set_start( $new_booking_start );
$booking->set_end($new_booking_end);
$booking->save();
}