Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  • Hook Reference
  • Docs Home

Packages

  • BKAP
    • Addons
    • Admin-Bookings
    • Attribute-Lockout
    • Block-Pricing
    • Booking-Box
    • Booking-Confirmation
    • Booking-Process
    • Cancel-Order
    • Cart
    • Checkout-Process
    • Core
    • Date-Time
    • Emails
    • Functions
    • Global-Function
    • Global-Settings
    • Google-Calendar-Sync
    • ICS
    • Import-Booking
    • Labels
    • License
    • Menus
    • Meta-Boxes
    • Reschedule
    • Resources
    • Search-Widget
    • Special-Price
    • Uninstall
    • Validation
    • Variation-Lockout
    • Vendors
      • Dokan
      • WC-Vendors
    • View-Bookings
  • None

Classes

  • bkap_addon_compatibility_class
  • bkap_admin_bookings
  • bkap_approve_booking
  • bkap_attributes
  • bkap_block_booking
  • BKAP_Booking
  • bkap_booking_box_class
  • bkap_booking_confirmation
  • bkap_booking_process
  • BKAP_Bookings_View
  • bkap_calendar_sync
  • bkap_cancel_order
  • bkap_cart
  • bkap_checkout
  • bkap_common
  • BKAP_Customer_Meta_Box
  • BKAP_Details_Meta_Box
  • bkap_dokan_calendar_class
  • bkap_dokan_class
  • bkap_dokan_orders_class
  • bkap_dokan_products_class
  • bkap_edit_bookings_class
  • BKAP_Email_Booking_Cancelled
  • BKAP_Email_Booking_Confirmed
  • BKAP_Email_Booking_Rescheduled_Admin
  • BKAP_Email_Imported_Event
  • BKAP_Email_Manager
  • BKAP_Email_New_Booking
  • BKAP_Gcal
  • BKAP_Gcal_Event
  • bkap_gcal_sync_settings
  • bkap_global_settings
  • BKAP_Google_Events_View
  • bkap_ics
  • bkap_license
  • bkap_load_scripts_class
  • BKAP_OPC_Addon
  • BKAP_Payment_Gateway
  • BKAP_Product_Resource
  • bkap_rescheduled_order_class
  • BKAP_Resource_Details_Meta_Box
  • BKAP_Save_Meta_Box
  • bkap_special_booking_price
  • bkap_timeslot_price
  • bkap_validation
  • bkap_variations
  • BKAP_Vendors
  • bkap_wc_vendors
  • bkap_wcv_product
  • Booking_Information_In_Voucher_Template
  • Class_Bkap_Product_Resource
  • Custom_WooCommerce_Widget_Product_Search
  • EDD_BOOK_Plugin_Updater
  • global_menu
  • import_bookings
  • product_gcal_settings
  • view_bookings
  • WAPBK_Import_Bookings_Table
  • WAPBK_View_Bookings_Table
  • woocommerce_booking

Functions

  • addDayswithdate
  • bkap_400_create_meta
  • bkap_400_recurring_data
  • bkap_400_update_db_tab
  • bkap_400_update_enable_specific
  • bkap_400_update_enable_week_blocking
  • bkap_400_update_holidays
  • bkap_400_update_ranges
  • bkap_400_update_recurring_lockout
  • bkap_400_update_settings
  • bkap_400_update_special
  • bkap_400_update_specific
  • bkap_410_create_meta
  • bkap_410_update_block_pricing_option_values_in_new_way
  • bkap_410_update_fixed_blocks
  • bkap_410_update_price_ranges
  • bkap_410_update_settings
  • bkap_420_add_gcal_posts
  • bkap_420_add_gcal_tour_posts
  • bkap_420_gcal_batch_size
  • bkap_420_gcal_meta
  • bkap_420_update_settings
  • bkap_add_days_to_date
  • bkap_array_of_given_date_range
  • bkap_booked_resources
  • bkap_booking_posts_for_resource
  • bkap_calculate_bookings_for_resource
  • bkap_check_booking_available
  • bkap_check_day_booking_available
  • bkap_check_for_max_date
  • bkap_check_for_min_date
  • bkap_check_holiday
  • bkap_check_in_custom_holiday_range
  • bkap_check_resource_available
  • bkap_check_resource_booked_in_date_range
  • bkap_db_420_1
  • bkap_db_420_2
  • bkap_delete_event_from_gcal
  • bkap_delete_folder_and_files
  • bkap_delete_options
  • bkap_delete_tables
  • bkap_find_matching_product_variation
  • bkap_generate_bookable_data
  • bkap_get_book_arrays
  • bkap_get_book_t
  • bkap_get_booked
  • bkap_get_booked_checkout
  • bkap_get_custom_posts
  • bkap_get_dateToCal
  • bkap_get_day_between_Week
  • bkap_get_db_count
  • bkap_get_escapeString
  • bkap_get_lockout
  • bkap_get_month_range
  • bkap_get_post_meta
  • bkap_get_posted_availability
  • bkap_get_total_timeslot_maximum_booking
  • bkap_get_week_range
  • bkap_import_events_cron
  • bkap_insert_event_to_gcal
  • bkap_manual_db_update_v420
  • bkap_orderby_date_key
  • bkap_save_resources
  • bkap_sort_by_from_time
  • bkap_update_po_file
  • bkap_vendors_get_bookings
  • bkap_widgets_init
  • bkapSortByPriority
  • calback_bkap_max_date
  • check_in_fixed_block_booking
  • check_in_range
  • check_in_range_abp
  • check_in_range_holidays
  • check_in_range_weekdays
  • create_posts
  • get_availability_for_date
  • get_booked_multiple
  • get_bookings_for_date
  • get_bookings_for_range
  • get_date_lockout
  • get_slot_availability
  • get_slot_lockout
  • get_standard_decimal_thousand_separator_price
  • is_booking_active
  • woocommerce_bkap_add_cron_schedule
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 
<?php
/**
 * Booking & Appointment Plugin for WooCommerce
 *
 * Class for Handling the timeslot pricing and to add hidden data on front end product page of the date and time booking product
 *
 * @author      Tyche Softwares
 * @category    Core
 * @package     BKAP/Special-Price
 * @version     2.0
 */

if ( !class_exists( 'bkap_special_booking_price' ) ) {
    
    /**
     * Class for Handling Special Pricing 
     * @class bkap_special_booking_price
     */

    class bkap_special_booking_price {

        /**
         * Default constructor
         *
         * @since 2.0
         */

        public function __construct() {
                
            // Display updated price on the product page
            add_action( 'bkap_display_updated_addon_price',         array( &$this, 'special_booking_display_updated_price' ), 2, 3 );
                
            // Display the multiple days specia  booking price on the product page
            add_action( 'bkap_display_multiple_day_updated_price',   array( &$this, 'bkap_special_booking_show_multiple_updated_price' ), 7, 8 );
        }       
                
        /**
         * This function is used to add/update special booking
         *
         * @since 2.0
         * @global object $wpdb Global wpdb Object
         * @param int $post_id Product ID
         * @param array $recurring_prices Array of special price set for Weekdays
         * @param array $specific_prices Array of special price set for Specific Date
         */

        function bkap_save_special_booking_price( $post_id, $recurring_prices = array(), $specific_prices = array() ) {
            
            global $wpdb;
                
            // Get the existing record
            $booking_special_prices = get_post_meta( $post_id, '_bkap_special_price', true );
            
            if ( is_array( $booking_special_prices ) && count( $booking_special_prices ) > 0 ) {
                $cnt = count( $booking_special_prices );
            } else {
                $booking_special_prices = array();
                $cnt = 0; 
            }

            /** 
             * this is being done only to make sure the code is compatible with PHP versions lower than 5.3
             * it should be removed when we decide to upgrade everything to 5.3+
             */
            
            // Loop through the existing records, note down the weekday/date and the key
            
            $special_prices = array();
            
            if ( is_array( $booking_special_prices ) && count( $booking_special_prices ) > 0 ) {
                foreach( $booking_special_prices as $special_key => $special_value ) {
                    $weekday_set = $special_value[ 'booking_special_weekday' ];
                    $date_set = $special_value[ 'booking_special_date' ];
                    if ( $weekday_set != "" ) {
                        $special_prices[ $weekday_set ] = $special_key;
                    } else if ( $date_set != "" ) {
                        $special_prices[ $date_set ] = $special_key;
                    }
                }
            }

            $max_key_value = 0;

            if ( is_array( $special_prices ) && count( $special_prices ) > 0 ) {
                $max_key_value = max( $special_prices );
            }
            // Run a loop through all weekdays
            if ( is_array( $recurring_prices ) && count( $recurring_prices ) > 0 ) {
                foreach( $recurring_prices as $w_key => $w_price ) {
                    // check if record exists for the given weekday
                    if ( $cnt > 0 ) {
                        // if record is present, we need the key
                     /* commented as USE is available only for PHP 5.3+
                        $key = key( array_filter( $booking_special_prices, function( $item ) use( $w_key ) {
                            return isset( $item[ 'booking_special_weekday' ] ) && $w_key == $item[ 'booking_special_weekday' ];
                        }) ); */
                        
                        if ( array_key_exists( $w_key, $special_prices ) ) {
                            $key = $special_prices[ $w_key ];
                        }
                    }
                    // if key is found, update the existing record
                    if ( isset( $key ) && is_numeric( $key ) && $key >= 0 ) {
                        $booking_special_prices[ $key ][ 'booking_special_weekday' ]  = $w_key;
                        $booking_special_prices[ $key ][ 'booking_special_date' ]     = '';
                        $booking_special_prices[ $key ][ 'booking_special_price' ]    = $w_price;
                        $key = ''; // reset the key
                    } else { // add a new one
                        $max_key_value++;
                        $booking_special_prices[ $max_key_value ][ 'booking_special_weekday' ]  = $w_key;
                        $booking_special_prices[ $max_key_value ][ 'booking_special_date' ]     = '';
                        $booking_special_prices[ $max_key_value ][ 'booking_special_price' ]    = $w_price;
                        $cnt++; // increment the count
                    }
                }
            }
            
            // Loop through all specific dates
            if ( is_array( $specific_prices ) && count( $specific_prices ) > 0 ) {
                foreach( $specific_prices as $w_key => $w_price ) {
    
                    $w_key = date( 'Y-m-d', strtotime( $w_key ) );
                    // Check if record exists for the given date
                    if ( $cnt > 0 ) {
                        // If record is present, we need the key
                     /* commented as USE is available only for PHP 5.3+
                        $key = key( array_filter( $booking_special_prices, function( $item ) use( $w_key ) {
                            return isset( $item[ 'booking_special_date' ] ) && $w_key == $item[ 'booking_special_date' ];
                        }) ); */
                        if ( array_key_exists( $w_key, $special_prices ) ) {
                            $key = $special_prices[ $w_key ];
                        }
                    }
                    // If key found, update existing record
                    if ( isset( $key ) && is_numeric( $key ) && $key >= 0 ) {
                        $booking_special_prices[ $key ][ 'booking_special_weekday' ]  = '';
                        $booking_special_prices[ $key ][ 'booking_special_date' ]     = $w_key;
                        $booking_special_prices[ $key ][ 'booking_special_price' ]    = $w_price;
                        $key = ''; // reset the key
                    } else { // add a new record
                        $max_key_value++;
                        $booking_special_prices[ $max_key_value ][ 'booking_special_weekday' ]  = '';
                        $booking_special_prices[ $max_key_value ][ 'booking_special_date' ]     = $w_key;
                        $booking_special_prices[ $max_key_value ][ 'booking_special_price' ]    = $w_price;
                        $cnt++; // increment the count
                    }
                }
            }
                        
            // Unset any records for recurring weekdays where price may have been reset to blanks
            if ( is_array( $special_prices ) && count( $special_prices ) > 0 ) {
                foreach( $special_prices as $s_key => $s_value ) {
                     
                    if ( substr( $s_key, 0, 7 ) == 'booking' ) {
                        if ( ! array_key_exists( $s_key, $recurring_prices ) ) {
                            unset( $booking_special_prices[ $s_value ] );
                        } 
                    } else { // it's a specific date
                        $key_check = date( 'j-n-Y', strtotime( $s_key ) );
                        if ( ! array_key_exists( $key_check, $specific_prices ) ) {
                            unset( $booking_special_prices[ $s_value ] );
                        }
                    }
                }
            }
            
            // Update the record in the DB
            update_post_meta( $post_id, '_bkap_special_price', $booking_special_prices );
            
        }
            
        /**
         * This function is used to updated price of product
         *
         * @since 2.0
         * @hook bkap_display_updated_addon_price
         * @global object $wpdb Global wpdb Object
         * @param int $product_id Product ID
         * @param string $booking_date Date
         * @param int $variation_id Variation ID
         */

        function special_booking_display_updated_price( $product_id, $booking_date, $variation_id ){ 
            
            $_product       = wc_get_product( $product_id );
            $product_type   = $_product->get_type();
            
            if ( $product_type == 'grouped' ) {
                $special_price_present = 'NO';
                $currency_symbol       = get_woocommerce_currency_symbol();
                $has_children          = '';
                $price_str             = '';
                $raw_price_str         = '';
                $price_arr             = array();
                    
                if ( $_product->has_child() ) {
                    $has_children = "yes";
                    $child_ids    = $_product->get_children();
                }
                    
                $quantity_grp_str  = $_POST[ 'quantity' ];
                
                $quantity_array    = explode( ",", $quantity_grp_str );
                $i                 = 0;
                    
                foreach ( $child_ids as $k => $v ) {
                    $final_price              = 0;
                    $child_product            = wc_get_product( $v );
                    $product_type_child       = $child_product->get_type();
                    $product_price            = bkap_common::bkap_get_price( $v, 0, 'simple' );
                    $special_booking_price    = $this->get_price( $v, $booking_date );
                    
                    if ( isset( $special_booking_price ) && $special_booking_price != 0 && $special_booking_price != '' ) {
                        $special_price_present   = 'YES';
                        $final_price             = $special_booking_price * trim( $quantity_array[ $i ] );
                        $raw_price               = $final_price;
                        
                        if ( function_exists( 'icl_object_id' ) ) {
                            global $woocommerce_wpml;
                            // Multi currency is enabled
                            if ( isset( $woocommerce_wpml->settings[ 'enable_multi_currency' ] ) && $woocommerce_wpml->settings[ 'enable_multi_currency' ] == '2' ) {
                                $custom_post = bkap_common::bkap_get_custom_post( $v, 0, $product_type );
                                if( $custom_post == 0 ) {
                                    $raw_price = apply_filters( 'wcml_raw_price_amount', $final_price );
                                }
                            } 
                        } 
                        $wc_price_args = bkap_common::get_currency_args();
                        $final_price = wc_price( $raw_price, $wc_price_args );
                        
                        $raw_price_str .= $v . ":" . $raw_price . ",";
                        $price_str .= $child_product->get_title() . ": " . $final_price . "<br>";
                    } else {
                        $final_price = $product_price * trim( $quantity_array[$i] );
                        $raw_price = $final_price;
                        if ( function_exists( 'icl_object_id' ) ) {
                            global $woocommerce_wpml;
                            // Multi currency is enabled
                            if ( isset( $woocommerce_wpml->settings[ 'enable_multi_currency' ] ) && $woocommerce_wpml->settings[ 'enable_multi_currency' ] == '2' ) {
                                $custom_post = bkap_common::bkap_get_custom_post( $v, 0, $product_type );
                                if( $custom_post == 0 ) {
                                    $raw_price = apply_filters( 'wcml_raw_price_amount', $final_price );
                                }
                            } 
                        } 
                        $wc_price_args = bkap_common::get_currency_args();
                        $final_price = wc_price( $raw_price, $wc_price_args );
                            
                        $raw_price_str .= $v . ":" . $raw_price . ",";
                        $price_str .= $child_product->get_title() . ": " . $final_price . "<br>";
                    }
                    $i++;
                }
                if ( isset( $price_str ) && $price_str != '' ) {
                    $special_booking_price = $price_str;
                    if ( $special_price_present == 'YES' ) {
                        $_POST[ 'special_booking_price' ] = $special_booking_price;
                        $_POST[ 'grouped_raw_price' ] = $raw_price_str;
                    }
                }
            } else {
                $special_booking_price = $this->get_price( $product_id, $booking_date );
                
                if ( isset( $special_booking_price ) && $special_booking_price != '' ) {

                    $_POST[ 'special_booking_price' ] = $special_booking_price;
                }
            }       
        }

        /**
         * This function will calculate the special price for specific date or weekday
         *
         * @since 4.0.0
         * @param int $product_id Product ID
         * @param string $booking_date Date
         * @return int $special_booking_price Returns the special price 
         */
            
        function get_price( $product_id, $booking_date ) {

            $booking_special_prices = get_post_meta( $product_id, '_bkap_special_price', true );
            $special_booking_price  = "";
            if ( is_array( $booking_special_prices ) && count( $booking_special_prices ) > 0 ) {
                foreach ( $booking_special_prices as $key => $values ){
                    list( $year, $month, $day ) = explode( "-", $booking_date );
                        
                    if ( $values[ 'booking_special_date' ] == $booking_date ){
                        $special_booking_price = $values[ 'booking_special_price' ];
                        break;
                    }
                }
                
                if ( $special_booking_price == "" ) { // specific date price was not found
                    foreach ( $booking_special_prices as $key => $values ) {
                        
                        list( $year, $month, $day ) =   explode( "-", $booking_date );
                        $booking_day              =   date( "w", mktime( 0, 0, 0, $month, $day, $year ) );
                        $day_name = "booking_weekday_$booking_day";
                        
                        if ( isset( $values[ 'booking_special_weekday' ] ) && $day_name == $values[ 'booking_special_weekday' ] ){
                            $special_booking_price = $values[ 'booking_special_price' ];
                            break;
                        }
                    }
                }
            }
            return $special_booking_price;
        }
            
        /**
         * This function is used to updated price of product for Multiple dates
         *
         * @since 2.0
         * @global object $wpdb global wpdb Object
         * @param int $product_id Product ID
         * @param string $product_type Type of Product
         * @param int $variation_id_to_fetch Variation ID
         * @param string $checkin_date Date
         * @param string $checkout_date Date
         * @param int $gf_options Option price from Gravity Forms
         * @param int $resource_id Resource ID
         * @param string $currency_selected Selected currency
         */
        
        function bkap_special_booking_show_multiple_updated_price( $product_id, $product_type, $variation_id_to_fetch, $checkin_date, $checkout_date, $gf_options = 0, $resource_id, $currency_selected ) {
            
            $global_settings    = json_decode( get_option( 'woocommerce_booking_global_settings' ) );
            $number_of_days     = strtotime( $checkout_date ) - strtotime( $checkin_date );
            $number             = floor( $number_of_days/( 60 * 60 * 24 ) );
                
            if ( $number == 0 ) {
                $number = 1;
            }
            
            $booking_settings = get_post_meta( $product_id, 'woocommerce_booking_settings', true );
                
            if ( function_exists( 'is_bkap_rental_active' ) && is_bkap_rental_active() && ( isset( $booking_settings ) && isset( $booking_settings['booking_charge_per_day'] ) &&  $booking_settings['booking_charge_per_day'] == 'on' ) ){
                if ( strtotime( $checkout_date ) > strtotime( $checkin_date) ) {
                    $number++;
                }
            }
            
            $booking_special_prices = get_post_meta( $product_id, '_bkap_special_price', true );
                    
            if ( isset( $_POST[ 'price' ] ) && ( isset( $booking_settings[ 'booking_fixed_block_enable' ] ) && $booking_settings[ 'booking_fixed_block_enable' ] == 'booking_fixed_block_enable' ) ) {
                $price = $_POST[ 'price' ];
                
                // Divide the block price by number of nights so per day price is calculated for the block and then added up to form the total
                if( is_array( $booking_special_prices ) && count( $booking_special_prices ) > 0 ) {
                    $price = $price / $number;
                }
                
                $number = 1;
            } else if ( isset( $_POST[ 'price' ] ) && ( isset( $booking_settings[ 'booking_block_price_enable' ] ) && $booking_settings[ 'booking_block_price_enable' ] == 'booking_block_price_enable' ) ) { 
                
                $str_pos = strpos( $_POST[ 'price' ], '-' );
                
                if ( isset( $str_pos ) && $str_pos != '' ) {
                    $price_type   =  explode( "-", $_POST['price'] );

                    $price         = $price_type[0] / $number;
                } else {
                    $price = $_POST['price'];
                }

            } else {
                $price = bkap_common::bkap_get_price( $product_id, $variation_id_to_fetch, $product_type,$checkin_date, $checkout_date );
            }

            $weekdays                           = bkap_get_book_arrays( 'bkap_weekdays' );
            $special_multiple_day_booking_price = 0;
            $startDate                          = $checkin_date;
            $check_special_price_flag           = "FALSE";
            
            if ( is_array( $booking_special_prices ) && count( $booking_special_prices ) > 0 ){
                
                // If rental is active, then we have chk price for all selected days
                if ( function_exists( 'is_bkap_rental_active' ) && is_bkap_rental_active() && ( isset( $booking_settings ) && isset( $booking_settings[ 'booking_charge_per_day' ] ) && $booking_settings[ 'booking_charge_per_day' ] == 'on' ) ) { 
                    $endDate = strtotime( $checkout_date ) + ( 60 * 24 * 24 );
                } else { 
                    $endDate = strtotime( $checkout_date ); 
                }
                    
                while ( strtotime( $startDate ) < $endDate ) {
                    
                    $check_special_price_flag   = "TRUE";
                    $special_price              = $price;

                    foreach ( $booking_special_prices as $key => $values ){
                        
                        list( $year, $month, $day ) = explode( "-", $startDate );
                        $booking_day                =  date("w", mktime(0, 0, 0, $month, $day, $year));
                        $startDate1                 = "booking_weekday_$booking_day";
                        
                        if ( isset( $values[ 'booking_special_weekday' ] ) &&  $startDate1 == $values[ 'booking_special_weekday' ] ) {
                            $special_price = $values[ 'booking_special_price' ];
                        }
                    }
                    
                    foreach( $booking_special_prices as $key => $values ) {
                        if ( $values[ 'booking_special_date' ] == $startDate ) {
                            $special_price = $values[ 'booking_special_price' ];
                        }
                    }

                    $special_multiple_day_booking_price  += $special_price;
                    $startDate                            = date ( "Y-m-d", strtotime( "+1 day", strtotime( $startDate ) ) );
                }
                
                if ( $check_special_price_flag == "FALSE" ){
                    $special_multiple_day_booking_price  = $price;
                }
                
                // Don't divide price by no. of days if Fixed block 
                if ( ( isset( $booking_settings[ 'booking_fixed_block_enable' ] ) && $booking_settings[ 'booking_fixed_block_enable' ] == 'booking_fixed_block_enable' ) ) {  
                    $special_multiple_day_booking_price = $special_multiple_day_booking_price;
                } else { 
                    $special_multiple_day_booking_price = $special_multiple_day_booking_price / $number;
                }
                
                $_SESSION[ 'special_multiple_day_booking_price' ]    = $_POST[ 'special_multiple_day_booking_price' ]  = $special_multiple_day_booking_price;
                $_SESSION[ 'booking_multiple_days_count' ]           = $_POST[ 'booking_multiple_days_count' ]         = $number;
            } else {    
                $special_multiple_day_booking_price                = $price;
                $_SESSION[ 'special_multiple_day_booking_price' ]    = $_SESSION[ 'booking_multiple_days_count' ] = '';
            }

            $resource_price = 0;
            if( $resource_id > 0 ){
            
                $resource       = new BKAP_Product_Resource( $resource_id, $product_id );
                $resource_price = $resource->get_base_cost();
            
                if ( isset( $global_settings->resource_price_per_day ) && $global_settings->resource_price_per_day == "on" ){
                    $resource_price = $resource_price * $number;
                }
                if ( isset( $_POST[ 'quantity' ] ) && $_POST[ 'quantity' ] > 0 ) {
                    $resource_price = $resource_price * $_POST[ 'quantity' ];
                }
            }        
                    
            if ( function_exists( 'is_bkap_deposits_active' ) && is_bkap_deposits_active() || function_exists( 'is_bkap_seasonal_active' ) && is_bkap_seasonal_active() ) {
                if ( isset( $special_multiple_day_booking_price ) && $special_multiple_day_booking_price !== '' ) {
                    $_POST['price'] = $special_multiple_day_booking_price + $resource_price;
                } else {
                    $error_message = __( "Please select an option.", "woocommerce-booking" );
                    print( 'jQuery( "#bkap_price" ).html( "' . addslashes( $error_message ) . '");' );
                    die();
                }
            } else {
                
                // the filter is applied to make the plugin wpml multi currency compatible
                // as a prt of that, we need to ensure that the final price is sent to the filter
                if ( isset( $number ) && $number > 1 ) {
                    $special_multiple_day_booking_price = $special_multiple_day_booking_price * $number;
                }
                if ( isset( $_POST[ 'quantity' ] ) && $_POST[ 'quantity' ] > 0 ) {
                    $special_multiple_day_booking_price = $special_multiple_day_booking_price * $_POST[ 'quantity' ];
                }
                if ( isset( $global_settings->enable_rounding ) && $global_settings->enable_rounding == "on" ) {
                    $special_multiple_day_booking_price = round( $special_multiple_day_booking_price );
                }
                
                $special_multiple_day_booking_price += $resource_price;
                    
                // Save the actual Bookable amount, as a raw amount
                // If Multi currency is enabled, convert the amount before saving it
                $total_price = $special_multiple_day_booking_price;
                
                if ( function_exists( 'icl_object_id' ) ) {
                    
                    $custom_post = bkap_common::bkap_get_custom_post( $product_id, 0, $product_type );
                    
                    if ( $custom_post == 1 ) {
                        $total_price = $special_multiple_day_booking_price;
                    } else if ( $custom_post == 0 ) {
                        $total_price = apply_filters( 'wcml_raw_price_amount', $special_multiple_day_booking_price );
                    }
                }

                print( 'jQuery( "#total_price_calculated" ).val(' . $total_price . ');' );
                // save the price in a hidden field to be used later
                print( 'jQuery( "#bkap_price_charged" ).val(' . $total_price . ');' );
                    
                // If gf options are enabled, multiply with the number of nights based on the settings
                if ( isset( $gf_options ) && $gf_options > 0 ) {
                    $gf_total = $gf_options;
                    if ( isset( $global_settings->woo_gf_product_addon_option_price ) && 'on' == $global_settings->woo_gf_product_addon_option_price ) {
                        if ( isset( $_POST[ 'diff_days' ] ) && $_POST[ 'diff_days' ] > 1 ) { // the diff days passed in the ajax need to be checked as the variable $diff_days is set to 1 for fixed blocks
                            $gf_total = $gf_options * $_POST[ 'diff_days' ];
                        }
                    }
                    $total_price += $gf_total;
                }

                // Format the price 
                $wc_price_args      = bkap_common::get_currency_args();
                $formatted_price    = wc_price( $total_price, $wc_price_args );

                if ( 'bundle' == $product_type ) {
                    $bundle_price = bkap_common::get_bundle_price( $total_price, $product_id, $variation_id_to_fetch );
                    $formatted_price = wc_price( $bundle_price, $wc_price_args );
                }

                if ( 'composite' === $product_type ) {
                    $composite_price = bkap_common::get_composite_price( $total_price, $product_id, $variation_id_to_fetch );

                    $formatted_price = wc_price( $composite_price, $wc_price_args );
                }
                    
                $display_price = get_option( 'book_price-label' ) . ' ' . $formatted_price;
                // display the price on the front end product page
                print( 'jQuery( "#bkap_price" ).html( "' . addslashes( $display_price ) . '");' );
                die();
            }
        }                       
    }
}
$bkap_special_booking_price = new bkap_special_booking_price();
?>
API documentation generated by ApiGen