appointment-buttons.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. if ( !isset($appointment_id) || !is_numeric($appointment_id) ) {
  3. return;
  4. }
  5. $appointment = Booked_WC_Appointment::get($appointment_id);
  6. $awaiting_status = BOOKED_WC_PLUGIN_PREFIX . 'awaiting';
  7. // add buttons only on appointments with products
  8. if ( !$appointment->products ) {
  9. return;
  10. }
  11. $current_time = current_time('timestamp');
  12. // check if the date has been passed
  13. // if so, hide the edit button
  14. if ( $current_time > $appointment->timestamp ) {
  15. return;
  16. }
  17. if ( !$appointment->calendar ) {
  18. return;
  19. }
  20. $calendar_link = $appointment->calendar->calendar_link;
  21. if ( !$calendar_link ) {
  22. return;
  23. }
  24. $calendar_link = esc_url(add_query_arg(array(
  25. 'app_id' => $appointment_id,
  26. 'app_action' => 'edit',
  27. 'source' => 'booked_wc_extension'
  28. ), $calendar_link));
  29. if ( !$appointment->is_paid && $appointment->payment_status == 'awaiting_checkout' ): ?>
  30. <a href="#" data-appt-id="<?php echo $appointment_id ?>" class="pay"><?php _e('Pay', 'booked-woocommerce-payments'); ?></a>
  31. <?php endif ?>
  32. <a href="<?php echo $calendar_link ?>" data-app-calendar="<?php echo $calendar_link ?>" data-appt-id="<?php echo $appointment_id ?>" class="edit"><?php _e('Change Date', 'booked-woocommerce-payments'); ?></a>
  33. <?php if ( !get_option('booked_dont_allow_user_cancellations',false) ) {
  34. $current_timestamp = current_time('timestamp');
  35. $cancellation_buffer = get_option('booked_cancellation_buffer',0);
  36. if ($cancellation_buffer):
  37. if ($cancellation_buffer < 1){
  38. $time_type = 'minutes';
  39. $time_count = $cancellation_buffer * 60;
  40. } else {
  41. $time_type = 'hours';
  42. $time_count = $cancellation_buffer;
  43. }
  44. $buffered_timestamp = strtotime('+'.$time_count.' '.$time_type,$current_timestamp);
  45. $date_to_compare = $buffered_timestamp;
  46. else:
  47. $date_to_compare = current_time('timestamp');
  48. endif;
  49. $date_to_convert = date_i18n('Y-m-d',$appointment->timestamp);
  50. $timeslots = explode('-',$appointment->timeslot);
  51. $appt_date_time = strtotime($date_to_convert.' '.date_i18n('H:i:s',strtotime($timeslots[0])));
  52. if ( $appt_date_time >= $date_to_compare) {
  53. if (!$appointment->is_paid || $appointment->is_paid && $appointment->order_id == 'manual'){
  54. echo '<a href="#" data-appt-id="'.$appointment_id.'" class="cancel">'.__('Cancel Appointment','booked-woocommerce-payments').'</a>';
  55. }
  56. }
  57. }