The actual booking is made via ajax. When you push the “book now” button a JavaScript event is triggered and a series of checks is started.
the click event is in property.js around line 300
$('#submit_booking_front').click(function (event) {
event.preventDefault();
var guest_number, guest_overload,guestfromone,max_guest;
if (!check_booking_form() || booking_error === 1) {
return;
}
.......
If all the checks are ok we call the function check_booking_valability in which we will see if the selected period is available for booking.
The function check_booking_valability is in control.js at line 216
In this function an ajax call is started. The php function for the ajax call is wpestate_ajax_check_booking_valability and can be found in ajax_functions_booking.php at line 155.
In this function we do some tests and see if the selected period is available. If everything is ok we return the string “run” to JavaScript function check_booking_valability
Going back to check_booking_valability function – on ajax succes branch – if the the returned string is “run” we call another javascript function that will actually do the “booking insert” . This new function is called owner_insert_book() and can be found in control.js ar line 154
In this function we do a second ajax call to a php function that will do the actually booking. The php function is wpestate_ajax_add_booking and is in ajax_functions_edit.php at line 565. In this php function we create the “booking” custom post, assing the right meta tags and send the booking emails.
$post = array(
'post_title' => $event_name,
'post_content' => $comment,
'post_status' => 'publish',
'post_type' => 'wpestate_booking' ,
'post_author' => $userID
);
$post_id = wp_insert_post($post );
If everything checks out the JavaScript function check_booking_valability will display the booking confirmed message
A similar process is happens when the owner do a internal booking (book his own property).
the internal book button is at line 765 in ajaxcalls_add.js
$('#book_dates').click(function () {
check_booking_valability_internal();
});
function check_booking_valability_internal is in control.js at line 300
function wpestate_ajax_check_booking_valability_internal is in ajax_functions_booking.php at line 61
function owner_insert_book_internal is in control.js at line 255
function wpestate_ajax_add_booking is in ajax_functions.edit at line 565