$pick_up = STInput::request('pick-up', ''); $location_id_drop_off = STInput::request('location_id_drop_off', ''); $drop_off = STInput::request('drop-off', ''); $location_id_pick_up = STInput::request('location_id_pick_up', ''); $start = $pick_up_date . ' ' . $pick_up_time; $start = strtotime($start); $end = $drop_off_date . ' ' . $drop_off_time; $end = strtotime($end); $time = STCars::get_date_diff($start, $end); ///// get Price $info_price = STCars::get_info_price(get_the_ID(), $start, $end); $cars_price = $info_price['price']; $count_sale = $info_price['discount']; $price_origin = $info_price['price_origin']; $list_price = $info_price['list_price']; $data_price_tmp = STPrice::getSaleCarPrice(get_the_ID(), $price_origin, $start, $end); ?> <form id="form-booking-inpage" method="post" class="car_booking_form" > <div class="booking-item-price-calc"> <div class="row row-wrap"> <?php $current_rate = 1; $current = TravelHelper::get_current_currency('name'); $default = TravelHelper::get_default_currency('name'); if ($current != $default) { $current_rate = TravelHelper::get_current_currency('rate'); } ?> <input type="hidden" name="price_rate" value="<?php echo esc_html($current_rate); ?>
/** * @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; }
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); } } }
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) . ')'; } ?> </td>