Exemple #1
0
 function ct_tour_submit_booking()
 {
     global $wpdb, $ct_options;
     // validation
     $result_json = array('success' => 0, 'result' => '');
     if (!isset($_POST['uid']) || !CT_Hotel_Cart::get($_POST['uid'])) {
         $result_json['success'] = 0;
         $result_json['result'] = esc_html__('Sorry, some error occurred on input data validation.', 'citytours');
         wp_send_json($result_json);
     }
     if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'checkout')) {
         $result_json['success'] = 0;
         $result_json['result'] = esc_html__('Sorry, your nonce did not verify.', 'citytours');
         wp_send_json($result_json);
     }
     // init variables
     $uid = $_POST['uid'];
     $post_fields = array('first_name', 'last_name', 'email', 'phone', 'country', 'address1', 'address2', 'city', 'state', 'zip');
     $order_info = ct_order_default_order_data('new');
     foreach ($post_fields as $post_field) {
         if (!empty($_POST[$post_field])) {
             $order_info[$post_field] = sanitize_text_field($_POST[$post_field]);
         }
     }
     $latest_order_id = $wpdb->get_var('SELECT id FROM ' . CT_ORDER_TABLE . ' ORDER BY id DESC LIMIT 1');
     $booking_no = mt_rand(1000, 9999);
     $booking_no .= $latest_order_id;
     $pin_code = mt_rand(1000, 9999);
     $cart_data = CT_Hotel_Cart::get($uid);
     $order_info['total_price'] = $cart_data['total_price'];
     $order_info['total_adults'] = $cart_data['total_adults'];
     $order_info['total_kids'] = $cart_data['total_kids'];
     $order_info['status'] = 'new';
     // new
     $order_info['deposit_paid'] = 1;
     $order_info['mail_sent'] = 0;
     $order_info['post_id'] = $cart_data['tour_id'];
     if (!empty($cart_data['date'])) {
         $order_info['date_from'] = date('Y-m-d', ct_strtotime($cart_data['date']));
     }
     $order_info['booking_no'] = $booking_no;
     $order_info['pin_code'] = $pin_code;
     // calculate deposit payment
     $deposit_rate = get_post_meta($cart_data['tour_id'], '_tour_security_deposit', true);
     // if woocommerce enabled change currency_code and exchange rate as default
     if (!empty($deposit_rate) && ct_is_woo_enabled()) {
         $order_info['currency_code'] = ct_get_def_currency();
         $order_info['exchange_rate'] = 1;
     } else {
         if (!isset($_SESSION['exchange_rate'])) {
             ct_init_currency();
         }
         $order_info['exchange_rate'] = $_SESSION['exchange_rate'];
         $order_info['currency_code'] = ct_get_user_currency();
     }
     // if payment enabled set deposit price field
     if (!empty($deposit_rate) && ct_is_payment_enabled()) {
         $order_info['deposit_price'] = $deposit_rate / 100 * $order_info['total_price'] * $order_info['exchange_rate'];
         $order_info['deposit_paid'] = 0;
         // set unpaid if payment enabled
         $order_info['status'] = 'pending';
     }
     $order_info['created'] = date('Y-m-d H:i:s');
     $order_info['post_type'] = 'tour';
     if ($wpdb->insert(CT_ORDER_TABLE, $order_info)) {
         CT_Hotel_Cart::_unset($uid);
         $order_id = $wpdb->insert_id;
         if (!empty($cart_data['tour'])) {
             $tour_booking_info = array();
             $tour_booking_info['order_id'] = $order_id;
             $tour_booking_info['tour_id'] = $cart_data['tour_id'];
             $tour_booking_info['tour_date'] = $cart_data['date'];
             $tour_booking_info['adults'] = $cart_data['tour']['adults'];
             $tour_booking_info['kids'] = $cart_data['tour']['kids'];
             $tour_booking_info['total_price'] = $cart_data['tour']['total'];
             $wpdb->insert(CT_TOUR_BOOKINGS_TABLE, $tour_booking_info);
         }
         if (!empty($cart_data['add_service'])) {
             foreach ($cart_data['add_service'] as $service_id => $service_data) {
                 $service_booking_info = array();
                 $service_booking_info['order_id'] = $order_id;
                 $service_booking_info['add_service_id'] = $service_id;
                 $service_booking_info['qty'] = $service_data['qty'];
                 $service_booking_info['total_price'] = $service_data['total'];
                 $wpdb->insert(CT_ADD_SERVICES_BOOKINGS_TABLE, $service_booking_info);
             }
         }
         $result_json['success'] = 1;
         $result_json['result']['order_id'] = $order_id;
         $result_json['result']['booking_no'] = $booking_no;
         $result_json['result']['pin_code'] = $pin_code;
     } else {
         $result_json['success'] = 0;
         $result_json['result'] = esc_html__('Sorry, An error occurred while add your order.', 'citytours');
     }
     wp_send_json($result_json);
 }
Exemple #2
0
$deposit_rate = get_post_meta($tour_id, '_tour_security_deposit', true);
$deposit_rate = empty($deposit_rate) ? 0 : $deposit_rate;
$add_services = ct_get_add_services_by_postid($tour_id);
$date = '';
if (!empty($is_repeated)) {
    if (empty($_REQUEST['date'])) {
        do_action('ct_tour_booking_wrong_data');
        // ct_redirect_home() - if data is not valid return to home
        exit;
    }
    $date = $_REQUEST['date'];
}
$uid = $tour_id . $date;
$adults = isset($_REQUEST['adults']) ? $_REQUEST['adults'] : 1;
$kids = isset($_REQUEST['kids']) ? $_REQUEST['kids'] : 0;
if (($cart_data = CT_Hotel_Cart::get($uid)) && $adults == $cart_data['tour']['adults'] && $kids == $cart_data['tour']['kids']) {
    // init booking info if cart is not empty
    $total_price = $cart_data['tour']['total'];
} else {
    // init cart if it is empty
    $total_price = ct_tour_calc_tour_price($tour_id, $date, $adults, $kids);
    $cart_data = array('tour' => array('adults' => $adults, 'kids' => $kids, 'total' => $total_price), 'tour_id' => $tour_id, 'date' => $date, 'total_adults' => $adults, 'total_kids' => $kids, 'total_price' => $total_price);
    CT_Hotel_Cart::set($uid, $cart_data);
}
$cart = new CT_Hotel_Cart();
$cart_service = $cart->get_field($uid, 'add_service');
// main function
if (!ct_get_tour_checkout_page()) {
    ?>
	<h5 class="alert alert-warning"><?php 
    echo esc_html__('Please set checkout page in theme options panel.', 'citytours');
<?php

// validation
if (isset($_REQUEST['uid'])) {
    // init variables
    $uid = $_REQUEST['uid'];
    if (!CT_Hotel_Cart::get($uid)) {
        do_action('ct_hotel_booking_wrong_data');
        // ct_redirect_home() - if data is not valid return to home
        exit;
    }
    $cart = new CT_Hotel_Cart();
    $hotel_id = $cart->get_field($uid, 'hotel_id');
    $date_from = $cart->get_field($uid, 'date_from');
    $date_to = $cart->get_field($uid, 'date_to');
    $cart_rooms = $cart->get_field($uid, 'room');
    $cart_service = $cart->get_field($uid, 'add_service');
    $user_info = ct_get_current_user_info();
    $_countries = ct_get_all_countries();
    $deposit_rate = get_post_meta($hotel_id, '_hotel_security_deposit', true);
    $deposit_rate = empty($deposit_rate) ? 0 : $deposit_rate;
    // function
    if (!ct_get_hotel_thankyou_page()) {
        ?>
		<h5 class="alert alert-warning"><?php 
        echo esc_html__('Please set booking confirmation page in theme options panel.', 'citytours');
        ?>
</h5>
	<?php 
    } else {
        ?>