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'); $item_price = STPrice::getRentalPriceOnlyCustomPrice($item_id, strtotime($check_in), strtotime($check_out)); $numberday = TravelHelper::dateDiff($check_in, $check_out); $origin_price = $item_price; //Extra price $extras = STInput::request('extra_price', array()); $extra_price = STPrice::getExtraPrice($extras, $room_num_search, $numberday); $sale_price = STPrice::getSalePrice($item_id, $item_price, strtotime($check_in), strtotime($check_out)); $price_with_tax = STPrice::getPriceWithTax($sale_price + $extra_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'])) { $total_price = $deposit_price; } else { $total_price = $price_with_tax; } $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); $item_data = array('item_number' => 1, 'item_id' => $item_id, 'item_price' => $item_price, 'check_in' => $check_in, 'check_out' => $check_out, 'adult_number' => $adult_number, 'child_number' => $child_number, 'total_price' => $total_price, 'data_prices' => $data_prices, 'deposit_money' => $deposit_money['data']['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'), 'extras' => $extras, 'extra_price' => $extra_price, 'commission' => TravelHelper::get_commission()); foreach ($item_data as $val => $value) { update_post_meta($order_id, $val, $value); } if (TravelHelper::checkTableDuplicate('st_rental')) { 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_rental', 'st_booking_id' => $item_id, 'adult_number' => $adult_number, 'child_number' => $child_number, 'check_in_timestamp' => strtotime($check_in), 'check_out_timestamp' => strtotime($check_out), 'room_num_search' => $room_num_search, '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); } do_action('st_booking_success', $order_id); //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); } } }
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); } } }
</td> <td class="text-right "><strong><?php echo TravelHelper::format_money($extra_price); ?> </strong></td> </tr> <?php } ?> <tr> <td class="text-left title"><?php echo __('Tax', ST_TEXTDOMAIN); ?> </td> <td class="text-right "><strong><?php echo STPrice::getTax() . ' %'; ?> </strong></td> </tr> <tr> <td class="text-left title"><?php echo __('Total Price (with tax)', ST_TEXTDOMAIN); ?> </td> <td class="text-right "><strong><?php echo TravelHelper::format_money($price_with_tax); ?> </strong></td> </tr> <?php if (STCart::use_coupon()) {
static function booking_form_submit($item_id = '') { if (STInput::post('st_payment_gateway') and wp_verify_nonce(STInput::post('travel_order'), 'submit_form_order')) { $first_item_id = self::get_booking_id(); // All gateway available $gateways = STPaymentGateways::get_payment_gateways(); if (empty($gateways)) { return array('status' => false, 'message' => __('Sorry! No payment gateway available', ST_TEXTDOMAIN)); } $payment_gateway_used = false; $payment_gateway_id = false; if (!empty($gateways)) { foreach ($gateways as $key => $value) { if (STInput::post('st_payment_gateway_' . $key)) { $payment_gateway_id = $key; $payment_gateway_used = STPaymentGateways::get_gateway($payment_gateway_id, $first_item_id); } } } if (!$payment_gateway_id or !$payment_gateway_used) { $payment_gateway_name = apply_filters('st_payment_gateway_' . $payment_gateway_id . '_name', $payment_gateway_id); return array('status' => false, 'message' => sprintf(__('Sorry! Payment Gateway: <code>%s</code> is not available for this item!', ST_TEXTDOMAIN), $payment_gateway_name)); } // Action before submit form do_action('st_before_form_submit_run'); $form_validate = true; if (!self::check_cart()) { return array('status' => false, 'message' => __('Your cart is currently empty.', ST_TEXTDOMAIN), 'code' => '1'); } if ($coupon_code = STInput::request('coupon_code')) { $status = self::do_apply_coupon($coupon_code); if (!$status['status']) { return array('status' => false, 'message' => $status['message']); } } if (st()->get_option('booking_enable_captcha', 'on') == 'on') { $st_security_key = STInput::request('st_security_key'); $allow_captcha = STInput::request('allow_capcha', 'off'); if ($allow_captcha == 'off') { if (!$st_security_key) { return array('status' => false, 'message' => __('You dose not enter the captcha', ST_TEXTDOMAIN)); } $valid = STCoolCaptcha::validate_captcha($st_security_key); if (!$valid) { return array('status' => false, 'message' => __('Captcha is not correct', ST_TEXTDOMAIN), 'error_code' => 'invalid_captcha'); } } } $default = array('st_note' => '', 'term_condition' => '', 'create_account' => false, 'paypal_checkout' => false); extract(wp_parse_args($_POST, $default)); //Term and condition if (!$term_condition) { return array('status' => false, 'message' => __('Please accept our terms and conditions', ST_TEXTDOMAIN)); } $form_validate = self::validate_checkout_fields(); if ($form_validate) { $form_validate = $payment_gateway_used->_pre_checkout_validate(); } if (!$form_validate) { $message = array('status' => false, 'message' => STTemplate::get_message_content(), 'form_validate' => 'false'); STTemplate::clear(); return $message; } $post = array('post_title' => __('Order', ST_TEXTDOMAIN) . ' - ' . date(get_option('date_format')) . ' @ ' . date(get_option('time_format')), 'post_type' => 'st_order', 'post_status' => 'publish'); $data_price = STPrice::getDataPrice(); //save the order $insert_post = wp_insert_post($post); if ($insert_post) { $cart = self::get_items(); $fields = self::get_checkout_fields(); if (!empty($fields)) { foreach ($fields as $key => $value) { update_post_meta($insert_post, $key, STInput::post($key)); } } update_post_meta($insert_post, 'st_tax', STPrice::getTax()); update_post_meta($insert_post, 'st_tax_percent', STPrice::getTax()); update_post_meta($insert_post, 'st_is_tax_included_listing_page', STCart::is_tax_included_listing_page() ? 'on' : 'off'); update_post_meta($insert_post, 'currency', TravelHelper::get_current_currency('symbol')); update_post_meta($insert_post, 'currency_rate', TravelHelper::get_current_currency('rate')); update_post_meta($insert_post, 'coupon_code', STCart::get_coupon_code()); update_post_meta($insert_post, 'coupon_amount', STCart::get_coupon_amount()); update_post_meta($insert_post, 'status', 'pending'); update_post_meta($insert_post, 'st_cart_info', $cart); update_post_meta($insert_post, 'total_price', STPrice::getTotal()); update_post_meta($insert_post, 'ip_address', STInput::ip_address()); update_post_meta($insert_post, 'order_token_code', wp_hash($insert_post)); update_post_meta($insert_post, 'data_prices', $data_price); update_post_meta($insert_post, 'booking_by', STInput::post('booking_by', '')); self::saveOrderItems($insert_post); if (!is_user_logged_in()) { $user_name = STInput::post('st_email'); $user_id = username_exists($user_name); //Now Create Account if user agree if ($create_account) { 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); //Create User Success, send the nofitication wp_new_user_notification($user_id); } } } else { $user_id = get_current_user_id(); } if ($user_id) { //Now Update the Post Meta update_post_meta($insert_post, 'id_user', $user_id); //Update User Meta update_user_meta($user_id, 'st_phone', STInput::post('st_phone')); update_user_meta($user_id, 'first_name', STInput::post('st_first_name')); update_user_meta($user_id, 'last_name', STInput::post('st_last_name')); update_user_meta($user_id, 'st_address', STInput::post('st_address')); update_user_meta($user_id, 'st_address2', STInput::post('st_address2')); update_user_meta($user_id, 'st_city', STInput::post('st_city')); update_user_meta($user_id, 'st_province', STInput::post('st_province')); update_user_meta($user_id, 'st_zip_code', STInput::post('st_zip_code')); update_user_meta($user_id, 'st_country', STInput::post('st_country')); } update_post_meta($insert_post, 'payment_method', $payment_gateway_id); do_action('st_booking_success', $insert_post); // Now gateway do the rest return $payment_gateway_used->do_checkout($insert_post); } else { return array('status' => false, 'message' => __('Can not save order.', ST_TEXTDOMAIN)); } } }