PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.3
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.3
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 / anonymous-books-appointment.php

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

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