function _pre_checkout_validate() { $validate = true; if (!STPrice::getTotal()) { STTemplate::set_message(__('Can not process free payment', ST_TEXTDOMAIN), 'danger'); return false; } if ($this->is_available()) { $paypal = new STPaypal(); $pp = $paypal->test_authorize(); if (isset($pp['redirect_url']) and $pp['redirect_url']) { $pp_link = $pp['redirect_url']; } if (!isset($pp_link)) { STTemplate::set_message(isset($pp['message']) ? $pp['message'] : __('Paypal Payment Gateway Validate Fail'), 'danger'); $validate = false; } } return $validate; }
function do_add_to_cart() { $pass_validate = true; $item_id = STInput::request('item_id', ''); if ($item_id <= 0 || get_post_type($item_id) != 'st_holidays') { STTemplate::set_message(__('This holiday is not available..', ST_TEXTDOMAIN), 'danger'); $pass_validate = false; return false; } $number = 1; $adult_number = intval(STInput::request('adult_number', 1)); $child_number = intval(STInput::request('child_number', 0)); $infant_number = intval(STInput::request('infant_number', 0)); $data['adult_number'] = $adult_number; $data['child_number'] = $child_number; $data['infant_number'] = $infant_number; $max_number = intval(get_post_meta($item_id, 'max_people', true)); $type_holiday = get_post_meta($item_id, 'type_holiday', true); $data['type_holiday'] = $type_holiday; $today = date('Y-m-d'); $check_in = STInput::request('check_in', ''); $check_out = STInput::request('check_out', ''); if (!$check_in || !$check_out) { STTemplate::set_message(__('Select a holiday in the calendar above.', ST_TEXTDOMAIN), 'danger'); $pass_validate = FALSE; return false; } $compare = TravelHelper::dateCompare($today, $check_in); if ($compare < 0) { STTemplate::set_message(__('This holiday has expired', ST_TEXTDOMAIN), 'danger'); $pass_validate = false; return false; } $booking_period = intval(get_post_meta($item_id, 'holidays_booking_period', true)); $period = TravelHelper::dateDiff($today, $check_in); if ($period < $booking_period) { STTemplate::set_message(sprintf(__('This holiday allow minimum booking is %d day(s)', ST_TEXTDOMAIN), $booking_period), 'danger'); $pass_validate = false; return false; } if ($adult_number + $child_number + $infant_number > $max_number) { STTemplate::set_message(sprintf(__('Max of people for this holiday is %d people', ST_TEXTDOMAIN), $max_number), 'danger'); $pass_validate = FALSE; return false; } $holiday_available = HolidayHelper::checkAvailableHoliday($item_id, strtotime($check_in), strtotime($check_out)); if (!$holiday_available) { STTemplate::set_message(__('The check in, check out day is not invalid or this holiday not available.', ST_TEXTDOMAIN), 'danger'); $pass_validate = FALSE; return false; } $free_people = intval(get_post_meta($item_id, 'max_people', true)); $result = HolidayHelper::_get_free_peple($item_id, strtotime($check_in), strtotime($check_out)); if (is_array($result) && count($result)) { $free_people = intval($result['free_people']); } if ($free_people < $adult_number + $child_number + $infant_number) { STTemplate::set_message(sprintf(__('This holiday only vacant %d people', ST_TEXTDOMAIN), $free_people), 'danger'); $pass_validate = FALSE; return false; } $data_price = STPrice::getPriceByPeopleHoliday($item_id, strtotime($check_in), strtotime($check_out), $adult_number, $child_number, $infant_number); $total_price = $data_price['total_price']; $sale_price = STPrice::getSaleHolidaySalePrice($item_id, $total_price, $type_holiday, strtotime($check_in)); $data['check_in'] = date('m/d/Y', strtotime($check_in)); $data['check_out'] = date('m/d/Y', strtotime($check_out)); $people_price = STPrice::getPeoplePrice($item_id, strtotime($check_in), strtotime($check_out)); $data = wp_parse_args($data, $people_price); $data['ori_price'] = $sale_price; $data['currency'] = TravelHelper::get_current_currency('symbol'); $data['currency_rate'] = TravelHelper::get_current_currency('rate'); $data['currency_pos'] = TravelHelper::get_current_currency('booking_currency_pos'); $data['commission'] = TravelHelper::get_commission(); $data['data_price'] = $data_price; $data['discount_rate'] = STPrice::get_discount_rate($item_id, strtotime($check_in)); if ($pass_validate) { $data['duration'] = $type_holiday == 'daily_holiday' ? floatval(get_post_meta($item_id, 'duration_day', true)) : ''; if ($pass_validate) { STCart::add_cart($item_id, $number, $sale_price, $data); } } return $pass_validate; }
function do_add_to_cart() { $pass_validate = true; $item_id = intval(STInput::request('item_id', '')); if ($item_id <= 0 || get_post_type($item_id) != 'st_activity') { STTemplate::set_message(__('This activity is not available..', ST_TEXTDOMAIN), 'danger'); $pass_validate = false; return false; } $number = 1; $type_activity = STInput::request('type_activity', 'specific_date'); $adult_number = intval(STInput::request('adult_number', 1)); $child_number = intval(STInput::request('child_number', 0)); $infant_number = intval(STInput::request('infant_number', 0)); $max_number = intval(get_post_meta($item_id, 'max_people', true)); $today = date('Y-m-d'); if ($adult_number + $child_number + $infant_number > $max_number) { STTemplate::set_message(sprintf(__('Max of people for this activity is %d people', ST_TEXTDOMAIN), $max_number), 'danger'); $pass_validate = FALSE; return false; } if ($type_activity == 'specific_date') { $check_in = TravelHelper::convertDateFormat(STInput::request('check_in', '')); $check_out = TravelHelper::convertDateFormat(STInput::request('check_out', '')); if (empty($check_in)) { STTemplate::set_message(__('The check in field is not empty.', ST_TEXTDOMAIN), 'danger'); $pass_validate = false; return false; } if (empty($check_out)) { STTemplate::set_message(__('The check out field is not empty.', ST_TEXTDOMAIN), 'danger'); $pass_validate = false; return false; } $compare = TravelHelper::dateCompare($today, $check_in); if ($compare < 0) { STTemplate::set_message(__('This activity has expired', ST_TEXTDOMAIN), 'danger'); $pass_validate = false; return false; } $people = $adult_number + $child_number + $child_number; $result = ActivityHelper::_get_free_peple_special($item_id, $check_in, $check_out); $free_people = intval(get_post_meta($item_id, 'max_people', true)); if (is_array($result) && count($result)) { $free_people = intval($result['free_people']); } if ($free_people < $people) { STTemplate::set_message(sprintf(__('This activity only vacant %d people', ST_TEXTDOMAIN), $free_people), 'danger'); $pass_validate = false; return false; } $data['check_in'] = date('m/d/Y', strtotime($check_in)); $data['check_out'] = date('m/d/Y', strtotime($check_out)); } elseif ($type_activity == 'daily_activity') { $check_in = STInput::request('check_in', ''); if (empty($check_in)) { STTemplate::set_message(__('The check in field is not empty.', ST_TEXTDOMAIN), 'danger'); $pass_validate = false; return false; } $check_in = TravelHelper::convertDateFormat($check_in); $check_in = date('Y-m-d', strtotime($check_in)); $duration = intval(get_post_meta($item_id, 'duration', true)); $check_out = $duration >= 2 ? strtotime('+ ' . $duration . ' days', strtotime($check_in)) : strtotime('+ ' . $duration . ' day', strtotime($check_in)); $check_out = date('Y-m-d', $check_out); $booking_period = intval(get_post_meta($item_id, 'activity_booking_period', true)); $period = TravelHelper::dateDiff($today, $check_in); $compare = TravelHelper::dateCompare($today, $check_in); if ($compare < 0) { STTemplate::set_message(__('You can not set check-in date in the past', ST_TEXTDOMAIN), 'danger'); $pass_validate = false; return false; } if ($booking_period && $booking_period > $period) { STTemplate::set_message(sprintf(__('This activity allow minimum booking is %d day(s)', ST_TEXTDOMAIN), $booking_period), 'danger'); $pass_validate = false; return false; } $people = $adult_number + $child_number + $child_number; $result = ActivityHelper::_get_free_peple_daily($item_id, $check_in); $free_people = intval(get_post_meta($item_id, 'max_people', true)); if (is_array($result) && count($result)) { $free_people = intval($result['free_people']); } if ($free_people < $people) { STTemplate::set_message(sprintf(__('This activity only vacant %d people', ST_TEXTDOMAIN), $free_people), 'danger'); $pass_validate = false; return false; } $data['duration'] = $duration; } $data['adult_number'] = $adult_number; $data['child_number'] = $child_number; $data['infant_number'] = $infant_number; $data['check_in'] = date('m/d/Y', strtotime($check_in)); $data['check_out'] = date('m/d/Y', strtotime($check_out)); $data['type_activity'] = $type_activity; $data_price = STPrice::getPriceByPeople($item_id, strtotime($check_in), strtotime($check_out), $adult_number, $child_number, $infant_number); $total_price = $data_price['total_price']; $sale_price = STPrice::getSaleTourSalePrice($item_id, $total_price, $type_activity, strtotime($check_in)); $discount_rate = STPrice::get_discount_rate($item_id, strtotime($check_in)); $data['adult_price'] = floatval(get_post_meta($item_id, 'adult_price', true)); $data['child_price'] = floatval(get_post_meta($item_id, 'child_price', true)); $data['infant_price'] = floatval(get_post_meta($item_id, 'infant_price', true)); $data['ori_price'] = $sale_price; $data['currency'] = TravelHelper::get_current_currency('symbol'); $data['currency_rate'] = TravelHelper::get_current_currency('rate'); $data['currency_pos'] = TravelHelper::get_current_currency('booking_currency_pos'); $data['commission'] = TravelHelper::get_commission(); $data['data_price'] = $data_price; $data['discount_rate'] = $discount_rate; if ($pass_validate) { $pass_validate = apply_filters('st_activity_add_cart_validate', $pass_validate); } if ($pass_validate) { STCart::add_cart($item_id, $number, $sale_price, $data); } return $pass_validate; }
<strong> - <?php echo TravelHelper::format_money($price_coupon); ?> </strong> </td> </tr> <?php } ?> <?php if (!isset($price_coupon)) { $price_coupon = 0; } if (isset($item['data']['deposit_money']) && count($item['data']['deposit_money']) && floatval($item['data']['deposit_money']['amount']) > 0) { $deposit_price = STPrice::getDepositPrice($item['data']['deposit_money'], $price_with_tax, $price_coupon); ?> <tr> <td class="text-left title"><?php echo __('Deposit Price', ST_TEXTDOMAIN); ?> </td> <td class="text-right "> <strong><?php echo TravelHelper::format_money($deposit_price); ?> </strong> </td> </tr> <?php }
function do_add_to_cart() { $form_validate = TRUE; $item_id = intval(STInput::request('item_id', '')); if ($item_id <= 0 || get_post_type($item_id) != 'st_rental') { STTemplate::set_message(__('This rental is not available.', ST_TEXTDOMAIN), 'danger'); $form_validate = FALSE; return false; } $check_in = STInput::request('start', ''); if (empty($check_in)) { STTemplate::set_message(__('The check in field is not empty.', ST_TEXTDOMAIN), 'danger'); $form_validate = FALSE; return false; } $check_in = TravelHelper::convertDateFormat($check_in); $check_out = STInput::request('end', ''); if (empty($check_out)) { STTemplate::set_message(__('The check out field is not empty.', ST_TEXTDOMAIN), 'danger'); $form_validate = FALSE; return false; } $check_out = TravelHelper::convertDateFormat($check_out); $today = date('m/d/Y'); $booking_period = get_post_meta($item_id, 'rentals_booking_period', true); if (empty($booking_period) || $booking_period <= 0) { $booking_period = 0; } $period = TravelHelper::dateDiff($today, $check_in); $compare = TravelHelper::dateCompare($today, $check_in); if ($compare < 0) { STTemplate::set_message(__('You can not set check-in date in the past', ST_TEXTDOMAIN), 'danger'); $form_validate = FALSE; return false; } if ($period < $booking_period) { STTemplate::set_message(sprintf(__('This rental allow minimum booking is %d day(s)', ST_TEXTDOMAIN), $booking_period), 'danger'); $form_validate = FALSE; return false; } $adult_number = intval(STInput::request('adult_number', '')); $child_number = intval(STInput::request('child_number', '')); $max_adult = intval(get_post_meta($item_id, 'rental_max_adult', true)); $max_children = intval(get_post_meta($item_id, 'rental_max_children', true)); if ($adult_number > $max_adult) { STTemplate::set_message(sprintf(__('A maximum number of adult(s): %d', ST_TEXTDOMAIN), $max_adult), 'danger'); $form_validate = FALSE; return false; } if ($child_number > $max_children) { STTemplate::set_message(sprintf(__('A maximum number of children: %d', ST_TEXTDOMAIN), $max_children), 'danger'); $form_validate = FALSE; return false; } $number_room = intval(get_post_meta($item_id, 'rental_number', true)); $check_in_tmp = date('Y-m-d', strtotime($check_in)); $check_out_tmp = date('Y-m-d', strtotime($check_out)); if (!RentalHelper::check_day_cant_order($item_id, $check_in_tmp, $check_out_tmp, 1)) { STTemplate::set_message(sprintf(__('This rental is not available from %s to %s.', ST_TEXTDOMAIN), $check_in_tmp, $check_out_tmp), 'danger'); $pass_validate = FALSE; return false; } if (!RentalHelper::_check_room_available($item_id, $check_in_tmp, $check_out_tmp, 1)) { STTemplate::set_message(__('This rental is not available.', ST_TEXTDOMAIN), 'danger'); $pass_validate = FALSE; return false; } $item_price = STPrice::getRentalPriceOnlyCustomPrice($item_id, strtotime($check_in), strtotime($check_out)); $extras = STInput::request('extra_price', array()); $numberday = TravelHelper::dateDiff($check_in, $check_out); $extra_price = STPrice::getExtraPrice($extras, 1, $numberday); $price_sale = STPrice::getSalePrice($item_id, $item_price, strtotime($check_in), strtotime($check_out)); $discount_rate = STPrice::get_discount_rate($item_id, strtotime($check_in)); $data = array('item_price' => $item_price, 'ori_price' => $price_sale + $extra_price, 'check_in' => $check_in, 'check_out' => $check_out, 'adult_number' => $adult_number, 'child_number' => $child_number, 'extras' => $extras, 'extra_price' => $extra_price, 'commission' => TravelHelper::get_commission(), 'discount_rate' => $discount_rate); if ($form_validate) { $form_validate = apply_filters('st_rental_add_cart_validate', $form_validate); } if ($form_validate) { STCart::add_cart($item_id, 1, $item_price, $data); } return $form_validate; }
function do_add_to_cart() { $pass_validate = TRUE; $item_id = intval(STInput::request('item_id', '')); if ($item_id <= 0 || get_post_type($item_id) != 'st_hotel') { STTemplate::set_message(__('This hotel is not available.', ST_TEXTDOMAIN), 'danger'); $pass_validate = FALSE; return false; } $room_id = intval(STInput::request('room_id', '')); if ($room_id <= 0 || get_post_type($room_id) != 'hotel_room') { STTemplate::set_message(__('This room is not available.', ST_TEXTDOMAIN), 'danger'); $pass_validate = FALSE; return false; } $check_in = STInput::request('check_in', ''); if (empty($check_in)) { STTemplate::set_message(__('Date is invalid', ST_TEXTDOMAIN), 'danger'); $pass_validate = FALSE; return false; } $check_in = TravelHelper::convertDateFormat($check_in); $check_out = STInput::request('check_out', ''); if (empty($check_out)) { STTemplate::set_message(__('Date is invalid', ST_TEXTDOMAIN), 'danger'); $pass_validate = FALSE; return false; } $check_out = TravelHelper::convertDateFormat($check_out); $room_num_search = intval(STInput::request('room_num_search', '')); if ($room_num_search <= 0) { $room_num_search = 1; } $adult_number = intval(STInput::request('adult_number', '')); if ($adult_number <= 0) { $adult_number = 1; } $child_number = intval(STInput::request('child_number', '')); if ($child_number <= 0) { $child_number = 0; } $checkin_ymd = date('Y-m-d', strtotime($check_in)); $checkout_ymd = date('Y-m-d', strtotime($check_out)); if (!HotelHelper::check_day_cant_order($room_id, $checkin_ymd, $checkout_ymd, $room_num_search)) { STTemplate::set_message(sprintf(__('This room is not available from %s to %s.', ST_TEXTDOMAIN), $checkin_ymd, $checkout_ymd), 'danger'); $pass_validate = FALSE; return false; } if (!HotelHelper::_check_room_available($room_id, $checkin_ymd, $checkout_ymd, $room_num_search)) { STTemplate::set_message(__('This room is not available.', ST_TEXTDOMAIN), 'danger'); $pass_validate = FALSE; return false; } if (strtotime($check_out) - strtotime($check_in) <= 0) { STTemplate::set_message(__('The check-out is later than the check-in.', ST_TEXTDOMAIN), 'danger'); $pass_validate = FALSE; return false; } $num_room = intval(get_post_meta($room_id, 'number_room', true)); $adult = intval(get_post_meta($room_id, 'adult_number', true)); $children = intval(get_post_meta($room_id, 'children_number', true)); if ($room_num_search > $num_room) { STTemplate::set_message(__('Max of rooms are incorrect.', ST_TEXTDOMAIN), 'danger'); $pass_validate = FALSE; return false; } if ($adult_number > $adult) { STTemplate::set_message(sprintf(__('Max of adults is %d people.', ST_TEXTDOMAIN), $adult), 'danger'); $pass_validate = FALSE; return false; } if ($child_number > $children) { STTemplate::set_message(__('Number of children in the room are incorrect.', ST_TEXTDOMAIN), 'danger'); $pass_validate = FALSE; return false; } $today = date('m/d/Y'); $period = TravelHelper::dateDiff($today, $check_in); $booking_min_day = intval(get_post_meta($item_id, 'min_book_room', true)); $compare = TravelHelper::dateCompare($today, $check_in); $booking_period = get_post_meta($item_id, 'hotel_booking_period', true); if (empty($booking_period) || $booking_period <= 0) { $booking_period = 0; } if ($compare < 0) { STTemplate::set_message(__('You can not set check-in date in the past', ST_TEXTDOMAIN), 'danger'); $pass_validate = FALSE; return false; } if ($period < $booking_period) { STTemplate::set_message(sprintf(__('This hotel allow minimum booking is %d day(s)', ST_TEXTDOMAIN), $booking_period), 'danger'); $pass_validate = FALSE; return false; } if ($booking_min_day and $booking_min_day > TravelHelper::dateDiff($check_in, $check_out)) { STTemplate::set_message(sprintf(__('Please booking at least %d day(s)', ST_TEXTDOMAIN), $booking_min_day), 'danger'); $pass_validate = false; return false; } $item_price = floatval(get_post_meta($room_id, 'price', true)); // Extra price added in the new version 1.1.9 $extras = STInput::request('extra_price', array()); $numberday = TravelHelper::dateDiff($check_in, $check_out); $extra_price = STPrice::getExtraPrice($extras, $room_num_search, $numberday); $sale_price = STPrice::getRoomPrice($room_id, strtotime($check_in), strtotime($check_out), $room_num_search); $discount_rate = STPrice::get_discount_rate($room_id, strtotime($check_in)); $data = array('item_price' => $item_price, 'ori_price' => $sale_price + $extra_price, 'check_in' => $check_in, 'check_out' => $check_out, 'room_num_search' => $room_num_search, 'room_id' => $room_id, 'adult_number' => $adult_number, 'child_number' => $child_number, 'extras' => $extras, 'extra_price' => $extra_price, 'commission' => TravelHelper::get_commission(), 'discount_rate' => $discount_rate); if ($pass_validate) { $pass_validate = apply_filters('st_hotel_add_cart_validate', $pass_validate, $data); } if ($pass_validate) { STCart::add_cart($item_id, $room_num_search, $sale_price + $extra_price, $data); } return $pass_validate; }
</p> </li> <?php } else { ?> <li> <p><?php echo st_get_language('car_price_per') . ' ' . ucfirst(STCars::get_price_unit('label')); ?> </p> <div class="show_custom_price"> <ul> <?php $format = "d/m"; $tmp_price = 0; $list_price = STPrice::convert_array_date_custom_price_by_date($list_price); foreach ($list_price as $k => $v) { ?> <li> <p class="margin_0"> <?php if ($v['start'] == $v['end']) { $format = "d/m/y"; ?> <?php echo esc_html(date_i18n($format, strtotime($v['start']))); ?> <?php } else { ?> <?php
</td> <td class="text-right "><strong><?php echo TravelHelper::format_money($extra_price); ?> </strong></td> </tr> <?php } ?> <tr> <td class="text-left title"><?php echo __('Tax', ST_TEXTDOMAIN); ?> </td> <td class="text-right "><strong><?php echo STPrice::getTax() . ' %'; ?> </strong></td> </tr> <tr> <td class="text-left title"><?php echo __('Total Price (with tax)', ST_TEXTDOMAIN); ?> </td> <td class="text-right "><strong><?php echo TravelHelper::format_money($price_with_tax); ?> </strong></td> </tr> <?php if (STCart::use_coupon()) {
function _add_booking() { if (!check_admin_referer('shb_action', 'shb_field')) { die; } $data = $this->check_validate(); if (is_array($data) && count($data)) { extract($data); $order = array('post_title' => __('Order', ST_TEXTDOMAIN) . ' - ' . date(get_option('date_format')) . ' @ ' . date(get_option('time_format')), 'post_type' => 'st_order', 'post_status' => 'publish'); $order_id = wp_insert_post($order); if ($order_id) { $check_out_field = STCart::get_checkout_fields(); if (!empty($check_out_field)) { foreach ($check_out_field as $field_name => $field_desc) { update_post_meta($order_id, $field_name, STInput::post($field_name)); } } update_post_meta($order_id, 'payment_method', 'st_submit_form'); $id_user = get_current_user_id(); update_post_meta($order_id, 'id_user', $id_user); $item_price = floatval(get_post_meta($item_id, 'cars_price', true)); $unit = st()->get_option('cars_price_unit', 'day'); /*if($unit == 'day'){ $numberday = ceil(($check_out_timestamp - $check_in_timestamp) / (60 * 60 * 24)); }elseif($unit == 'hour'){ $numberday = ceil(($check_out_timestamp - $check_in_timestamp) / (60 * 60)); }*/ $numberday = STCars::get_date_diff($check_in_timestamp, $check_out_timestamp, $unit); $selected_equipments = $_POST['item_equipment']; $price_equipment = STPrice::getPriceEuipmentCarAdmin($selected_equipments); $data_equipment = STPrice::convertEquipmentToOject($selected_equipments); $origin_price = $item_price * $numberday; $sale_price = STPrice::getSaleCarPrice($item_id, $item_price, $check_in_timestamp, $check_out_timestamp); $price_with_tax = STPrice::getPriceWithTax($sale_price + $price_equipment); $coupon_price = 0; $deposit_money['data'] = array(); $deposit_money = STPrice::getDepositData($item_id, $deposit_money); $deposit_price = STPrice::getDepositPrice($deposit_money['data']['deposit_money'], $price_with_tax, 0); if (isset($deposit_money['data']['deposit_money'])) { $total_price = $deposit_price; } else { $total_price = $price_with_tax - $coupon_price; } $data_prices = array('origin_price' => $origin_price, 'sale_price' => $sale_price, 'coupon_price' => 0, 'price_with_tax' => $price_with_tax, 'total_price' => $total_price, 'deposit_price' => $deposit_price, 'unit' => $unit, 'price_equipment' => $price_equipment); $item_data = array('item_id' => $item_id, 'item_number' => 1, 'total_price' => $total_price, 'item_price' => $item_price, 'check_in' => $check_in, 'check_in_timestamp' => $check_in_timestamp, 'check_out' => $check_out, 'check_out_timestamp' => $check_out_timestamp, 'st_booking_id' => $item_id, 'check_in_time' => $check_in_time, 'check_out_time' => $check_out_time, 'pick_up' => get_the_title($location_id_pick_up), 'location_id_pick_up' => $location_id_pick_up, 'drop_off' => get_the_title($location_id_drop_off), 'location_id_drop_off' => $location_id_drop_off, 'deposit_money' => $deposit_money, 'booking_by' => 'admin', 'st_tax' => STPrice::getTax(), 'st_tax_percent' => STPrice::getTax(), 'status' => $_POST['status'], 'currency' => TravelHelper::get_current_currency('symbol'), 'currency_rate' => TravelHelper::get_current_currency('rate'), 'data_equipment' => $data_equipment, 'data_prices' => $data_prices, 'commission' => TravelHelper::get_commission()); foreach ($item_data as $val => $value) { update_post_meta($order_id, $val, $value); } if (TravelHelper::checkTableDuplicate('st_cars')) { global $wpdb; $table = $wpdb->prefix . 'st_order_item_meta'; $g_post = get_post($item_id); $partner_id = $g_post ? $g_post->post_author : ''; global $sitepress; if ($sitepress) { $post_type = get_post_type($st_booking_id); if ($post_type == 'st_hotel') { $post_type = 'hotel_room'; $id = $room_id; } else { $id = $st_booking_id; } $lang_code = $sitepress->get_default_language(); $origin_id = icl_object_id($id, $post_type, true, $lang_code); } else { $origin_id = $st_booking_id; } $data = array('order_item_id' => $order_id, 'type' => 'normal_booking', 'st_booking_post_type' => 'st_cars', 'check_in' => date('m/d/Y', strtotime($check_in)), 'check_out' => date('m/d/Y', strtotime($check_out)), 'st_booking_id' => $item_id, 'check_in_timestamp' => $check_in_timestamp, 'check_out_timestamp' => $check_out_timestamp, 'user_id' => $id_user, 'status' => $_POST['status'], 'wc_order_id' => $order_id, 'partner_id' => $partner_id, 'created' => get_the_date('Y-m-d', $order_id), 'total_order' => $total_price, 'commission' => TravelHelper::get_commission(), 'origin_id' => $origin_id); $wpdb->insert($table, $data); } //Check email $user_name = STInput::post('st_email'); $user_id = username_exists($user_name); if (!$user_id and email_exists($user_name) == false) { $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false); $userdata = array('user_login' => $user_name, 'user_pass' => $random_password, 'user_email' => $user_name, 'first_name' => STInput::post('st_first_name'), 'last_name' => STInput::post('st_last_name')); $user_id = wp_insert_user($userdata); wp_new_user_notification($user_id); } STCart::send_mail_after_booking($order_id, true); STCart::send_email_confirm($order_id); do_action('st_booking_success', $order_id); wp_safe_redirect(self::$booking_page); } } }
</div> <div class="col-md-3"> <?php $start = TravelHelper::convertDateFormat(STInput::request('start')); $end = TravelHelper::convertDateFormat(STInput::request('end')); $numberday = TravelHelper::dateDiff($start, $end); $is_search_room = STInput::request('is_search_room'); ?> <?php if ($start and $end and $is_search_room) { ?> <?php $room_id = get_the_ID(); $room_num_search = intval(STInput::request('room_num_search', 1)); $sale_price = STPrice::getRoomPrice($room_id, strtotime($start), strtotime($end), $room_num_search); $total_price = STPrice::getRoomPriceOnlyCustomPrice($room_id, strtotime($start), strtotime($end), $room_num_search); ?> <?php if ($sale_price < $total_price) { ?> <span class="text-lg onsale mr20"> <?php echo TravelHelper::format_money($total_price); ?> </span> <br /> <?php } ?> <span class="booking-item-price"> <?php
static function booking_form_submit($item_id = '') { if (STInput::post('st_payment_gateway') and wp_verify_nonce(STInput::post('travel_order'), 'submit_form_order')) { $first_item_id = self::get_booking_id(); // All gateway available $gateways = STPaymentGateways::get_payment_gateways(); if (empty($gateways)) { return array('status' => false, 'message' => __('Sorry! No payment gateway available', ST_TEXTDOMAIN)); } $payment_gateway_used = false; $payment_gateway_id = false; if (!empty($gateways)) { foreach ($gateways as $key => $value) { if (STInput::post('st_payment_gateway_' . $key)) { $payment_gateway_id = $key; $payment_gateway_used = STPaymentGateways::get_gateway($payment_gateway_id, $first_item_id); } } } if (!$payment_gateway_id or !$payment_gateway_used) { $payment_gateway_name = apply_filters('st_payment_gateway_' . $payment_gateway_id . '_name', $payment_gateway_id); return array('status' => false, 'message' => sprintf(__('Sorry! Payment Gateway: <code>%s</code> is not available for this item!', ST_TEXTDOMAIN), $payment_gateway_name)); } // Action before submit form do_action('st_before_form_submit_run'); $form_validate = true; if (!self::check_cart()) { return array('status' => false, 'message' => __('Your cart is currently empty.', ST_TEXTDOMAIN), 'code' => '1'); } if ($coupon_code = STInput::request('coupon_code')) { $status = self::do_apply_coupon($coupon_code); if (!$status['status']) { return array('status' => false, 'message' => $status['message']); } } if (st()->get_option('booking_enable_captcha', 'on') == 'on') { $st_security_key = STInput::request('st_security_key'); $allow_captcha = STInput::request('allow_capcha', 'off'); if ($allow_captcha == 'off') { if (!$st_security_key) { return array('status' => false, 'message' => __('You dose not enter the captcha', ST_TEXTDOMAIN)); } $valid = STCoolCaptcha::validate_captcha($st_security_key); if (!$valid) { return array('status' => false, 'message' => __('Captcha is not correct', ST_TEXTDOMAIN), 'error_code' => 'invalid_captcha'); } } } $default = array('st_note' => '', 'term_condition' => '', 'create_account' => false, 'paypal_checkout' => false); extract(wp_parse_args($_POST, $default)); //Term and condition if (!$term_condition) { return array('status' => false, 'message' => __('Please accept our terms and conditions', ST_TEXTDOMAIN)); } $form_validate = self::validate_checkout_fields(); if ($form_validate) { $form_validate = $payment_gateway_used->_pre_checkout_validate(); } if (!$form_validate) { $message = array('status' => false, 'message' => STTemplate::get_message_content(), 'form_validate' => 'false'); STTemplate::clear(); return $message; } $post = array('post_title' => __('Order', ST_TEXTDOMAIN) . ' - ' . date(get_option('date_format')) . ' @ ' . date(get_option('time_format')), 'post_type' => 'st_order', 'post_status' => 'publish'); $data_price = STPrice::getDataPrice(); //save the order $insert_post = wp_insert_post($post); if ($insert_post) { $cart = self::get_items(); $fields = self::get_checkout_fields(); if (!empty($fields)) { foreach ($fields as $key => $value) { update_post_meta($insert_post, $key, STInput::post($key)); } } update_post_meta($insert_post, 'st_tax', STPrice::getTax()); update_post_meta($insert_post, 'st_tax_percent', STPrice::getTax()); update_post_meta($insert_post, 'st_is_tax_included_listing_page', STCart::is_tax_included_listing_page() ? 'on' : 'off'); update_post_meta($insert_post, 'currency', TravelHelper::get_current_currency('symbol')); update_post_meta($insert_post, 'currency_rate', TravelHelper::get_current_currency('rate')); update_post_meta($insert_post, 'coupon_code', STCart::get_coupon_code()); update_post_meta($insert_post, 'coupon_amount', STCart::get_coupon_amount()); update_post_meta($insert_post, 'status', 'pending'); update_post_meta($insert_post, 'st_cart_info', $cart); update_post_meta($insert_post, 'total_price', STPrice::getTotal()); update_post_meta($insert_post, 'ip_address', STInput::ip_address()); update_post_meta($insert_post, 'order_token_code', wp_hash($insert_post)); update_post_meta($insert_post, 'data_prices', $data_price); update_post_meta($insert_post, 'booking_by', STInput::post('booking_by', '')); self::saveOrderItems($insert_post); if (!is_user_logged_in()) { $user_name = STInput::post('st_email'); $user_id = username_exists($user_name); //Now Create Account if user agree if ($create_account) { if (!$user_id and email_exists($user_name) == false) { $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false); $userdata = array('user_login' => $user_name, 'user_pass' => $random_password, 'user_email' => $user_name, 'first_name' => STInput::post('st_first_name'), 'last_name' => STInput::post('st_last_name')); $user_id = wp_insert_user($userdata); //Create User Success, send the nofitication wp_new_user_notification($user_id); } } } else { $user_id = get_current_user_id(); } if ($user_id) { //Now Update the Post Meta update_post_meta($insert_post, 'id_user', $user_id); //Update User Meta update_user_meta($user_id, 'st_phone', STInput::post('st_phone')); update_user_meta($user_id, 'first_name', STInput::post('st_first_name')); update_user_meta($user_id, 'last_name', STInput::post('st_last_name')); update_user_meta($user_id, 'st_address', STInput::post('st_address')); update_user_meta($user_id, 'st_address2', STInput::post('st_address2')); update_user_meta($user_id, 'st_city', STInput::post('st_city')); update_user_meta($user_id, 'st_province', STInput::post('st_province')); update_user_meta($user_id, 'st_zip_code', STInput::post('st_zip_code')); update_user_meta($user_id, 'st_country', STInput::post('st_country')); } update_post_meta($insert_post, 'payment_method', $payment_gateway_id); do_action('st_booking_success', $insert_post); // Now gateway do the rest return $payment_gateway_used->do_checkout($insert_post); } else { return array('status' => false, 'message' => __('Can not save order.', ST_TEXTDOMAIN)); } } }
static function get_info_price($post_id = null, $date_start = false, $date_end = false) { if (!$post_id) { $post_id = get_the_ID(); } $price_origin = get_post_meta($post_id, 'cars_price', true); $list_price = array(); $price = $price_origin; $is_custom_price = get_post_meta($post_id, 'is_custom_price', true); if (empty($is_custom_price)) { $is_custom_price = 'price_by_number'; } /////////////////////////////////////// /////////// Price By Date ///////////// /////////////////////////////////////// if ($is_custom_price == 'price_by_number') { if (!empty($date_start) and !empty($date_end)) { $price = self::get_rental_price_by_number_of_day_or_hour($post_id, $price_origin, $date_start, $date_end); } else { $price = $price_origin; } } /////////////////////////////////////// /////////// Price By Date ///////////// /////////////////////////////////////// if ($is_custom_price == 'price_by_date') { if (!empty($date_start) and !empty($date_end)) { $unit = st()->get_option('cars_price_unit', 'day'); if ($unit == 'day') { $one_day = 60 * 60 * 24; } elseif ($unit == 'hour') { $one_day = 60 * 60; } $total = 0; $str_start_date = $date_start; $str_end_date = $date_end; $number_days = STCars::get_date_diff($str_start_date, $str_end_date); for ($i = 1; $i <= $number_days; $i++) { $data_date = date("Y-m-d", $str_start_date + $one_day * $i - $one_day); $tmp_date = date("Y-m-d H:i:s", $str_start_date + $one_day * $i - $one_day); $price_tmp = TravelerObject::st_get_custom_price_by_date($post_id, $data_date); if (empty($price_tmp)) { $price_tmp = $price; } $is_sale = STPrice::_check_car_sale_schedule_by_date($post_id, $data_date); if (!empty($is_sale)) { $price_tmp = $price_tmp - $price_tmp * ($is_sale / 100); } $list_price[$data_date] = array('start' => $tmp_date, 'end' => $tmp_date, 'price' => apply_filters('st_apply_tax_amount', $price_tmp)); $total += $price_tmp; } } else { $price = TravelerObject::st_get_custom_price_by_date($post_id); if (empty($price)) { $price = $price_origin; } } } $discount = get_post_meta($post_id, 'discount', true); $is_sale_schedule = get_post_meta($post_id, 'is_sale_schedule', true); if ($is_sale_schedule == 'on') { $sale_from = get_post_meta($post_id, 'sale_price_from', true); $sale_to = get_post_meta($post_id, 'sale_price_to', true); if ($sale_from and $sale_from) { $today = date('Y-m-d'); $sale_from = date('Y-m-d', strtotime($sale_from)); $sale_to = date('Y-m-d', strtotime($sale_to)); if ($today >= $sale_from && $today <= $sale_to) { } else { $discount = 0; } } else { $discount = 0; } } if ($discount) { if ($discount > 100) { $discount = 100; } $new_price = $price - $price / 100 * $discount; } else { $new_price = $price; } $data = array('price' => apply_filters('st_apply_tax_amount', $new_price), 'price_origin' => apply_filters('st_apply_tax_amount', $price_origin), 'discount' => $discount, 'is_custom_price' => $is_custom_price, 'list_price' => $list_price); return apply_filters('st_car_info_price', $data, $post_id); }
function get_line_items() { // Do not send lines when too many line items in the order. $count = STCart::count(); if ($count > 9 or !$count) { return false; } $args = array(); $item_loop = 0; if (STCart::check_cart()) { $cart = STCart::get_carts(); if (!empty($cart)) { foreach ($cart as $key => $value) { $args[] = array('name' => $this->paypal_item_name(get_the_title($key)), 'quantity' => intval($value['number']), 'price' => round(STPrice::getTotal(true), 2)); } /*if (STCart::use_coupon()) { $args[] = array( 'name' => sprintf(st_get_language('coupon_key'), STCart::get_coupon_code()), 'quantity' => 1, 'price' => -STCart::get_coupon_amount() ); }*/ } } return $args; }
if (!isset($_REQUEST['check_in'])) { $check_in = date('m/d/Y', strtotime("now")); } else { $check_in = TravelHelper::convertDateFormat(STInput::request('check_in')); } if (!isset($_REQUEST['check_out'])) { $check_out = date('m/d/Y', strtotime("+1 day")); } else { $check_out = TravelHelper::convertDateFormat(STInput::request('check_out')); } $room_num_search = STInput::request('room_num_search'); if (!isset($room_num_search) || intval($room_num_search) <= 0) { $room_num_search = 1; } $room_id = get_the_ID(); $total_price = STPrice::getRoomPriceOnlyCustomPrice($room_id, strtotime($check_in), strtotime($check_out), $room_num_search); $default = array('align' => 'right'); if (isset($attr)) { extract(wp_parse_args($attr, $default)); } else { extract($default); } $room_id = get_the_ID(); $item_id = get_post_meta(get_the_ID(), 'room_parent', true); $booking_period = intval(get_post_meta($item_id, 'hotel_booking_period', TRUE)); $numberday = TravelHelper::dateDiff($check_in, $check_out); $extra_price = get_post_meta(get_the_ID(), 'extra_price', true); $external = STRoom::get_external_url(); ?> <div class="hotel-room-form"> <!-- <div class="overlay-form"><i class="fa fa-refresh text-color"></i></div> -->
static function get_avg_price_hotel($hotel_id) { global $wpdb; $rooms = self::_getAllRoomHotelID($hotel_id); $avg_price = 0; $check_in = STInput::request('start', ''); $check_out = STInput::request('end', ''); if (empty($check_in)) { $check_in = date('m/d/Y'); } else { $check_in = TravelHelper::convertDateFormat($check_in); } if (empty($check_out)) { $check_out = date('m/d/Y', strtotime("+1 day")); } else { $check_out = TravelHelper::convertDateFormat($check_out); } $room_num_search = STInput::request('room_num_search', 1); if (intval($room_num_search) <= 0) { $room_num_search = 1; } $room_full_ordered = HotelHelper::_get_room_cant_book_by_id($hotel_id, date('Y-m-d', strtotime($check_in)), date('Y-m-d', strtotime($check_out)), $room_num_search); if (is_array($rooms) && count($rooms)) { $i = 0; foreach ($rooms as $room) { if (!in_array($room, $room_full_ordered)) { $price = STPrice::getRoomPriceOnlyCustomPrice($room, strtotime($check_in), strtotime($check_out), $room_num_search); if ($price > 0) { $avg_price += $price; } } $i++; } $avg_price /= $i; } return $avg_price; }
function _check_validate() { $data = array(); $order_item_id = STInput::request('order_item_id', ''); $st_first_name = STInput::request('st_first_name', ''); if (empty($st_first_name)) { STAdmin::set_message(__('The firstname field is not empty.', ST_TEXTDOMAIN), 'danger'); return false; } $st_last_name = STInput::request('st_last_name', ''); if (empty($st_last_name)) { STAdmin::set_message(__('The lastname field is not empty.', ST_TEXTDOMAIN), 'danger'); return false; } $st_email = STInput::request('st_email', ''); if (empty($st_email)) { STAdmin::set_message(__('The email field is not empty.', ST_TEXTDOMAIN), 'danger'); return false; } $st_phone = STInput::request('st_phone', ''); if (empty($st_phone)) { STAdmin::set_message(__('The phone field is not empty.', ST_TEXTDOMAIN), 'danger'); return false; } if (STInput::request('section', '') != 'edit_order_item') { $item_id = intval(STInput::request('item_id', '')); if ($item_id <= 0 || get_post_type($item_id) != 'st_holidays') { STAdmin::set_message(__('The holiday field is not empty.', ST_TEXTDOMAIN), 'danger'); return false; } $type_holiday = get_post_meta($item_id, 'type_holiday', true); $today = date('Y-m-d'); $check_in = STInput::request('check_in', ''); $check_out = STInput::request('check_out', ''); if (!$check_in || !$check_out) { STAdmin::set_message(__('Select a holiday in the calendar above.', ST_TEXTDOMAIN), 'danger'); $pass_validate = FALSE; return false; } $compare = TravelHelper::dateCompare($today, $check_in); if ($compare < 0) { STAdmin::set_message(__('This holiday has expired', ST_TEXTDOMAIN), 'danger'); $pass_validate = false; return false; } $duration = ($type_holiday = 'daily_holiday') ? get_post_meta($item_id, 'duration_day', true) : ''; $booking_period = intval(get_post_meta($item_id, 'holidays_booking_period', true)); $period = TravelHelper::dateDiff($today, $check_in); if ($period < $booking_period) { STAdmin::set_message(sprintf(__('This holiday allow minimum booking is %d day(s)', ST_TEXTDOMAIN), $booking_period), 'danger'); $pass_validate = false; return false; } $adult_number = intval(STInput::request('adult_number', 1)); $child_number = intval(STInput::request('child_number', 0)); $infant_number = intval(STInput::request('infant_number', 0)); $max_number = intval(get_post_meta($item_id, 'max_people', true)); if ($adult_number + $child_number + $infant_number > $max_number) { STAdmin::set_message(sprintf(__('Max of people for this holiday is %d people', ST_TEXTDOMAIN), $max_number), 'danger'); return false; } $holiday_available = HolidayHelper::checkAvailableHoliday($item_id, strtotime($check_in), strtotime($check_out)); if (!$holiday_available) { STAdmin::set_message(__('The check in, check out day is not invalid or this holiday not available.', ST_TEXTDOMAIN), 'danger'); $pass_validate = FALSE; return false; } $free_people = intval(get_post_meta($item_id, 'max_people', true)); $result = HolidayHelper::_get_free_peple($item_id, strtotime($check_in), strtotime($check_out), $order_item_id); if (is_array($result) && count($result)) { $free_people = intval($result['free_people']); } if ($free_people > $max_number) { STAdmin::set_message(sprintf(__('This holiday only vacant %d people', ST_TEXTDOMAIN), $free_people), 'danger'); $pass_validate = FALSE; return false; } $data['order_item_id'] = $order_item_id; $data['item_id'] = $item_id; $data['check_in'] = date('m/d/Y', strtotime($check_in)); $data['check_out'] = date('m/d/Y', strtotime($check_out)); $data['adult_number'] = $adult_number; $data['child_number'] = $child_number; $data['infant_number'] = $infant_number; $data['type_holiday'] = $type_holiday; $data['duration'] = $duration; $people_price = STPrice::getPeoplePrice($item_id, strtotime($check_in), strtotime($check_out)); $data = wp_parse_args($data, $people_price); } return $data; }
function _add_booking() { if (!check_admin_referer('shb_action', 'shb_field')) { die; } $data = $this->_check_validate(); if (is_array($data) && count($data)) { extract($data); $order = array('post_title' => __('Order', ST_TEXTDOMAIN) . ' - ' . date(get_option('date_format')) . ' @ ' . date(get_option('time_format')), 'post_type' => 'st_order', 'post_status' => 'publish'); $order_id = wp_insert_post($order); if ($order_id) { $check_out_field = STCart::get_checkout_fields(); if (!empty($check_out_field)) { foreach ($check_out_field as $field_name => $field_desc) { update_post_meta($order_id, $field_name, STInput::post($field_name)); } } $id_user = get_current_user_id(); update_post_meta($order_id, 'id_user', $id_user); update_post_meta($order_id, 'payment_method', 'st_submit_form'); $item_price = STPrice::getRentalPriceOnlyCustomPrice($item_id, strtotime($check_in), strtotime($check_out)); $numberday = TravelHelper::dateDiff($check_in, $check_out); $origin_price = $item_price; //Extra price $extras = STInput::request('extra_price', array()); $extra_price = STPrice::getExtraPrice($extras, $room_num_search, $numberday); $sale_price = STPrice::getSalePrice($item_id, $item_price, strtotime($check_in), strtotime($check_out)); $price_with_tax = STPrice::getPriceWithTax($sale_price + $extra_price); $deposit_money['data'] = array(); $deposit_money = STPrice::getDepositData($item_id, $deposit_money); $deposit_price = STPrice::getDepositPrice($deposit_money['data']['deposit_money'], $price_with_tax, 0); if (isset($deposit_money['data']['deposit_money'])) { $total_price = $deposit_price; } else { $total_price = $price_with_tax; } $data_prices = array('origin_price' => $origin_price, 'sale_price' => $sale_price, 'coupon_price' => 0, 'price_with_tax' => $price_with_tax, 'total_price' => $total_price, 'deposit_price' => $deposit_price); $item_data = array('item_number' => 1, 'item_id' => $item_id, 'item_price' => $item_price, 'check_in' => $check_in, 'check_out' => $check_out, 'adult_number' => $adult_number, 'child_number' => $child_number, 'total_price' => $total_price, 'data_prices' => $data_prices, 'deposit_money' => $deposit_money['data']['deposit_money'], 'booking_by' => 'admin', 'st_tax' => STPrice::getTax(), 'st_tax_percent' => STPrice::getTax(), 'status' => $_POST['status'], 'currency' => TravelHelper::get_current_currency('symbol'), 'currency_rate' => TravelHelper::get_current_currency('rate'), 'extras' => $extras, 'extra_price' => $extra_price, 'commission' => TravelHelper::get_commission()); foreach ($item_data as $val => $value) { update_post_meta($order_id, $val, $value); } if (TravelHelper::checkTableDuplicate('st_rental')) { global $wpdb; $table = $wpdb->prefix . 'st_order_item_meta'; $g_post = get_post($item_id); $partner_id = $g_post ? $g_post->post_author : ''; global $sitepress; if ($sitepress) { $post_type = get_post_type($st_booking_id); if ($post_type == 'st_hotel') { $post_type = 'hotel_room'; $id = $room_id; } else { $id = $st_booking_id; } $lang_code = $sitepress->get_default_language(); $origin_id = icl_object_id($id, $post_type, true, $lang_code); } else { $origin_id = $st_booking_id; } $data = array('order_item_id' => $order_id, 'type' => 'normal_booking', 'check_in' => $check_in, 'check_out' => $check_out, 'st_booking_post_type' => 'st_rental', 'st_booking_id' => $item_id, 'adult_number' => $adult_number, 'child_number' => $child_number, 'check_in_timestamp' => strtotime($check_in), 'check_out_timestamp' => strtotime($check_out), 'room_num_search' => $room_num_search, 'user_id' => $id_user, 'status' => $_POST['status'], 'wc_order_id' => $order_id, 'partner_id' => $partner_id, 'created' => get_the_date('Y-m-d', $order_id), 'total_order' => $total_price, 'commission' => TravelHelper::get_commission(), 'origin_id' => $origin_id); $wpdb->insert($table, $data); } do_action('st_booking_success', $order_id); //Check email $user_name = STInput::post('st_email'); $user_id = username_exists($user_name); if (!$user_id and email_exists($user_name) == false) { $random_password = wp_generate_password($length = 12, $include_standard_special_chars = false); $userdata = array('user_login' => $user_name, 'user_pass' => $random_password, 'user_email' => $user_name, 'first_name' => STInput::post('st_first_name'), 'last_name' => STInput::post('st_last_name')); $user_id = wp_insert_user($userdata); wp_new_user_notification($user_id); } STCart::send_mail_after_booking($order_id, true); STCart::send_email_confirm($order_id); wp_safe_redirect(self::$booking_page); } } }
public function _get_availability_rental_single() { $list_date = array(); $rental_id = STInput::request('post_id', ''); $check_in = STInput::request('start', ''); $check_out = STInput::request('end', ''); $year = date('Y', $check_in); if (empty($year)) { $year = date('Y'); } $year2 = date('Y', $check_out); if (empty($year2)) { $year2 = date('Y'); } $month = date('m', $check_in); if (empty($month)) { $month = date('m'); } $month2 = date('m', $check_out); if (empty($month2)) { $month2 = date('m'); } $result = RentalHelper::_get_full_ordered($rental_id, $month, $month2, $year, $year2); $number_rental = intval(get_post_meta($rental_id, 'rental_number', true)); $min_max = RentalHelper::_get_min_max_date_ordered($rental_id, $year, $year2); if (is_array($min_max) && count($min_max) && is_array($result) && count($result)) { $disable = array(); for ($i = intval($min_max['min_date']); $i <= intval($min_max['max_date']); $i = strtotime('+1 day', $i)) { $num_rental = 0; foreach ($result as $key => $date) { if ($i >= intval($date['check_in_timestamp']) && $i <= intval($date['check_out_timestamp'])) { $num_rental += 1; } } $disable[$i] = $num_rental; } if (count($disable)) { foreach ($disable as $key => $num_rental) { if (intval($num_rental) >= $number_rental) { $list_date[] = date(TravelHelper::getDateFormat(), $key); } } } } $list_date_2 = AvailabilityHelper::_getDisableCustomDateRental($rental_id, $month, $month2, $year, $year2); $date1 = strtotime($year . '-' . $month . '-01'); $date2 = strtotime($year2 . '-' . $month2 . '-01'); $date2 = strtotime(date('Y-m-t', $date2)); $today = strtotime(date('Y-m-d')); $return = array(); $booking_period = intval(get_post_meta($rental_id, 'rentals_booking_period', true)); for ($i = $date1; $i <= $date2; $i = strtotime('+1 day', $i)) { $period = TravelHelper::dateDiff(date('Y-m-d', $today), date('Y-m-d', $i)); $d = date(TravelHelper::getDateFormat(), $i); if (in_array($d, $list_date)) { // booked $return[] = array('start' => date('Y-m-d', $i), 'date' => date('Y-m-d', $i), 'day' => date('d', $i), 'status' => 'booked'); } else { if ($i < $today) { // past $return[] = array('start' => date('Y-m-d', $i), 'date' => date('Y-m-d', $i), 'day' => date('d', $i), 'status' => 'past'); } else { // disabled if (in_array($d, $list_date_2)) { $return[] = array('start' => date('Y-m-d', $i), 'date' => date('Y-m-d', $i), 'day' => date('d', $i), 'status' => 'disabled'); } else { if ($period < $booking_period) { $return[] = array('start' => date('Y-m-d', $i), 'date' => date('Y-m-d', $i), 'day' => date('d', $i), 'status' => 'disabled'); } else { $return[] = array('start' => date('Y-m-d', $i), 'date' => date('Y-m-d', $i), 'day' => date('d', $i), 'status' => 'avalable', 'price' => TravelHelper::format_money(STPrice::getRentalPriceOnlyCustomPrice($rental_id, $i, strtotime('+1 day', $i)))); } } } } } echo json_encode($return); die; }