edit-appointment.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. do_action('booked_before_editing_appointment');
  3. $appt_id = isset($_POST['appt_id']) ? $_POST['appt_id'] : '';
  4. $date = isset($_POST['appt_date']) ? $_POST['appt_date'] : '';
  5. $timeslot = isset($_POST['appt_timeslot']) ? $_POST['appt_timeslot'] : '';
  6. $first_name = isset($_POST['name']) ? $_POST['name'] : '';
  7. $last_name = isset($_POST['surname']) ? $_POST['surname'] : '';
  8. $email = isset($_POST['email']) ? $_POST['email'] : '';
  9. $phone = isset($_POST['phone']) ? $_POST['phone'] : '';
  10. $user_id = (isset($_POST['user_id']) ? $_POST['user_id'] : false);
  11. $calendar_id = (isset($_POST['calendar_id']) ? $_POST['calendar_id'] : false);
  12. $_timeslots = explode( '-', $timeslot );
  13. $_timestamp_time = date( 'H:i:s', strtotime( $_timeslots[0] ) );
  14. if ( $appt_id ):
  15. if ( $email && !is_email($email) ):
  16. echo 'error###' . esc_html__( 'That email does not appear to be valid.','booked');
  17. wp_die();
  18. endif;
  19. if ($calendar_id):
  20. $booked_defaults = get_option('booked_defaults_'.$calendar_id);
  21. if (!$booked_defaults):
  22. $booked_defaults = get_option('booked_defaults');
  23. endif;
  24. else :
  25. $booked_defaults = get_option('booked_defaults');
  26. endif;
  27. $booked_defaults = booked_apply_custom_timeslots_filter($booked_defaults,$calendar_id);
  28. $timestamp = strtotime( date_i18n('Y-m-d', strtotime($date) ) . ' ' . $_timestamp_time );
  29. $day = date('D',strtotime($date));
  30. $title = isset($booked_defaults[$day.'-details'][$timeslot]['title']) ? $booked_defaults[$day.'-details'][$timeslot]['title'] : '';
  31. if ( !$user_id ):
  32. update_post_meta( $appt_id, '_appointment_title', $title );
  33. update_post_meta( $appt_id, '_appointment_guest_name', $first_name );
  34. update_post_meta( $appt_id, '_appointment_guest_surname', $last_name );
  35. update_post_meta( $appt_id, '_appointment_guest_email', $email );
  36. update_post_meta( $appt_id, '_appointment_timestamp', $timestamp );
  37. update_post_meta( $appt_id, '_appointment_timeslot', $timeslot );
  38. else:
  39. update_post_meta( $appt_id, '_appointment_title', $title );
  40. update_post_meta( $appt_id, '_appointment_phone', $phone );
  41. update_post_meta( $appt_id, '_appointment_timestamp', $timestamp );
  42. update_post_meta( $appt_id, '_appointment_timeslot', $timeslot );
  43. update_user_meta( $user_id, 'booked_phone', $phone );
  44. wp_update_user( array( 'ID' => $user_id, 'first_name' => $first_name, 'last_name' => $last_name, 'user_email' => $email, 'user_login' => $email, 'display_name' => $first_name . ( $last_name ? ' ' . $last_name : '' ) ) );
  45. endif;
  46. endif;