PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.1
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.1
6.0.3 6.0.2 6.0.1 6.0.0 5.8.6 5.8.5 5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 5.7.9.2 5.7.9.1 5.7.8 5.7.9 5.7.6 5.7.7 5.7.5 5.7.4 5.7.3 5.7.2 5.7.1 trunk 5.6.0 5.6.1 All 34 releases
automatorwp / integrations / ameliabooking / includes / triggers / user-books-appointment.php

user-books-appointment.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 6.0.1, at integrations/ameliabooking/includes/triggers/user-books-appointment.php

154 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * User Books Appointment
4 *
5 * @package AutomatorWP\Integrations\Amelia\Triggers\User_Books_Appointment
6 * @author AutomatorWP <[email protected]>, Ruben Garcia <[email protected]>
7 * @since 1.0.0
8 */
9 // Exit if accessed directly
10 if( !defined( 'ABSPATH' ) ) exit;
11
12 class AutomatorWP_Amelia_User_Books_Appointment extends AutomatorWP_Integration_Trigger {
13
14 public $integration = 'ameliabooking';
15 public $trigger = 'ameliabooking_user_books_appointment';
16
17 /**
18 * Register the trigger
19 *
20 * @since 1.0.0
21 */
22 public function register() {
23
24 automatorwp_register_trigger( $this->trigger, array(
25 'integration' => $this->integration,
26 'label' => __( 'User books an appointment', 'automatorwp' ),
27 'select_option' => __( 'User books an <strong>appointment</strong>', 'automatorwp' ),
28 /* translators: %1$s: Number of times. */
29 'edit_label' => sprintf( __( 'User books an appointment %1$s time(s)', 'automatorwp' ), '{times}' ),
30 'log_label' => __( 'User books an appointment', 'automatorwp' ),
31 'action' => 'AmeliaBookingAddedBeforeNotify',
32 'function' => array( $this, 'listener' ),
33 'priority' => 10,
34 'accepted_args' => 2,
35 'options' => array(
36 'times' => automatorwp_utilities_times_option(),
37 ),
38 'tags' => array_merge(
39 automatorwp_ameliabooking_get_appointment_tags(),
40 automatorwp_ameliabooking_get_customer_tags(),
41 automatorwp_utilities_times_tag()
42 )
43 ) );
44
45 }
46
47 /**
48 * Trigger listener
49 *
50 * @since 1.0.0
51 *
52 * @param array $args Appointment data
53 */
54 public function listener( $args ) {
55
56 // Bail if can not find any data
57 if ( empty( $args ) ) {
58 return;
59 }
60
61 // Bail if the booking is not for an appointment
62 if ( $args['type'] !== 'appointment' ){
63 return;
64 }
65
66 $user_id = get_current_user_id( );
67
68 // Bail if user is not logged
69 if ( $user_id === 0 ){
70 return;
71 }
72
73 // Appointment tags
74 $appointment_id = absint( $args['appointment']['id'] );
75 $booking_start = $args['appointment']['bookingStart'];
76 $booking_end = $args['appointment']['bookingEnd'];
77 $status = $args['appointment']['status'];
78
79 // Customer tags
80 $customer_id = absint( $args['customer']['id'] );
81 $customer_first_name = $args['customer']['firstName'];
82 $customer_last_name = $args['customer']['lastName'];
83 $customer_email = $args['customer']['email'];
84 $customer_phone = $args['customer']['phone'];
85
86
87 // Trigger user appointment
88 automatorwp_trigger_event( array(
89 'trigger' => $this->trigger,
90 'user_id' => $user_id,
91 'appointment_id' => $appointment_id,
92 'appointment_booking_start' => $booking_start,
93 'appointment_booking_end' => $booking_end,
94 'appointment_status' => $status,
95 'customer_id' => $customer_id,
96 'customer_first_name' => $customer_first_name,
97 'customer_last_name' => $customer_last_name,
98 'customer_email' => $customer_email,
99 'customer_phone' => $customer_phone
100 ) );
101
102 }
103
104 /**
105 * Register the required hooks
106 *
107 * @since 1.0.0
108 */
109 public function hooks() {
110
111 // Log meta data
112 add_filter( 'automatorwp_user_completed_trigger_log_meta', array( $this, 'log_meta' ), 10, 6 );
113
114 parent::hooks();
115 }
116
117 /**
118 * Trigger custom log meta
119 *
120 * @since 1.0.0
121 *
122 * @param array $log_meta Log meta data
123 * @param stdClass $trigger The trigger object
124 * @param int $user_id The user ID
125 * @param array $event Event information
126 * @param array $trigger_options The trigger's stored options
127 * @param stdClass $automation The trigger's automation object
128 *
129 * @return array
130 */
131 function log_meta( $log_meta, $trigger, $user_id, $event, $trigger_options, $automation ) {
132
133 // Bail if action type don't match this action
134 if( $trigger->type !== $this->trigger ) {
135 return $log_meta;
136 }
137
138 $log_meta['appointment_id'] = ( isset( $event['appointment_id'] ) ? $event['appointment_id'] : '' );
139 $log_meta['appointment_booking_start'] = ( isset( $event['appointment_booking_start'] ) ? $event['appointment_booking_start'] : '' );
140 $log_meta['appointment_booking_end'] = ( isset( $event['appointment_booking_end'] ) ? $event['appointment_booking_end'] : '' );
141 $log_meta['appointment_status'] = ( isset( $event['appointment_status'] ) ? $event['appointment_status'] : '' );
142 $log_meta['customer_id'] = ( isset( $event['customer_id'] ) ? $event['customer_id'] : '' );
143 $log_meta['customer_first_name'] = ( isset( $event['customer_first_name'] ) ? $event['customer_first_name'] : '' );
144 $log_meta['customer_last_name'] = ( isset( $event['customer_last_name'] ) ? $event['customer_last_name'] : '' );
145 $log_meta['customer_email'] = ( isset( $event['customer_email'] ) ? $event['customer_email'] : '' );
146 $log_meta['customer_phone'] = ( isset( $event['customer_phone'] ) ? $event['customer_phone'] : '' );
147
148 return $log_meta;
149
150 }
151
152 }
153
154 new AutomatorWP_Amelia_User_Books_Appointment();