function wpestate_new_ajax_add_booking() { check_ajax_referer('booking_ajax_nonce', 'security'); global $current_user; get_currentuserinfo(); $userID = $current_user->ID; $comment = trim($_POST['comment']); $guests = intval($_POST['guests']); $property_id = intval($_POST['property_name']); $fromdate = trim($_POST['fromdate']); $to_date = trim($_POST['todate']); $event_name = esc_html__('Booking Request', 'wpestate'); $post = array('post_title' => $event_name, 'post_content' => $comment, 'post_status' => 'publish', 'post_type' => 'wpestate_booking', 'post_author' => $userID); $post_id = wp_insert_post($post); $post = array('ID' => $post_id, 'post_title' => $event_name . ' ' . $post_id); wp_update_post($post); update_post_meta($post_id, 'booking_id', $property_id); update_post_meta($post_id, 'booking_from_date', $fromdate); update_post_meta($post_id, 'booking_to_date', $to_date); update_post_meta($post_id, 'booking_status', 'confirmed'); update_post_meta($post_id, 'booking_invoice_no', 0); update_post_meta($post_id, 'booking_pay_ammount', 0); update_post_meta($post_id, 'booking_guests', $guests); $preview = wp_get_attachment_image_src(get_post_thumbnail_id($property_id), 'property_sidebar'); // build the reservation array $reservation_array = wpestate_get_booking_dates($property_id); update_post_meta($property_id, 'booking_dates', $reservation_array); print ' <div class="dasboard-prop-listing"> <div class="blog_listing_image"> <img src="' . $preview[0] . '" alt="slider-thumb" /></a> </div> <div class="prop-info"> <h3 class="listing_title"> ' . $event_name . ' </h3> <div class="user_dashboard_listed"> <strong>' . esc_html__('Request by ', 'wpestate') . '</strong>' . get_the_author_meta('user_login', $userID) . '<strong> </div> <div class="user_dashboard_listed"> <strong>' . esc_html__('Period: ', 'wpestate') . '</strong> ' . $fromdate . ' <strong>' . esc_html__('to', 'wpestate') . '</strong> ' . $to_date . ' </div> <div class="user_dashboard_listed"> <strong>' . esc_html__('Invoice No: ', 'wpestate') . '</strong> </div> <div class="user_dashboard_listed"> <strong>' . esc_html__('Pay Ammount: ', 'wpestate') . ' </strong> </div> </div> <div class="info-container_booking"> <span class="tag-published">' . esc_html__('Confirmed', 'wpestate') . '</span> </div> </div>'; die; }
function wpestate_ajax_add_booking() { // check_ajax_referer( 'booking_ajax_nonce','security'); global $current_user; get_currentuserinfo(); $allowded_html = array(); $userID = $current_user->ID; $from = $current_user->user_login; $comment = ''; $status = 'pending'; if (isset($_POST['comment'])) { $comment = wp_kses($_POST['comment'], $allowded_html); } $booking_guest_no = 0; if (isset($_POST['booking_guest_no'])) { $booking_guest_no = intval($_POST['booking_guest_no']); } if (isset($_POST['confirmed'])) { if (intval($_POST['confirmed']) == 1) { $status = 'confirmed'; } } $property_id = intval($_POST['listing_edit']); $owner_id = wpsestate_get_author($property_id); $fromdate = wp_kses($_POST['fromdate'], $allowded_html); $to_date = wp_kses($_POST['todate'], $allowded_html); $event_name = esc_html__('Booking Request', 'wpestate'); $post = array('post_title' => $event_name, 'post_content' => $comment, 'post_status' => 'publish', 'post_type' => 'wpestate_booking', 'post_author' => $userID); $post_id = wp_insert_post($post); $post = array('ID' => $post_id, 'post_title' => $event_name . ' ' . $post_id); wp_update_post($post); update_post_meta($post_id, 'booking_status', $status); update_post_meta($post_id, 'booking_id', $property_id); update_post_meta($post_id, 'owner_id', $owner_id); update_post_meta($post_id, 'booking_from_date', $fromdate); update_post_meta($post_id, 'booking_to_date', $to_date); update_post_meta($post_id, 'booking_invoice_no', 0); update_post_meta($post_id, 'booking_pay_ammount', 0); update_post_meta($post_id, 'booking_guests', $booking_guest_no); // build the reservation array $reservation_array = wpestate_get_booking_dates($property_id); update_post_meta($property_id, 'booking_dates', $reservation_array); if ($owner_id == $userID) { $subject = esc_html__('You reserved a period', 'wpestate'); $description = esc_html__('You have reserverd a period on your own listing', 'wpestate'); $from = $current_user->user_login; $to = $owner_id; $receiver = get_userdata($owner_id); $receiver_email = $receiver->user_email; wpestate_add_to_inbox($userID, $from, $to, $subject, $description); wpestate_send_booking_email('mynewbook', $receiver_email); } else { $subject = esc_html__('New Booking Request from ', 'wpestate'); $description = esc_html__('You have received a new booking request', 'wpestate'); $from = $current_user->ID; $to = $owner_id; $receiver = get_userdata($owner_id); $receiver_email = $receiver->user_email; wpestate_add_to_inbox($userID, $userID, $to, $subject, $description, 1); wpestate_send_booking_email('newbook', $receiver_email); } die; }
//////////////////////////////////////////////////////////////////////////////// ///////////////// payment for booking //////////////////////////////////////////////////////////////////////////////// if (isset($_POST['booking_id'])) { try { $token = $_POST['stripeToken']; $customer = Stripe_Customer::create(array('email' => $stripeEmail, 'card' => $token)); $userId = intval($_POST['userID']); $invoice_id = intval($_POST['invoice_id']); $booking_id = intval($_POST['booking_id']); $depozit = intval($_POST['depozit']); $charge = Stripe_Charge::create(array('customer' => $customer->id, 'amount' => $depozit, 'currency' => $submission_curency_status)); // confirm booking update_post_meta($booking_id, 'booking_status', 'confirmed'); $curent_listng_id = get_post_meta($booking_id, 'booking_id', true); $reservation_array = wpestate_get_booking_dates($curent_listng_id); update_post_meta($curent_listng_id, 'booking_dates', $reservation_array); // set invoice to paid update_post_meta($invoice_id, 'invoice_status', 'confirmed'); update_post_meta($invoice_id, 'depozit_paid', $depozit / 100); ///////////////////////////////////////////////////////////////////////////// // send confirmation emails ///////////////////////////////////////////////////////////////////////////// wpestate_send_booking_email("bookingconfirmeduser", $user_email); $receiver_id = wpsestate_get_author($invoice_id); $receiver_email = get_the_author_meta('user_email', $receiver_id); $receiver_name = get_the_author_meta('user_login', $receiver_id); wpestate_send_booking_email("bookingconfirmed", $receiver_email); // add messages to inbox $subject = esc_html__('Booking Confirmation', 'wpestate'); $description = esc_html__('A booking was confirmed', 'wpestate');
function estate_save_booking_postdata($post_id) { global $post; if (!is_object($post) || !isset($post->post_type)) { return; } if ($post->post_type != 'wpestate_booking') { return; } $curent_listng_id = get_post_meta($post_id, 'booking_id', true); if ($curent_listng_id == '') { $selected = $curent_listng_id = get_post_meta($post->ID, 'booking_listing_name', true); update_post_meta($post_id, 'booking_id', $selected); } // save booking dates; $reservation_array = wpestate_get_booking_dates($curent_listng_id); update_post_meta($curent_listng_id, 'booking_dates', $reservation_array); }