PluginProbe ʕ •ᴥ•ʔ
OttoKit: All-in-One Automation Platform / 1.1.35
OttoKit: All-in-One Automation Platform v1.1.35
1.1.37 1.1.36 1.1.35 1.1.34 1.1.33 1.1.32 1.1.31 1.1.30 1.1.29 1.1.28 1.1.27 1.1.9 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.47 1.0.48 1.0.49 1.0.50 1.0.51 1.0.52 1.0.53 1.0.54 1.0.55 1.0.56 1.0.57 1.0.58 1.0.59 1.0.60 1.0.61 1.0.62 1.0.63 1.0.64 1.0.65 1.0.66 1.0.67 1.0.68 1.0.69 1.0.7 1.0.70 1.0.71 1.0.72 1.0.73 1.0.74 1.0.75 1.0.76 1.0.77 1.0.78 1.0.79 1.0.8 1.0.80 1.0.81 1.0.82 1.0.83 1.0.84 1.0.85 1.0.86 1.0.87 1.0.88 1.0.89 1.0.9 1.0.90 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.20 1.1.21 1.1.22 1.1.23 1.1.24 1.1.25 1.1.26 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8
suretriggers / src / Integrations / wp-travel-engine / actions / list-bookings.php
suretriggers / src / Integrations / wp-travel-engine / actions Last commit date
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
list-bookings.php
167 lines
1 <?php
2 /**
3 * RetrieveBooking.
4 * php version 5.6
5 *
6 * @category RetrieveBooking
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 * RetrieveBooking
21 *
22 * @category RetrieveBooking
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 ListBookings extends AutomateAction {
30
31 use SingletonLoader;
32
33 /**
34 * Integration type.
35 *
36 * @var string
37 */
38 public $integration = 'WPTravelEngine';
39
40 /**
41 * Action name.
42 *
43 * @var string
44 */
45 public $action = 'wte_list_bookings';
46
47 /**
48 * Register the action.
49 *
50 * @param array $actions Actions array.
51 * @return array
52 */
53 public function register( $actions ) {
54 $actions[ $this->integration ][ $this->action ] = [
55 'label' => __( 'List Bookings', 'suretriggers' ),
56 'description' => __( 'Get a list of bookings with optional filtering', 'suretriggers' ),
57 'action' => $this->action,
58 'function' => [ $this, '_action_listener' ],
59 ];
60
61 return $actions;
62 }
63
64 /**
65 * Action listener.
66 *
67 * @param int $user_id User ID.
68 * @param int $automation_id Automation ID.
69 * @param array $fields Fields.
70 * @param array $selected_options Selected options.
71 * @return array
72 */
73 public function _action_listener( $user_id, $automation_id, $fields, $selected_options ) {
74 if ( ! function_exists( 'wp_travel_engine_get_booking_status' ) ) {
75 return [
76 'status' => 'error',
77 'message' => __( 'WP Travel Engine plugin is not active.', 'suretriggers' ),
78
79 ];
80 }
81
82 $limit = ! empty( $selected_options['limit'] ) ? intval( $selected_options['limit'] ) : 20;
83
84 $args = [
85 'post_type' => 'booking',
86 'post_status' => 'publish',
87 'posts_per_page' => $limit,
88 'meta_query' => [],
89 ];
90
91 $bookings_query = new \WP_Query( $args );
92 $bookings = [];
93
94 if ( $bookings_query->have_posts() ) {
95 while ( $bookings_query->have_posts() ) {
96 $bookings_query->the_post();
97 $booking_id = get_the_ID();
98
99 if ( ! $booking_id ) {
100 continue;
101 }
102
103 $booking_status = get_post_meta( $booking_id, 'wp_travel_engine_booking_status', true );
104
105 $cart_info_raw = get_post_meta( $booking_id, 'cart_info', true );
106 $traveler_raw = get_post_meta( $booking_id, 'wptravelengine_travelers_details', true );
107
108 $cart_info = is_string( $cart_info_raw ) ? json_decode( wp_unslash( $cart_info_raw ), true ) : $cart_info_raw;
109 $traveler_data = is_string( $traveler_raw ) ? json_decode( wp_unslash( $traveler_raw ), true ) : $traveler_raw;
110
111 if ( ! is_array( $cart_info ) ) {
112 $cart_info = [];
113 }
114 if ( ! is_array( $traveler_data ) ) {
115 $traveler_data = [];
116 }
117
118 $trip_id = 0;
119 if ( isset( $cart_info['items'][0]['trip_id'] ) ) {
120 $trip_id = absint( $cart_info['items'][0]['trip_id'] );
121 }
122
123 $trip = $trip_id ? get_post( $trip_id ) : null;
124
125 $fname = '';
126 $lname = '';
127 $email = '';
128 if ( isset( $traveler_data[0] ) && is_array( $traveler_data[0] ) ) {
129 $fname = isset( $traveler_data[0]['fname'] ) ? sanitize_text_field( $traveler_data[0]['fname'] ) : '';
130 $lname = isset( $traveler_data[0]['lname'] ) ? sanitize_text_field( $traveler_data[0]['lname'] ) : '';
131 $email = isset( $traveler_data[0]['email'] ) ? sanitize_email( $traveler_data[0]['email'] ) : '';
132 }
133
134 $total_cost = isset( $cart_info['total'] ) ? floatval( $cart_info['total'] ) : 0;
135 $payment_status = isset( $cart_info['items'][0]['payment_status'] ) ? sanitize_text_field( $cart_info['items'][0]['payment_status'] ) : '';
136
137 if ( ! empty( $selected_options['trip_id'] ) && absint( $selected_options['trip_id'] ) !== $trip_id ) {
138 continue;
139 }
140
141 $bookings[] = [
142 'booking_id' => $booking_id,
143 'booking_date' => get_the_date( 'Y-m-d H:i:s' ),
144 'trip_id' => $trip_id,
145 'trip_name' => $trip ? $trip->post_title : '',
146 'customer_name' => trim( $fname . ' ' . $lname ),
147 'customer_email' => $email,
148 'total_cost' => $total_cost,
149 'booking_status' => $booking_status,
150 'payment_status' => $payment_status,
151 ];
152 }
153 wp_reset_postdata();
154 }
155
156 return [
157 'status' => 'success',
158 'data' => [
159 'bookings' => $bookings,
160 'count' => count( $bookings ),
161 ],
162 ];
163 }
164 }
165
166 ListBookings::get_instance();
167