create-coupon.php
11 months ago
create-trip.php
6 months ago
duplicate-trip.php
6 months ago
list-bookings.php
11 months ago
list-coupons.php
3 weeks ago
list-trips.php
11 months ago
retrieve-booking.php
11 months ago
retrieve-coupon.php
3 weeks ago
retrieve-enquiry.php
2 months ago
update-booking-status.php
11 months ago
update-coupon.php
3 weeks ago
update-trip.php
6 months ago
update-booking-status.php
127 lines
| 1 | <?php |
| 2 | /** |
| 3 | * UpdateBookingStatus. |
| 4 | * php version 5.6 |
| 5 | * |
| 6 | * @category UpdateBookingStatus |
| 7 | * @package SureTriggers |
| 8 | * @author BSF <username@example.com> |
| 9 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3 |
| 10 | * @link https://www.brainstormforce.com/ |
| 11 | * @since 1.0.0 |
| 12 | */ |
| 13 | |
| 14 | namespace SureTriggers\Integrations\WPTravelEngine\Actions; |
| 15 | |
| 16 | use SureTriggers\Integrations\AutomateAction; |
| 17 | use SureTriggers\Traits\SingletonLoader; |
| 18 | |
| 19 | /** |
| 20 | * UpdateBookingStatus |
| 21 | * |
| 22 | * @category UpdateBookingStatus |
| 23 | * @package SureTriggers |
| 24 | * @author BSF <username@example.com> |
| 25 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3 |
| 26 | * @link https://www.brainstormforce.com/ |
| 27 | * @since 1.0.0 |
| 28 | */ |
| 29 | class UpdateBookingStatus extends AutomateAction { |
| 30 | |
| 31 | /** |
| 32 | * Integration type. |
| 33 | * |
| 34 | * @var string |
| 35 | */ |
| 36 | public $integration = 'WPTravelEngine'; |
| 37 | |
| 38 | /** |
| 39 | * Action name. |
| 40 | * |
| 41 | * @var string |
| 42 | */ |
| 43 | public $action = 'wte_update_booking_status'; |
| 44 | |
| 45 | use SingletonLoader; |
| 46 | |
| 47 | /** |
| 48 | * Register a action. |
| 49 | * |
| 50 | * @param array $actions actions. |
| 51 | * @return array |
| 52 | */ |
| 53 | public function register( $actions ) { |
| 54 | $actions[ $this->integration ][ $this->action ] = [ |
| 55 | 'label' => __( 'Update Booking Status', 'suretriggers' ), |
| 56 | 'action' => $this->action, |
| 57 | 'function' => [ $this, '_action_listener' ], |
| 58 | ]; |
| 59 | return $actions; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Action listener. |
| 64 | * |
| 65 | * @param int $user_id user_id. |
| 66 | * @param int $automation_id automation_id. |
| 67 | * @param array $fields fields. |
| 68 | * @param array $selected_options selectedOptions. |
| 69 | * @return array |
| 70 | */ |
| 71 | public function _action_listener( $user_id, $automation_id, $fields, $selected_options ) { |
| 72 | |
| 73 | if ( ! function_exists( 'wp_travel_engine_get_booking_status' ) ) { |
| 74 | return [ |
| 75 | 'status' => 'error', |
| 76 | 'message' => __( 'WP Travel Engine plugin is not active.', 'suretriggers' ), |
| 77 | |
| 78 | ]; |
| 79 | } |
| 80 | |
| 81 | if ( empty( $selected_options['booking_id'] ) ) { |
| 82 | return [ |
| 83 | 'status' => 'error', |
| 84 | 'message' => __( 'Booking ID is required.', 'suretriggers' ), |
| 85 | |
| 86 | ]; |
| 87 | } |
| 88 | |
| 89 | if ( empty( $selected_options['new_status'] ) ) { |
| 90 | return [ |
| 91 | 'status' => 'error', |
| 92 | 'message' => __( 'New status is required.', 'suretriggers' ), |
| 93 | |
| 94 | ]; |
| 95 | } |
| 96 | |
| 97 | $booking_id = absint( $selected_options['booking_id'] ); |
| 98 | $new_status = sanitize_text_field( $selected_options['new_status'] ); |
| 99 | |
| 100 | $booking = get_post( $booking_id ); |
| 101 | if ( ! $booking || 'booking' !== $booking->post_type ) { |
| 102 | return [ |
| 103 | 'status' => 'error', |
| 104 | 'message' => __( 'Booking not found.', 'suretriggers' ), |
| 105 | |
| 106 | ]; |
| 107 | } |
| 108 | |
| 109 | $old_status = get_post_meta( $booking_id, 'wp_travel_engine_booking_status', true ); |
| 110 | |
| 111 | update_post_meta( $booking_id, 'wp_travel_engine_booking_status', $new_status ); |
| 112 | |
| 113 | do_action( 'wte_booking_status_changed', $booking_id, $old_status, $new_status ); |
| 114 | |
| 115 | return [ |
| 116 | 'status' => 'success', |
| 117 | 'data' => [ |
| 118 | 'booking_id' => $booking_id, |
| 119 | 'old_status' => $old_status, |
| 120 | 'new_status' => $new_status, |
| 121 | ], |
| 122 | ]; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | UpdateBookingStatus::get_instance(); |
| 127 |