Forked from apintocr/wc-bookings-availability-search.php
Created
September 18, 2017 14:54
-
-
Save zarankumar/f7a14bea56c5993b00385f161b2b10e2 to your computer and use it in GitHub Desktop.
WooCommerce Bookings Availability Search
This file contains 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
<?php | |
/** | |
* WooCommerce Bookings Availability Search | |
* | |
* This is almost pseudo code, it only serves to explain the "how to do it" and does not attempt to be "The Way" to do it. | |
* NOTE: This NEEDS to be refined in order to work as expected. | |
* | |
* @author António Pinto <apinto@vanguardly.com> | |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License | |
* | |
* @var string $bookStart (example: '2016-06-14 16:23:00') | |
* @var string $bookEnd (example: '2016-06-14 16:23:00') | |
*/ | |
// Creating DateTime() objects from the input data. | |
$dateTimeStart = new DateTime($bookStart); | |
$dateTimeEnd = new DateTime($bookEnd); | |
// Get all Bookings in Range | |
$bookings = WC_Bookings_Controller::get_bookings_in_date_range( | |
$dateTimeStart->getTimestamp(), | |
$dateTimeEnd->getTimestamp(), | |
'', | |
false | |
); | |
// Build Array of all the Booked Products for the given Date-Time interval. | |
$exclude[] = 0; | |
foreach ($bookings as $booking) { | |
$exclude[] = $booking->product_id; | |
} | |
// Do a regular WP_Query using 'post__not_in' with the previous array. | |
$args = array ( | |
'post__not_in' => $exclude, | |
'post_type' => ['product'], | |
'post_status' => ['published'], | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment