Пример #1
0
 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');
             $data_price = STPrice::getPriceByPeopleHoliday($item_id, strtotime($check_in), strtotime($check_out), $adult_number, $child_number, $infant_number);
             $sale_price = STPrice::getSaleHolidaySalePrice($item_id, $data_price['total_price'], $type_holiday, strtotime($check_in));
             $price_with_tax = STPrice::getPriceWithTax($sale_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']) && $deposit_price > 0) {
                 $total_price = $deposit_price;
             } else {
                 $total_price = $price_with_tax - $coupon_price;
             }
             $data_prices = array('origin_price' => $data_price['total_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, 'check_in' => date('Y-m-d', strtotime($check_in)), 'check_out' => date('Y-m-d', strtotime($check_out)), 'type_holiday' => $type_holiday, 'duration' => $duration, 'adult_price' => $adult_price, 'child_price' => $child_price, 'infant_price' => $infant_price, 'adult_number' => $adult_number, 'child_number' => $child_number, 'infant_number' => $child_number, 'total_price' => $total_price, 'data_prices' => $data_prices, 'booking_by' => 'admin', 'st_tax' => STPrice::getTax(), 'st_tax_percent' => STPrice::getTax(), 'status' => $_POST['status'], 'deposit_money' => $deposit_money['data']['deposit_money'], 'currency' => TravelHelper::get_current_currency('symbol'), 'currency_rate' => TravelHelper::get_current_currency('rate'), 'commission' => TravelHelper::get_commission());
             foreach ($item_data as $key => $value) {
                 update_post_meta($order_id, $key, $value);
             }
             if (TravelHelper::checkTableDuplicate('st_holidays')) {
                 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_holidays', 'st_booking_id' => $item_id, 'adult_number' => $adult_number, 'child_number' => $child_number, 'infant_number' => $infant_number, 'check_in_timestamp' => strtotime($check_in), 'check_out_timestamp' => strtotime($check_out), 'duration' => $duration, '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);
             wp_safe_redirect(self::$booking_page);
             do_action('st_booking_success', $order_id);
         }
     }
 }
Пример #2
0
 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;
 }
Пример #3
0
            <input id="field-coupon_code" value="<?php 
echo esc_attr($code);
?>
" 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 
$data_price = STPrice::getPriceByPeopleHoliday($item_id, strtotime($check_in), strtotime($check_out), $adult_number, $child_number, $infant_number);
$origin_price = floatval($data_price['total_price']);
$sale_price = STPrice::getSaleHolidaySalePrice($item_id, $origin_price, $type_holiday, strtotime($check_in));
$price_with_tax = STPrice::getPriceWithTax($sale_price);
?>
    <table border="0" class="table_checkout">
        <tr>
            <td class="text-left title"><?php 
echo __('Adult Price', ST_TEXTDOMAIN);
?>
</td>
            <td class="text-right "><strong><?php 
if ($data_price['adult_price']) {
    echo TravelHelper::format_money($data_price['adult_price']);
} else {
    echo '0';