/** * @since 1.0.9 * @update 1.1.3 **/ function do_add_to_cart() { $pass_validate = true; $item_id = STInput::request('item_id', ''); if ($item_id <= 0 || get_post_type($item_id) != 'st_cars') { STTemplate::set_message(__('This car is not available.', ST_TEXTDOMAIN), 'danger'); $pass_validate = FALSE; return false; } $number = 1; // Validate required field if (!isset($_POST['booking_by']) || $_POST['booking_by'] != 'partner') { $change_location_date_box = $this->get_search_fields_box(); $field_types = $this->get_search_fields_name(); if (!empty($change_location_date_box)) { $message = ''; foreach ($change_location_date_box as $key => $value) { if (isset($field_types[$value['field_atrribute']]) and $value['is_required'] == 'on') { $field_name = isset($field_types[$value['field_atrribute']]['field_name']) ? $field_types[$value['field_atrribute']]['field_name'] : false; if ($field_name) { if (is_array($field_name)) { foreach ($field_name as $v) { if (!STInput::request($v)) { $message .= sprintf(__('%s is required', ST_TEXTDOMAIN), $value['title']) . '<br>'; $pass_validate = false; } } } elseif (is_string($field_name)) { if (!STInput::request($field_name)) { $message .= sprintf(__('%s is required', ST_TEXTDOMAIN), $value['title']) . '<br>'; $pass_validate = false; } } } } } if ($message) { $message = substr($message, 0, -4); STTemplate::set_message($message, 'danger'); } } } $check_in = ''; $check_in_n = ''; $check_in_time = ''; if (isset($_REQUEST['pick-up-date']) && !empty($_REQUEST['pick-up-date'])) { $check_in = TravelHelper::convertDateFormat($_REQUEST['pick-up-date']); $check_in_n = $check_in; } if (isset($_REQUEST['pick-up-time']) && !empty($_REQUEST['pick-up-time'])) { $check_in .= ' ' . $_REQUEST['pick-up-time']; $check_in_time = $_REQUEST['pick-up-time']; } $check_in = date('Y-m-d H:i:s', strtotime($check_in)); $check_out = ''; $check_out_n = ''; $check_out_time = ''; if (isset($_REQUEST['drop-off-date']) && !empty($_REQUEST['drop-off-date'])) { $check_out = TravelHelper::convertDateFormat($_REQUEST['drop-off-date']); $check_out_n = $check_out; } if (isset($_REQUEST['drop-off-time']) && !empty($_REQUEST['drop-off-time'])) { $check_out .= ' ' . $_REQUEST['drop-off-time']; $check_out_time = $_REQUEST['drop-off-time']; } $check_out = date('Y-m-d H:i:s', strtotime($check_out)); $location_id_pick_up = STInput::request('location_id_pick_up', ''); $location_id_drop_off = STInput::request('location_id_drop_off', ''); if (isset($_REQUEST['location_id_pick_up']) && !empty($_REQUEST['location_id_pick_up']) && isset($_REQUEST['location_id_drop_off']) && !empty($_REQUEST['location_id_drop_off'])) { $location_id_pick_up = intval(STInput::request('location_id_pick_up', '0')); $location_id_drop_off = intval(STInput::request('location_id_drop_off', '0')); $pickup_country = get_post_meta($location_id_pick_up, 'location_country', true); $dropoff_country = get_post_meta($location_id_drop_off, 'location_country', true); if (!$pickup_country) { STTemplate::set_message(__('The \'country\' field not set for the \'' . get_the_title($location_id_pick_up) . '\'', ST_TEXTDOMAIN), 'danger'); $pass_validate = false; return false; } if (!$dropoff_country) { STTemplate::set_message(__('The \'country\' field not set for \'' . get_the_title($location_id_drop_off) . '\'', ST_TEXTDOMAIN), 'danger'); $pass_validate = false; return false; } if ($pickup_country != $dropoff_country) { STTemplate::set_message(__('The country is not same', ST_TEXTDOMAIN), 'danger'); $pass_validate = false; return false; } } $today = date('m/d/Y'); $booking_period = intval(get_post_meta($item_id, 'cars_booking_period', true)); $booking_min_day = intval(get_post_meta($item_id, 'cars_booking_min_day', true)); $booking_min_hour = intval(get_post_meta($item_id, 'cars_booking_min_hour', true)); if (empty($booking_period) || $booking_period <= 0) { $booking_period = 0; } $check_in_timestamp = ''; $check_out_timestamp = ''; if (!empty($check_in_n) && !empty($check_out_n)) { $period = TravelHelper::dateDiff($today, $check_in_n); $compare = TravelHelper::dateCompare($today, $check_in_n); $check_in_timestamp = strtotime($check_in); $check_out_timestamp = strtotime($check_out); if ($check_in_timestamp - $check_out_timestamp >= 0) { STTemplate::set_message(__('The drop off datetime is later than the pick up datetime.', ST_TEXTDOMAIN), 'danger'); $pass_validate = false; return false; } 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 car allow minimum booking is %d day(s)', ST_TEXTDOMAIN), $booking_period), 'danger'); $pass_validate = false; return false; } $unit = st()->get_option('cars_price_unit', 'day'); if ($unit == 'day' and $booking_min_day and $booking_min_day > self::get_date_diff($check_in_timestamp, $check_out_timestamp)) { STTemplate::set_message(sprintf(__('Please booking at least %d day(s)', ST_TEXTDOMAIN), $booking_min_day), 'danger'); $pass_validate = false; return false; } if ($unit == 'hour' and $booking_min_hour and $booking_min_hour > self::get_date_diff($check_in_timestamp, $check_out_timestamp)) { STTemplate::set_message(sprintf(__('Please booking at least %d hour(s)', ST_TEXTDOMAIN), $booking_min_hour), 'danger'); $pass_validate = false; return false; } } if ($check_in_timestamp > 0 && $check_out_timestamp > 0) { if (!CarHelper::_get_car_cant_order_by_id($item_id, $check_in_timestamp, $check_out_timestamp)) { STTemplate::set_message(__('This car is full order', ST_TEXTDOMAIN), 'danger'); $pass_validate = false; return false; } } $selected_equipments = json_decode(str_ireplace("\\", '', STInput::request('selected_equipments', ''))); $info_price = STCars::get_info_price($item_id, strtotime($check_in), strtotime($check_out)); $price_unit = $info_price['price']; $item_price = floatval(get_post_meta($item_id, 'cars_price', true)); $price_equipment = STPrice::getPriceEuipmentCar($selected_equipments, $check_in_timestamp, $check_out_timestamp); $sale_price = STPrice::getSaleCarPrice($item_id, $item_price, strtotime($check_in), strtotime($check_out)); $car_sale_price = STPrice::get_car_price_by_number_of_day_or_hour($item_id, $item_price, strtotime($check_in), strtotime($check_out)); $discount_rate = STPrice::get_discount_rate($item_id, strtotime($check_in)); $numberday = $numberday = STCars::get_date_diff(strtotime($check_in), strtotime($check_out), st()->get_option('cars_price_unit', 'day')); $data = array('check_in' => $check_in_n, 'check_out' => $check_out_n, 'check_in_time' => $check_in_time, 'check_out_time' => $check_out_time, 'check_in_timestamp' => strtotime($check_in), 'check_out_timestamp' => strtotime($check_out), 'location_id_pick_up' => $location_id_pick_up, 'location_id_drop_off' => $location_id_drop_off, 'pick_up' => get_the_title($location_id_pick_up), 'drop_off' => get_the_title($location_id_drop_off), 'ori_price' => $sale_price + $price_equipment, 'item_price' => $item_price, 'sale_price' => $car_sale_price, 'numberday' => $numberday, 'price_equipment' => $price_equipment, 'data_equipment' => $selected_equipments, 'commission' => TravelHelper::get_commission(), 'discount_rate' => $discount_rate); $pass_validate = apply_filters('st_car_add_cart_validate', $pass_validate, $item_id, $number, $price_unit, $data); if ($pass_validate) { STCart::add_cart($item_id, $number, $price_equipment + $sale_price, $data); } return $pass_validate; }
?> " type="text" class="form-control" name="coupon_code"> </div> <button class="btn btn-primary" type="submit"><?php _e('Apply Coupon', ST_TEXTDOMAIN); ?> </button> </form> </div> <div class="booking-item-payment-total text-right"> <?php $unit = st()->get_option('cars_price_unit', 'day'); // $time_number=STCars::get_date_diff($check_in_timestamp,$check_out_timestamp); $price_equipment = STPrice::getPriceEuipmentCar($selected_equipments, $check_in_timestamp, $check_out_timestamp); $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); ?> <table border="0" class="table_checkout"> <tr> <td class="text-left title"> <?php echo __('Origin Price', ST_TEXTDOMAIN); ?> <?php $include_tax = STPrice::checkIncludeTax(); if ($include_tax) { echo '(' . __('tax included', ST_TEXTDOMAIN) . ')'; }