<?php
/*
* Prevent guest users from booking before waitlists
*/
add_filter('em_bookings_is_open','my_booking_open', 100, 2);
function my_booking_open( $return, $EM_Bookings ){
global $wpdb;
if( get_option('dbem_waitlists_events') && !is_user_logged_in() ) {
$EM_Event = $EM_Bookings->get_event();
$waitlist_events = get_option('dbem_waitlists_events_default');
if ( $waitlist_events ){
if (!empty($EM_Event->event_attributes['waitlist'])) {
/* start */
if ( isset($_REQUEST['uuid']) ){
$sql = 'SELECT booking_status FROM '.EM_BOOKINGS_TABLE. ' WHERE booking_status = 7 AND booking_uuid = %s ';
$status = $wpdb->get_var( $wpdb->prepare($sql, $_REQUEST['uuid']) );
if ( $status == 7 ){
$return = true;
return $return;
}
}
/* end */
$statuses = array(6);
$sql = 'SELECT SUM(booking_spaces) FROM '.EM_BOOKINGS_TABLE. ' WHERE booking_status IN ('. implode(',', $statuses) .') AND event_id=%d';
$pending_spaces = $wpdb->get_var( $wpdb->prepare($sql, $EM_Bookings->event_id) );
if ( $pending_spaces > 0 ){
$return = false;
add_filter('em_event_output_placeholder', 'my_em_bookinform', 100, 3);
}
}
}
}
if( get_option('dbem_waitlists_events') && is_user_logged_in() ) {
/* start */
if ( isset($_REQUEST['uuid']) ){
$sql = 'SELECT booking_status FROM '.EM_BOOKINGS_TABLE. ' WHERE booking_status = 7 AND booking_uuid = %s ';
$status = $wpdb->get_var( $wpdb->prepare($sql, $_REQUEST['uuid']) );
if ( $status == 7 ){
$return = true;
return $return;
}
}
/* end */
$current_user = wp_get_current_user(); //$current_user->ID
$statuses = array(6); //6 - waiting // 7 - approved
$sql = 'SELECT SUM(booking_spaces) FROM '.EM_BOOKINGS_TABLE. ' WHERE booking_status IN ('. implode(',', $statuses) .') AND event_id=%d AND person_id=%d';
$pending_spaces = $wpdb->get_var( $wpdb->prepare($sql, $EM_Bookings->event_id, $current_user->ID ) );
if ( $pending_spaces > 0 && !isset($_REQUEST['uuid']) ){
$return = false;
add_filter('em_event_output_placeholder', 'my_em_bookinform_already_waiting', 100, 3);
} else {
$return = false;
add_filter('em_event_output_placeholder', 'my_em_bookinform', 100, 3);
}
}
return $return;
}
function my_em_bookinform_already_waiting($replace, $EM_Event, $result) {
if ( $result == '#_BOOKINGFORM' ) {
include( emp_locate_template('waitlists/already-waiting.php') );
return ob_get_clean();
}
return $replace;
}
function my_em_bookinform($replace, $EM_Event, $result) {
if ( $result == '#_BOOKINGFORM' ) {
include( emp_locate_template('waitlists/form.php') );
echo "<script>";
include( emp_locate_template('waitlists/waitlists.js') );
echo "</script>";
return ob_get_clean();
}
return $replace;
}
Comments
0 B
|👍
/👎
0 B
|0 👍
/0 👎
0 B
|0 👍
/0 👎
0 B
|0 👍
/0 👎