Пример #1
0
 static function get_room_price($room_id, $start_date, $end_date)
 {
     if (!$room_id) {
         $room_id = get_the_ID();
     }
     $list_price = array();
     $price = 0;
     $number_days = 0;
     if ($start_date and $end_date) {
         $one_day = 60 * 60 * 24;
         $str_start_date = strtotime($start_date);
         $str_end_date = strtotime($end_date);
         $number_days = ($str_end_date - $str_start_date) / $one_day;
         $total = 0;
         for ($i = 1; $i <= $number_days; $i++) {
             $data_date = date("Y-m-d", $str_start_date + $one_day * $i);
             $date_tmp = date("Y-m-d", strtotime($data_date) - $one_day);
             $data_price = get_post_meta($room_id, 'price', true);
             $price_custom = TravelerObject::st_get_custom_price_by_date($room_id, $data_date);
             if ($price_custom) {
                 $data_price = $price_custom;
             }
             $list_price[$data_date] = array('start' => $date_tmp, 'end' => $data_date, 'price' => apply_filters('st_apply_tax_amount', $data_price));
             $total += $data_price;
         }
         $price = $total;
     }
     /** get custom price by date **/
     /** get custom price by date **/
     $data_price = array('discount' => false, 'price' => apply_filters('st_apply_tax_amount', $price), 'info_price' => $list_price, 'number_day' => $number_days);
     if ($price > 0) {
         $discount_rate = get_post_meta($room_id, 'discount_rate', true);
         $is_sale_schedule = get_post_meta($room_id, 'is_sale_schedule', true);
         if ($is_sale_schedule == 'on') {
             $sale_from = get_post_meta($room_id, 'sale_price_from', true);
             $sale_to = get_post_meta($room_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_rate = 0;
                 }
             } else {
                 $discount_rate = 0;
             }
         }
         if ($discount_rate > 100) {
             $discount_rate = 100;
         }
         if ($discount_rate) {
             $data_price = array('discount' => true, 'price' => apply_filters('st_apply_tax_amount', $price - $price / 100 * $discount_rate), 'price_old' => apply_filters('st_apply_tax_amount', $price), 'info_price' => $list_price, 'number_day' => $number_days);
         }
     }
     return $data_price;
 }
Пример #2
0
 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);
 }