function do_add_to_cart() { $pass_validate = true; $item_id = STInput::request('item_id', ''); if ($item_id <= 0 || get_post_type($item_id) != 'st_tours') { STTemplate::set_message(__('This tour 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_tour = get_post_meta($item_id, 'type_tour', true); $data['type_tour'] = $type_tour; $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 tour 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 tour has expired', ST_TEXTDOMAIN), 'danger'); $pass_validate = false; return false; } $booking_period = intval(get_post_meta($item_id, 'tours_booking_period', true)); $period = TravelHelper::dateDiff($today, $check_in); if ($period < $booking_period) { STTemplate::set_message(sprintf(__('This tour 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 tour is %d people', ST_TEXTDOMAIN), $max_number), 'danger'); $pass_validate = FALSE; return false; } $tour_available = TourHelper::checkAvailableTour($item_id, strtotime($check_in), strtotime($check_out)); if (!$tour_available) { STTemplate::set_message(__('The check in, check out day is not invalid or this tour not available.', ST_TEXTDOMAIN), 'danger'); $pass_validate = FALSE; return false; } $free_people = intval(get_post_meta($item_id, 'max_people', true)); $result = TourHelper::_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 tour only vacant %d people', ST_TEXTDOMAIN), $free_people), 'danger'); $pass_validate = FALSE; return false; } $data_price = STPrice::getPriceByPeopleTour($item_id, strtotime($check_in), strtotime($check_out), $adult_number, $child_number, $infant_number); $total_price = $data_price['total_price']; $sale_price = STPrice::getSaleTourSalePrice($item_id, $total_price, $type_tour, 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_tour == 'daily_tour' ? floatval(get_post_meta($item_id, 'duration_day', true)) : ''; if ($pass_validate) { STCart::add_cart($item_id, $number, $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)); } } $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::getPriceByPeopleTour($item_id, strtotime($check_in), strtotime($check_out), $adult_number, $child_number, $infant_number); $sale_price = STPrice::getSaleTourSalePrice($item_id, $data_price['total_price'], $type_tour, 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_tour' => $type_tour, '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_tours')) { 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_tours', '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); } } }
function do_add_to_cart() { $pass_validate = true; $item_id = intval(STInput::request('item_id', '')); if ($item_id <= 0 || get_post_type($item_id) != 'st_activity') { STTemplate::set_message(__('This activity is not available..', ST_TEXTDOMAIN), 'danger'); $pass_validate = false; return false; } $number = 1; $type_activity = STInput::request('type_activity', 'specific_date'); $adult_number = intval(STInput::request('adult_number', 1)); $child_number = intval(STInput::request('child_number', 0)); $infant_number = intval(STInput::request('infant_number', 0)); $max_number = intval(get_post_meta($item_id, 'max_people', true)); $today = date('Y-m-d'); if ($adult_number + $child_number + $infant_number > $max_number) { STTemplate::set_message(sprintf(__('Max of people for this activity is %d people', ST_TEXTDOMAIN), $max_number), 'danger'); $pass_validate = FALSE; return false; } if ($type_activity == 'specific_date') { $check_in = TravelHelper::convertDateFormat(STInput::request('check_in', '')); $check_out = TravelHelper::convertDateFormat(STInput::request('check_out', '')); if (empty($check_in)) { STTemplate::set_message(__('The check in field is not empty.', ST_TEXTDOMAIN), 'danger'); $pass_validate = false; return false; } if (empty($check_out)) { STTemplate::set_message(__('The check out field is not empty.', ST_TEXTDOMAIN), 'danger'); $pass_validate = false; return false; } $compare = TravelHelper::dateCompare($today, $check_in); if ($compare < 0) { STTemplate::set_message(__('This activity has expired', ST_TEXTDOMAIN), 'danger'); $pass_validate = false; return false; } $people = $adult_number + $child_number + $child_number; $result = ActivityHelper::_get_free_peple_special($item_id, $check_in, $check_out); $free_people = intval(get_post_meta($item_id, 'max_people', true)); if (is_array($result) && count($result)) { $free_people = intval($result['free_people']); } if ($free_people < $people) { STTemplate::set_message(sprintf(__('This activity only vacant %d people', ST_TEXTDOMAIN), $free_people), 'danger'); $pass_validate = false; return false; } $data['check_in'] = date('m/d/Y', strtotime($check_in)); $data['check_out'] = date('m/d/Y', strtotime($check_out)); } elseif ($type_activity == 'daily_activity') { $check_in = STInput::request('check_in', ''); if (empty($check_in)) { STTemplate::set_message(__('The check in field is not empty.', ST_TEXTDOMAIN), 'danger'); $pass_validate = false; return false; } $check_in = TravelHelper::convertDateFormat($check_in); $check_in = date('Y-m-d', strtotime($check_in)); $duration = intval(get_post_meta($item_id, 'duration', true)); $check_out = $duration >= 2 ? strtotime('+ ' . $duration . ' days', strtotime($check_in)) : strtotime('+ ' . $duration . ' day', strtotime($check_in)); $check_out = date('Y-m-d', $check_out); $booking_period = intval(get_post_meta($item_id, 'activity_booking_period', true)); $period = TravelHelper::dateDiff($today, $check_in); $compare = TravelHelper::dateCompare($today, $check_in); 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 ($booking_period && $booking_period > $period) { STTemplate::set_message(sprintf(__('This activity allow minimum booking is %d day(s)', ST_TEXTDOMAIN), $booking_period), 'danger'); $pass_validate = false; return false; } $people = $adult_number + $child_number + $child_number; $result = ActivityHelper::_get_free_peple_daily($item_id, $check_in); $free_people = intval(get_post_meta($item_id, 'max_people', true)); if (is_array($result) && count($result)) { $free_people = intval($result['free_people']); } if ($free_people < $people) { STTemplate::set_message(sprintf(__('This activity only vacant %d people', ST_TEXTDOMAIN), $free_people), 'danger'); $pass_validate = false; return false; } $data['duration'] = $duration; } $data['adult_number'] = $adult_number; $data['child_number'] = $child_number; $data['infant_number'] = $infant_number; $data['check_in'] = date('m/d/Y', strtotime($check_in)); $data['check_out'] = date('m/d/Y', strtotime($check_out)); $data['type_activity'] = $type_activity; $data_price = STPrice::getPriceByPeople($item_id, strtotime($check_in), strtotime($check_out), $adult_number, $child_number, $infant_number); $total_price = $data_price['total_price']; $sale_price = STPrice::getSaleTourSalePrice($item_id, $total_price, $type_activity, strtotime($check_in)); $discount_rate = STPrice::get_discount_rate($item_id, strtotime($check_in)); $data['adult_price'] = floatval(get_post_meta($item_id, 'adult_price', true)); $data['child_price'] = floatval(get_post_meta($item_id, 'child_price', true)); $data['infant_price'] = floatval(get_post_meta($item_id, 'infant_price', true)); $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'] = $discount_rate; if ($pass_validate) { $pass_validate = apply_filters('st_activity_add_cart_validate', $pass_validate); } if ($pass_validate) { STCart::add_cart($item_id, $number, $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 $data_price = STPrice::getPriceByPeople($item_id, strtotime($check_in), strtotime($check_out), $adult_number, $child_number, $infant_number); $origin_price = floatval($data_price['total_price']); $sale_price = STPrice::getSaleTourSalePrice($item_id, $origin_price, $type_activity, 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 echo TravelHelper::format_money($data_price['adult_price']); ?> </strong></td> </tr> <tr> <td class="text-left title"><?php