Hotel Raxa - Advanced Booking System Implementation

🏨 Hotel Booking Enhancements:
- Implemented Eagle Booking Advanced Pricing add-on
- Added Booking.com-style rate management system
- Created professional calendar interface for pricing
- Integrated deals and discounts functionality

💰 Advanced Pricing Features:
- Dynamic pricing models (per room, per person, per adult)
- Base rates, adult rates, and child rates management
- Length of stay discounts and early bird deals
- Mobile rates and secret deals implementation
- Seasonal promotions and flash sales

📅 Availability Management:
- Real-time availability tracking
- Stop sell and restriction controls
- Closed to arrival/departure functionality
- Minimum/maximum stay requirements
- Automatic sold-out management

💳 Payment Integration:
- Maintained Redsys payment gateway integration
- Seamless integration with existing Eagle Booking
- No modifications to core Eagle Booking plugin

🛠️ Technical Implementation:
- Custom database tables for advanced pricing
- WordPress hooks and filters integration
- AJAX-powered admin interface
- Data migration from existing Eagle Booking
- Professional calendar view for revenue management

📊 Admin Interface:
- Booking.com-style management dashboard
- Visual rate and availability calendar
- Bulk operations for date ranges
- Statistics and analytics dashboard
- Modal dialogs for quick editing

🔧 Code Quality:
- WordPress coding standards compliance
- Secure database operations with prepared statements
- Proper input validation and sanitization
- Error handling and logging
- Responsive admin interface

🤖 Generated with Claude Code (https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Hotel Raxa Dev
2025-07-11 07:43:22 +02:00
commit 5b1e2453c7
9816 changed files with 2784509 additions and 0 deletions

View File

@@ -0,0 +1,265 @@
<?php
/* --------------------------------------------------------------------------
* Booking Page Shortcode
* @since 1.0.0
* modified 1.2.5
---------------------------------------------------------------------------*/
defined('ABSPATH') || exit;
function eb_booking_shortcode() {
ob_start();
/**
* Include Stepline
*/
if ( eb_get_option('eb_stepline' ) == true ) include eb_load_template('elements/stepline.php');
// Check if rooms has been selected
if( isset( $_POST['submit'] ) ) {
if( isset( $_POST['eb_single_room'] ) ) {
$eb_arrive_from_single_room = $_POST['eb_single_room'];
} else {
$eb_arrive_from_single_room = 0;
}
// ARRIVE FROM SINGLE ROOM
if ( $eb_arrive_from_single_room == 1 ) {
// PARAMETERS
$eb_room_id = $_POST['eb_room_id'];
$eb_checkin = $_POST['eb_checkin'];
$eb_checkout = $_POST['eb_checkout'];
// Guests
if ( eb_get_option('eb_adults_children') == true ) {
if ( !empty( $_POST['eb_adults'] ) ) {
$eb_adults = $_POST['eb_adults'];
} else {
$eb_adults = 0;
}
if ( !empty( $_POST['eb_children'] ) ) {
$eb_children = $_POST['eb_children'];
} else {
$eb_children = 0;
}
$eb_guests = $eb_adults + $eb_children;
} else {
$eb_adults = '';
$eb_children = '';
$eb_guests = $_POST['eb_guests'];
}
// ARRIVE FROM SEARCH PAGE
} else {
// GET DATA
$eb_room_id= $_POST['eb_room_id'];
$eb_checkin = $_POST['eb_checkin'];
$eb_checkout = $_POST['eb_checkout'];
$eb_guests = $_POST['eb_guests'];
$eb_adults = $_POST['eb_adults'];
$eb_children = $_POST['eb_children'];
}
// IF ROOM IS AVAILABLE
if ( eb_room_is_available_block($eb_room_id, $eb_checkin, $eb_checkout) && eagle_booking_is_qnt_available( eb_room_availability($eb_room_id, $eb_checkin, $eb_checkout), $eb_checkin, $eb_checkout, $eb_room_id) == 1 ) {
/**
* Check min & max booking night
*/
$eb_booking_nights = eb_total_booking_nights($eb_checkin, $eb_checkout);
$eb_min_booking_nights = get_post_meta( $eb_room_id, 'eagle_booking_mtb_room_min_booking_nights', true );
$eb_max_booking_nights = get_post_meta( $eb_room_id, 'eagle_booking_mtb_room_max_booking_nights', true );
if ( empty($eb_min_booking_nights) ) $eb_min_booking_nights = 1;
if ( empty($eb_max_booking_nights) ) $eb_max_booking_nights = 1000;
if ( $eb_booking_nights >= $eb_min_booking_nights && $eb_booking_nights <= $eb_max_booking_nights ) {
/**
* Price ( include it as a external function )
*/
$eb_trip_price = 0;
$eagle_booking_index = 1;
$eagle_booking_date_cicle = $eb_checkin;
// Sart Cecking price
while ($eagle_booking_index <= eb_total_booking_nights($eb_checkin, $eb_checkout)) {
/**
* Calculate the booking price based on room price type
*/
$eb_room_price_type = get_post_meta($eb_room_id, 'eagle_booking_mtb_room_price_type', true);
// Charge based on room price x booking nights x guests number
if ($eb_room_price_type === 'room_price_nights_guests') {
// Adults & children option is enabled
if ( eb_get_option('eb_adults_children') == true ) {
// Calculate the total price
$eb_trip_price = $eb_trip_price + eb_room_total_price($eb_room_id, $eagle_booking_date_cicle) * ($eb_adults + $eb_children);
} else {
// Calculate the total price
$eb_trip_price = $eb_trip_price + eb_room_total_price($eb_room_id, $eagle_booking_date_cicle) * $eb_guests;
}
// Charge bades on guests or adults & children price
} elseif ($eb_room_price_type === 'room_price_nights_guests_custom') {
// Adults & children option is enabled
if (eb_get_option('eb_adults_children') == true) {
$eb_adults_price = get_post_meta($eb_room_id, 'eagle_booking_mtb_room_adult_price', true) ?: 0;
$eb_adults_price_start = get_post_meta($eb_room_id, 'eagle_booking_mtb_room_adults_price_start', true) ?: 0;
$eb_children_price = get_post_meta($eb_room_id, 'eagle_booking_mtb_room_children_price', true) ?: 0;
$eb_children_price_start = get_post_meta($eb_room_id, 'eagle_booking_mtb_room_children_price_start', true) ?: 0;
// Adults total custom price
if ($eb_adults < $eb_adults_price_start) {
$eb_adults_price_total = 0;
} else {
$eb_adults_price_total = $eb_adults_price * ($eb_adults - $eb_adults_price_start);
}
// Children total custom price
if ($eb_children < $eb_children_price_start) {
$eb_children_price_total = 0;
} else {
$eb_children_price_total = $eb_children_price * ( $eb_children - $eb_children_price_start );
}
// Calculate the total price
$eb_trip_price = ($eb_trip_price + eb_room_total_price($eb_room_id, $eagle_booking_date_cicle)) + ($eb_adults_price_total) + ($eb_children_price_total);
} else {
$eb_guests_price = get_post_meta($eb_room_id, 'eagle_booking_mtb_room_guests_price', true) ?: 0;
$eb_guests_price_start = get_post_meta($eb_room_id, 'eagle_booking_mtb_room_guests_price_start', true) ?: 0;
// Guests total custom price
if ($eb_guests < $eb_guests_price_start) {
$eb_guests_price_total = 0;
} else {
$eb_guests_price_total = $eb_guests_price * ($eb_guests - $eb_guests_price_start);
}
// Calculate the total price
$eb_trip_price = ($eb_trip_price + eb_room_total_price($eb_room_id, $eagle_booking_date_cicle)) + ($eb_guests_price_total);
}
// Charge based on room price x booking nights
} else {
// Calculate the total price
$eb_trip_price = $eb_trip_price + eb_room_total_price($eb_room_id, $eagle_booking_date_cicle);
}
// Room Total Price Excluding Taxes, Fees and Additional Services
$eb_room_total_price = $eb_trip_price;
$eagle_booking_date_cicle = date('Y/m/d', strtotime( $eagle_booking_date_cicle.' + 1 days' ));
$eagle_booking_index++;
}
?>
<div class="eb-checkout-page eb-sticky-sidebar-container">
<div>
<?php
/**
* Include notification mssg
*/
include eb_load_template('booking/notification-mssg.php');
/**
* Include additional services
*/
include eb_load_template('booking/additional-services.php');
/**
* Include booking form
*/
include eb_load_template('booking/form.php'); ?>
</div>
<div>
<?php
/**
* Include booking details
*/
include eb_load_template('booking/details.php'); ?>
</div>
</div>
<?php
} elseif ( $eb_booking_nights > $eb_max_booking_nights ) {
eb_notice( 'error', __('Max. Booking Nights', 'eagle-booking').' '.$eb_max_booking_nights.' <a href="'.eb_search_page().'">'.__('Return to search page','eagle-booking').'</a>' );
} elseif ( $eb_booking_nights <= $eb_min_booking_nights ) {
eb_notice( 'error', __('Min. Booking Nights', 'eagle-booking').' '.$eb_min_booking_nights.' <a href="'.eb_search_page().'">'.__('Return to search page','eagle-booking').'</a>' );
}
} else {
eb_notice( 'error', __('The room is not available.','eagle-booking').' <a href="'.eb_search_page().'">'.__('Return to search page','eagle-booking').'</a>' );
}
} else {
eb_notice( 'error', __('Please select a room to make a reservation.','eagle-booking').' <a href="'.eb_search_page().'">'.__('Return to search page','eagle-booking').'</a>' );
}
/**
* Enqueue Booking Page JS & AJAX
*/
wp_enqueue_script( 'eb-checkout', EB_URL .'assets/js/checkout.js', array( 'jquery' ), EB_VERSION, true );
wp_localize_script(
'eb-checkout', 'eb_checkout',
array(
'eb_user_sign_in_ajax' => admin_url( 'admin-ajax.php' ),
'eb_user_sign_up_ajax' => admin_url( 'admin-ajax.php' ),
'eb_user_sign_out_ajax' => admin_url( 'admin-ajax.php' ),
'eb_coupon_code_ajax' => admin_url( 'admin-ajax.php' ),
// Used for static Ajax requests
'eb_ajax_nonce' => wp_create_nonce( 'eb_nonce' ),
)
);
// Clean Buffer
return ob_get_clean();
}
// Depracated Shortcode (Will be removed soon)
add_shortcode('eagle_booking_booking', 'eb_booking_shortcode');
// Booking Page Shortcode
add_shortcode('eb_booking', 'eb_booking_shortcode');

View File

@@ -0,0 +1,288 @@
<?php
/* --------------------------------------------------------------------------
* Checkout Page Shortcode
* Author: Eagle Themes
* Package: Eagle-Booking/Core
* Since: 1.0.0
* Modified: 1.2.7
---------------------------------------------------------------------------*/
defined('ABSPATH') || exit;
function eb_checkout_shortcode() {
ob_start();
// Get checkout page
if( isset( $_POST['eb_arrive'] ) ) {
$eagle_booking_arrive = $_POST['eb_arrive'];
} else {
$eagle_booking_arrive = '';
}
// Get payment method
if( isset( $_POST['eagle_booking_payment_method'] ) ) {
$eagle_booking_payment_method = $_POST['eagle_booking_payment_method'];
} else {
$eagle_booking_payment_method = '';
}
// Payment Details
if ( $eagle_booking_arrive == 1 ) {
// Get the the form values from booking page
$eb_booking_price = sanitize_text_field( $_POST['eb_booking_price'] );
$eb_room_price = sanitize_text_field( $_POST['eb_room_price'] );
$eagle_booking_form_date_from = sanitize_text_field( $_POST['eb_date_from'] );
$eagle_booking_form_date_to = sanitize_text_field( $_POST['eb_date_to'] );
$eagle_booking_form_guests = sanitize_text_field( $_POST['eb_guests'] );
$eagle_booking_form_adults = sanitize_text_field( $_POST['eb_adults'] );
$eagle_booking_form_children = sanitize_text_field( $_POST['eb_children'] );
$eagle_booking_form_name = sanitize_text_field( $_POST['eb_user_firstname'] );
$eagle_booking_form_surname = sanitize_text_field( $_POST['eb_user_lastname'] );
$eagle_booking_form_email = sanitize_text_field( $_POST['eb_user_email'] );
$eagle_booking_form_phone = sanitize_text_field( $_POST['eb_user_phone'] );
$eagle_booking_room_id = sanitize_text_field( $_POST['eb_room_id'] );
$eagle_booking_room_title = sanitize_text_field( $_POST['eb_room_title'] );
$eagle_booking_form_services = sanitize_text_field( $_POST['eb_additional_services_id'] );
// Optional Fields
if( isset( $_POST['eb_user_address'] ) ) {
$eagle_booking_form_address = sanitize_text_field( $_POST['eb_user_address'] );
} else {
$eagle_booking_form_address = '';
}
if( isset( $_POST['eb_user_city'] ) ) {
$eagle_booking_form_city = sanitize_text_field( $_POST['eb_user_city'] );
} else {
$eagle_booking_form_city = '';
}
if( isset( $_POST['eb_user_country'] ) ) {
$eagle_booking_form_country = sanitize_text_field( $_POST['eb_user_country'] );
} else {
$eagle_booking_form_country = '';
}
if( isset( $_POST['eb_user_zip'] ) ) {
$eagle_booking_form_zip = sanitize_text_field( $_POST['eb_user_zip'] );
} else {
$eagle_booking_form_zip = '';
}
if( isset( $_POST['eb_user_requests'] ) ) {
$eagle_booking_form_requests = sanitize_text_field( $_POST['eb_user_requests'] );
} else {
$eagle_booking_form_requests = '';
}
if( isset( $_POST['eb_user_arrival'] ) ) {
$eagle_booking_form_arrival = sanitize_text_field( $_POST['eb_user_arrival'] );
} else {
$eagle_booking_form_arrival = '';
}
// Coupon
if( isset( $_POST['eb_coupon_code'] ) ) {
$eagle_booking_form_coupon = sanitize_text_field( $_POST['eb_coupon_code'] );
} else {
$eagle_booking_form_coupon = '';
}
$eagle_booking_form_final_price = $eb_booking_price;
/**
* Deposit Amount
*/
$eagle_booking_deposit_amount = $eagle_booking_form_final_price * eb_get_option('eagle_booking_deposit_amount') / 100;
/**
* Include booking details
*/
include eb_load_template('checkout/details.php');
if ( eagle_booking_is_qnt_available( eb_room_availability( $eagle_booking_room_id, $eagle_booking_form_date_from, $eagle_booking_form_date_to), $eagle_booking_form_date_from, $eagle_booking_form_date_to, $eagle_booking_room_id ) == 0 ) {
eb_notice( 'error', __('The room is not available.','eagle-booking') );
} else {
/**
* Include payment details
*/
include eb_load_template('checkout/payment.php');
}
// Details Page (After the payment)
} elseif ( $eagle_booking_payment_method == 'bank' OR isset($_GET['tx']) OR isset($_GET['order_id']) OR isset($_POST['tx_ref']) OR isset( $_POST['razorpay_payment_id'] ) OR $eagle_booking_payment_method == 'stripe' OR isset($_GET['sid']) OR isset($_POST['paystack_reference']) OR isset($_POST['key']) OR $eagle_booking_payment_method == 'payment_on_arrive' OR $eagle_booking_payment_method == 'booking_request' ) {
// Get payment method
foreach ( glob ( EB_PATH . 'core/admin/gateways/*/payment.php' ) as $file ){
include_once $file;
}
/**
* Include additional services
*/
include eb_load_template('checkout/additional-services.php');
// Get the payment method text
if( $eagle_booking_form_action_type === 'payment_on_arrive' ) {
$eagle_booking_checkout_payment_type = __('Payment on Arrival', 'eagle-booking');
} elseif ($eagle_booking_form_action_type === '2checkout') {
$eagle_booking_checkout_payment_type = __('2Checkout', 'eagle-booking');
} elseif ($eagle_booking_form_action_type === 'bank_transfer') {
$eagle_booking_checkout_payment_type = __('Bank Transfer', 'eagle-booking');
} elseif ($eagle_booking_form_action_type === 'PayU') {
$eagle_booking_checkout_payment_type = __('PayU', 'eagle-booking');
} elseif ($eagle_booking_form_action_type === 'paystack') {
$eagle_booking_checkout_payment_type = __('Paystack', 'eagle-booking');
} elseif ($eagle_booking_form_action_type === 'flutterwave') {
$eagle_booking_checkout_payment_type = __('Flutterwave', 'eagle-booking');
} elseif ($eagle_booking_form_action_type === 'razorpay') {
$eagle_booking_checkout_payment_type = __('Razorpay', 'eagle-booking');
} elseif ($eagle_booking_form_action_type === 'booking_request') {
$eagle_booking_checkout_payment_type = __('Booking Request', 'eagle-booking');
} elseif ($eagle_booking_form_action_type === 'stripe') {
$eagle_booking_checkout_payment_type = __('Stripe', 'eagle-booking');
} elseif ($eagle_booking_form_action_type === 'paypal') {
$eagle_booking_checkout_payment_type = __('PayPal', 'eagle-booking');
} elseif ($eagle_booking_form_action_type === 'vivawallet') {
$eagle_booking_checkout_payment_type = __('Viva Wallet', 'eagle-booking');
}
// Check if room is still available
if ( eagle_booking_is_qnt_available( eb_room_availability($eagle_booking_room_id, $eagle_booking_form_date_from, $eagle_booking_form_date_to), $eagle_booking_form_date_from, $eagle_booking_form_date_to, $eagle_booking_room_id) == 1 ) {
// User Details
$eb_user_id = get_current_user_id();
$eb_user_ip = eb_user_ip();
if ($eb_user_id == '') $eb_user_id = 0;
/**
* Room ID based on used multi-language plugin (WPML or Polylang)
*/
if ( function_exists('wpml_loaded') ) {
$eagle_booking_room_id = apply_filters('wpml_object_id', $eagle_booking_room_id, 'eagle_rooms', true, apply_filters('wpml_default_language', NULL ));
} elseif ( function_exists('pll_the_languages') ) {
$eagle_booking_room_id = pll_get_post( $eagle_booking_room_id, pll_default_language() );
} else {
$eagle_booking_room_id = $eagle_booking_room_id ;
}
/**
* Check if payment has been completed
*/
if ($eagle_booking_payment_completed == true) {
/**
* Insert the booking into the DB
*/
$eb_insert_booking_in_db = eb_insert_booking_into_db (
$eagle_booking_room_id,
$eagle_booking_room_title,
$eagle_booking_date,
$eagle_booking_form_date_from,
$eagle_booking_form_date_to,
$eagle_booking_form_guests,
$eagle_booking_form_adults,
$eagle_booking_form_children,
$eb_room_price,
$eagle_booking_form_final_price,
$eagle_booking_deposit_amount,
$eagle_booking_form_extra_services,
$eb_user_id,
$eagle_booking_form_name,
$eagle_booking_form_surname,
$eagle_booking_form_email,
$eb_user_ip,
$eagle_booking_form_phone,
$eagle_booking_form_address.' '.$eagle_booking_form_zip,
$eagle_booking_form_city,
$eagle_booking_form_country,
$eagle_booking_form_requests,
$eagle_booking_form_arrival,
$eagle_booking_form_coupon,
$eagle_booking_form_payment_status,
$eagle_booking_form_currency,
$eagle_booking_transaction_id,
$eagle_booking_form_action_type,
'direct'
);
/**
* Check if booking has been added successfull in the DB
*/
if ( $eb_insert_booking_in_db == true ) {
$eagle_booking_checkin_original = DateTime::createFromFormat('m/d/Y', $eagle_booking_form_date_from);
$eagle_booking_checkout_original = DateTime::createFromFormat('m/d/Y', $eagle_booking_form_date_to);
/**
* Include thank you page
*/
include eb_load_template('checkout/thankyou.php');
} else {
eb_notice( 'error', __('There was an unexpected error with your booking, please get in touch with us using our','eagle-booking'). ' <a href="'.eagle_booking_contact_page().'">' .__('contact form', 'eagle-booking').' '. '</a>' .__('for more details.', 'eagle-booking') );
}
} else {
eb_notice( 'error', __('Payment failed, please get in touch with us using our','eagle-booking').' '. ' <a href="'.eagle_booking_contact_page().'">' .__('contact form', 'eagle-booking').' '. '</a>' .__('for more details.', 'eagle-booking') );
}
} else {
eb_notice( 'error', __('The room is not available.','eagle-booking') );
}
} else {
eb_notice( 'error', __('Booking with these details already exists.','eagle-booking') );
}
return ob_get_clean();
}
// Depracated Shortcode (Will be removed soon)
add_shortcode('eagle_booking_checkout', 'eb_checkout_shortcode');
/**
* Checkout Page Shortcode
*/
add_shortcode('eb_checkout', 'eb_checkout_shortcode');

View File

@@ -0,0 +1,501 @@
<?php
/* --------------------------------------------------------------------------
* Search Page Shortcode
* @since 1.0.0
* @modified 1.2.4
---------------------------------------------------------------------------*/
defined('ABSPATH') || exit;
ob_start();
function eb_search_page_shortcode() {
/**
* Include Stepline
*/
if ( eb_get_option('eb_stepline' ) == true ) include eb_load_template('elements/stepline.php');
// Plugins Options
$eagle_booking_rooms_per_page = eb_get_option('eagle_booking_rooms_per_page');
$eagle_booking_price_range_min = eb_get_option('eb_price_range_min');
$eagle_booking_price_range_max = eb_get_option('eb_price_range_max');
$eagle_booking_guests = eb_get_option('eb_default_guests');
$eagle_booking_adults = eb_get_option('eb_default_adults');
$eagle_booking_children = eb_get_option('eb_default_children');
// Price Range
if( empty( $eagle_booking_price_range_min ) || eb_get_option('eagle_booking_search_page_settings')['price_range_filter'] == false ) {
$eagle_booking_price_range_min = eb_rooms_min_max_price('min');
}
if( empty( $eagle_booking_price_range_max ) || eb_get_option('eagle_booking_search_page_settings')['price_range_filter'] == false ) {
$eagle_booking_price_range_max = eb_rooms_min_max_price('max');
}
// Defaults
$eagle_booking_checkin = '';
$eagle_booking_checkout = '';
$eagle_booking_nights = 0;
$eagle_booking_dates = '';
$eagle_booking_checkin_param = 'eb_checkin';
$eagle_booking_checkout_param = 'eb_checkout';
$eagle_booking_guests_param = '';
$eagle_booking_adults_param = '';
$eagle_booking_children_param = '';
// GET values from search form (Homepage)
if( isset( $_GET['eb_checkin']) && isset( $_GET['eb_checkout']) ) {
// Check-In/Out
$eagle_booking_checkin = sanitize_text_field( $_GET['eb_checkin'] );
$eagle_booking_checkout = sanitize_text_field( $_GET['eb_checkout'] );
// Guests
if ( eb_get_option('eb_adults_children') == true ) {
$eagle_booking_adults = sanitize_text_field( $_GET['eb_adults'] );
$eagle_booking_children = sanitize_text_field( $_GET['eb_children'] );
$eagle_booking_guests = $eagle_booking_adults;
} else {
$eagle_booking_guests = sanitize_text_field( $_GET['eb_guests'] );
$eagle_booking_children = 0;
}
// Format checkin & checkout dates from m-d-y to displayd system format (m/d/Y)
$eagle_booking_checkin = DateTime::createFromFormat("m-d-Y", $eagle_booking_checkin)->format('m/d/Y');
$eagle_booking_checkout = DateTime::createFromFormat("m-d-Y", $eagle_booking_checkout)->format('m/d/Y');
// Booking Dates
$eagle_booking_dates = eagle_booking_displayd_date_format($eagle_booking_checkin). ' ' .' ' .' → '. ' ' .' ' .eagle_booking_displayd_date_format($eagle_booking_checkout);
// Booking Nights
$eagle_booking_nights = eb_total_booking_nights($eagle_booking_checkin, $eagle_booking_checkout);
}
if ( isset( $_GET['eb_view']) && $_GET['eb_view'] === 'grid' ) {
$eb_rooms_view = 'grid-view';
} else {
$eb_rooms_view = 'list-view';
}
/* --------------------------------------------------------------------------
* DEFAULT QUERRY
---------------------------------------------------------------------------*/
$eagle_booking_paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1 ;
$args = array(
'post_type' => 'eagle_rooms',
'post_status' => 'publish',
'posts_per_page' => $eagle_booking_rooms_per_page,
'meta_query' => array(
// Min Price
array(
'key' => 'eagle_booking_mtb_room_price_min',
'type' => 'numeric',
'value' => $eagle_booking_price_range_min,
'compare' => '>=',
),
// Max Price
array(
'key' => 'eagle_booking_mtb_room_price_min',
'type' => 'numeric',
'value' => $eagle_booking_price_range_max,
'compare' => '<=',
),
// Exclude
array(
'key' => 'eagle_booking_mtb_room_excluded',
'compare' => 'NOT EXISTS',
),
),
'paged' => $eagle_booking_paged
);
if ( eb_get_option('eb_adults_children') == true ) {
// Adults
$args['meta_query'][] = array(
'key' => 'eagle_booking_mtb_room_max_adults',
'type' => 'numeric',
'value' => $eagle_booking_adults,
'compare' => '>='
);
// Children
$args['meta_query'][] = array(
'key' => 'eagle_booking_mtb_room_max_children',
'type' => 'numeric',
'value' => $eagle_booking_children,
'compare' => '>='
);
} else {
// Guests
$args['meta_query'][] = array(
'key' => 'eagle_booking_mtb_room_maxguests',
'type' => 'numeric',
'value' => $eagle_booking_guests,
'compare' => '>='
);
}
// Branch
if( isset( $_GET['eb_branch'] ) && $_GET['eb_branch'] != 'all' ) {
$eb_selected_branch = $_GET['eb_branch'];
$args['tax_query'][] = array(
'taxonomy' => 'eagle_branch',
'field' => 'term_id',
'terms' => $eb_selected_branch,
);
} else {
$eb_selected_branch = '';
}
$the_query = new WP_Query( $args );
// Pagination
$eagle_booking_results_qnt = $the_query->found_posts;
$eagle_booking_qnt_pagination = ceil($eagle_booking_results_qnt / $eagle_booking_rooms_per_page);
?>
<div class="eb-search-page eb-sticky-sidebar-container eb-sidebar eb-left-sidebar">
<?php
/**
* Include Filters
*/
include eb_load_template('search/filters.php');
?>
<div>
<?php
/**
* Include Sorting
*/
include eb_load_template('search/sorting.php');
?>
<div class="eb-rooms <?php echo esc_attr( $eb_rooms_view ) ?>">
<div class="eb-rooms-list">
<?php
while ( $the_query->have_posts() ) : $the_query->the_post();
/**
* Include Room
*/
include eb_load_template('search/room.php');
endwhile;
/**
* Include Pagination
*/
include eb_load_template('search/pagination.php');
?>
</div>
</div>
<?php if ( $eagle_booking_results_qnt == 0 ) : ?>
<div id="eb-no-search-results" class="eb-alert mt20 text-center" role="alert">
<?php echo __('No results for this search','eagle-booking') ?>
</div>
<?php endif; ?>
</div>
</div>
<?php
/**
* Enqueue Search Page JS & AJAX
*/
wp_enqueue_script( 'eb-search', EB_URL .'assets/js/search.js', array( 'jquery' ), EB_VERSION, true );
wp_localize_script(
'eb-search', 'eb_search',
array(
'eb_ajax_nonce' => wp_create_nonce( 'eb_nonce' ),
)
);
// Clean Buffer
return ob_get_clean();
}
// Depracated Shortcode (Will be removed soon)
add_shortcode('eagle_booking_search_results', 'eb_search_page_shortcode');
// Search Page Shotcode
add_shortcode('eb_search', 'eb_search_page_shortcode');
function eagle_booking_filters() {
// Check Nonce
if ( !check_ajax_referer('eb_nonce', 'eb_search_filters_nonce', false) ) { ?>
<div id="eb-no-search-results" class="eb-alert mt20 text-center" role="alert">
<?php echo __('Invalid Nonce', 'eagle-booking') ?>
</div>
<?php } else {
// Plugin Options
$eagle_booking_rooms_per_page = eb_get_option('eagle_booking_rooms_per_page');
// Recover Values (Ajax Request)
$eagle_booking_paged = sanitize_text_field( $_GET['eagle_booking_paged'] );
$eagle_booking_checkin = sanitize_text_field( $_GET['eagle_booking_checkin'] );
$eagle_booking_checkout = sanitize_text_field( $_GET['eagle_booking_checkout'] );
$eagle_booking_price_range_min = sanitize_text_field( $_GET['eagle_booking_min_price'] );
$eagle_booking_price_range_max = sanitize_text_field( $_GET['eagle_booking_max_price'] );
$eb_normal_services = sanitize_text_field( $_GET['eb_normal_services'] );
$eb_additional_services = sanitize_text_field( $_GET['eb_additional_services'] );
$eb_branch_id = sanitize_text_field( $_GET['eb_branch_id'] );
$eagle_booking_search_sorting_filter_meta_key = sanitize_text_field( $_GET['eagle_booking_search_sorting_filter_meta_key'] );
$eagle_booking_search_sorting_filter_order = sanitize_text_field( $_GET['eagle_booking_search_sorting_filter_order'] );
$eb_rooms_view = sanitize_text_field( $_GET['view'] );
// Guests
if (eb_get_option('eb_adults_children') == true) {
$eagle_booking_adults = sanitize_text_field( $_GET['eagle_booking_adults'] );
$eagle_booking_children = sanitize_text_field( $_GET['eagle_booking_children'] );
$eagle_booking_guests = $eagle_booking_adults;
} else {
$eagle_booking_guests = sanitize_text_field($_GET['eagle_booking_guests']);
$eagle_booking_children = 0;
}
$eagle_booking_checkin = eagle_booking_system_date_format($eagle_booking_checkin);
$eagle_booking_checkout = eagle_booking_system_date_format($eagle_booking_checkout);
// Price Range
if (empty($eagle_booking_price_range_min)) {
$eagle_booking_price_range_min = eb_rooms_min_max_price('min');
}
if (empty($eagle_booking_price_range_max)) {
$eagle_booking_price_range_max = eb_rooms_min_max_price('max');
}
// Sorting
if (empty($eagle_booking_search_sorting_filter_meta_key)) {
$eagle_booking_booking_order_by = 'date';
$eagle_booking_booking = 'DESC';
} else {
$eagle_booking_booking_order_by = 'meta_value_num';
$eagle_booking_booking = $eagle_booking_search_sorting_filter_order;
}
/* --------------------------------------------------------------------------
* AJAX QUERRY
---------------------------------------------------------------------------*/
$args = array(
'post_type' => 'eagle_rooms',
'post_status' => 'publish',
'post__not_in' => array(),
'posts_per_page' => $eagle_booking_rooms_per_page,
'orderby' => $eagle_booking_booking_order_by,
'meta_key' => $eagle_booking_search_sorting_filter_meta_key,
'order' => $eagle_booking_booking,
'suppress_filters' => false,
'meta_query' => array(
// Min Price
array(
'key' => 'eagle_booking_mtb_room_price_min',
'type' => 'numeric',
'value' => $eagle_booking_price_range_min,
'compare' => '>=',
),
// Max Price
array(
'key' => 'eagle_booking_mtb_room_price_min',
'type' => 'numeric',
'value' => $eagle_booking_price_range_max,
'compare' => '<=',
),
// Exclude
array(
'key' => 'eagle_booking_mtb_room_excluded',
'compare' => 'NOT EXISTS',
),
),
'paged' => $eagle_booking_paged
);
if ( eb_get_option('eb_adults_children') == true ) {
// Adults
$args['meta_query'][] = array(
'key' => 'eagle_booking_mtb_room_max_adults',
'type' => 'numeric',
'value' => $eagle_booking_adults,
'compare' => '>='
);
// Children
$args['meta_query'][] = array(
'key' => 'eagle_booking_mtb_room_max_children',
'type' => 'numeric',
'value' => $eagle_booking_children,
'compare' => '>='
);
} else {
// Guests
$args['meta_query'][] = array(
'key' => 'eagle_booking_mtb_room_maxguests',
'type' => 'numeric',
'value' => $eagle_booking_guests,
'compare' => '>='
);
}
/* --------------------------------------------------------------------------
* Normal Services Filter
---------------------------------------------------------------------------*/
if ( $eb_normal_services ) {
$eb_normal_services_array = explode(',', $eb_normal_services);
for ( $eb_normal_services_i = 0; $eb_normal_services_i < count($eb_normal_services_array); $eb_normal_services_i++ ) {
$eb_normal_room_service = get_post( $eb_normal_services_array[$eb_normal_services_i], OBJECT, 'eagle_services' );
if( is_object( $eb_normal_room_service ) ) {
$eb_normal_service_id = $eb_normal_room_service->ID;
$args ['meta_query'][] = array(
'key' => 'eagle_booking_mtb_room_services',
'value' => $eb_normal_service_id,
'compare' => 'LIKE',
);
}
}
}
/* --------------------------------------------------------------------------
* Additional Services Filter
---------------------------------------------------------------------------*/
if ( $eb_additional_services ) {
$eb_additional_services_array = explode(',', $eb_additional_services);
for ($eb_additional_services_i = 0; $eb_additional_services_i < count($eb_additional_services_array); $eb_additional_services_i++) {
$eb_room_additional_service = get_post( $eb_additional_services_array[$eb_additional_services_i], OBJECT, 'eagle_services' );
if( is_object( $eb_room_additional_service ) ) {
$eb_additional_service_id = $eb_room_additional_service->ID;
$args['meta_query'][] = array(
'key' => 'eagle_booking_mtb_room_additional_services',
'value' => $eb_additional_service_id,
'compare' => 'LIKE',
);
}
}
}
/* --------------------------------------------------------------------------
* Branches Filter
---------------------------------------------------------------------------*/
if ( $eb_branch_id ) {
$args['tax_query'][] = array(
'taxonomy' => 'eagle_branch',
'field' => 'term_id',
'terms' => $eb_branch_id,
);
}
// Add all args to the query
$the_query = new WP_Query($args);
// Pagination
$eagle_booking_results_qnt = $the_query->found_posts;
$eagle_booking_qnt_pagination = ceil($eagle_booking_results_qnt / $eagle_booking_rooms_per_page);
?>
<div class="eb-rooms-list">
<input type="hidden" name="eagle_booking_results_qnt" id="eagle_booking_results_qnt" value="<?php echo $eagle_booking_results_qnt ?>">
<?php
while ($the_query->have_posts()) : $the_query->the_post();
/**
* Include Room
*/
include eb_load_template('search/room.php');
endwhile;
/**
* Include Pagination
*/
include eb_load_template('search/pagination.php');
?>
</div>
<?php if ($eagle_booking_results_qnt == 0) : ?>
<div id="eb-no-search-results" class="eb-alert mt20 text-center" role="alert">
<?php echo __('No results for this search', 'eagle-booking') ?>
</div>
<?php endif; ?>
<?php
}
// Reset Wuery
wp_reset_query();
wp_die();
}
// Actions
add_action( 'wp_ajax_eb_search_filters_action', 'eagle_booking_filters' );
add_action( 'wp_ajax_nopriv_eb_search_filters_action', 'eagle_booking_filters' );