Created
January 28, 2018 14:56
-
-
Save waqashassan98/eaf7a953b8fc71dde95076dd24bcdd61 to your computer and use it in GitHub Desktop.
This function can be used to get the booking details in a date range from Woocommerce Bookings plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get_bookings_in_date_range_wh( $next_monday, $next_friday, $product_id, true ); | |
function get_bookings_in_date_range_wh( $start_date, $end_date, $product_or_resource_id = 0, $check_in_cart = true ) { | |
$args = array( | |
'status' => get_wc_booking_statuses(), | |
'object_type' => 'product_or_resource', | |
'date_between' => array( | |
'start' => $start_date, | |
'end' => $end_date, | |
), | |
); | |
if ( ! $check_in_cart ) { | |
$args['status'] = array_diff( $args['status'], array( 'in-cart' ) ); | |
} | |
if ( $product_or_resource_id ) { | |
if ( get_post_type( $product_or_resource_id ) === 'bookable_resource' ) { | |
$args['resource_id'] = absint( $product_or_resource_id ); | |
} else { | |
$args['product_id'] = absint( $product_or_resource_id ); | |
} | |
} | |
$dts = apply_filters( 'woocommerce_bookings_in_date_range_query', WC_Booking_Data_Store::get_booking_ids_by( $args ) ); | |
$data = array(); | |
$header = array(); | |
$header[] = array("Booking_ID", "Order_ID", "Persons", "Creation_Date", "Booking_Date", "First_Name", "Last_Name", "Email", "Phone", "Allergies", "Cost", "Status"); | |
foreach ($dts as $dt) { | |
$booking = new WC_Booking( $dt ); | |
$order = new WC_Order( $booking->order_id ); | |
$row = array( | |
"".$booking->id, | |
"".$booking->order_id, | |
"".$booking->person_counts[158], | |
"".date('m/d/Y', $booking->date_created), | |
"".date('m/d/Y', $booking->start), | |
"".$order->get_billing_first_name(), | |
"".$order->get_billing_last_name(), | |
"".$order->get_billing_email(), | |
"".$order->get_billing_phone(), | |
"".get_post_meta($booking->order_id, "allergies", true), | |
"".$booking->cost, | |
"".$booking->status | |
); | |
$data[] = $row; | |
} | |
//Sort by booking start date | |
array_multisort(array_column($data, 4), SORT_ASC, $data); | |
//merge with header, which can be used later for csv export | |
$data = array_merge($header, $data); | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment