| 1 |
<?php |
| 2 |
|
| 3 |
namespace Booktics\Admin; |
| 4 |
|
| 5 |
use Booktics\Contracts\Hookable_Service_Contract; |
| 6 |
use Ens\Core\SDK; |
| 7 |
|
| 8 |
class Notification implements Hookable_Service_Contract { |
| 9 |
|
| 10 |
/** |
| 11 |
* Register notification |
| 12 |
* |
| 13 |
* @return void |
| 14 |
*/ |
| 15 |
public function register() { |
| 16 |
if ( class_exists( SDK::class ) ) { |
| 17 |
add_filter( 'notification_sdk_email_body', [ $this, 'wrap_email_body' ], 10, 1 ); |
| 18 |
|
| 19 |
SDK::get_instance() |
| 20 |
->setup( |
| 21 |
array( |
| 22 |
'plugin_name' => 'Booktics', |
| 23 |
'plugin_slug' => 'booktics', |
| 24 |
'general_prefix' => 'bt', |
| 25 |
'text_domain' => 'booktics', |
| 26 |
'admin_script_handler' => 'booktics-dashboard-scripts', |
| 27 |
'sub_menu_filter_hook' => 'booktics_menu', |
| 28 |
'sub_menu_details' => |
| 29 |
array( |
| 30 |
'id' => 'booktics-automation', |
| 31 |
'title' => __( 'Automation', 'booktics' ), |
| 32 |
'link' => '/automation', |
| 33 |
'capability' => apply_filters( 'booktics_menu_permission_automation_dashboard', 'manage_options' ), |
| 34 |
'position' => apply_filters( 'booktics_menu_position_automation', 11 ), |
| 35 |
), |
| 36 |
) |
| 37 |
) |
| 38 |
->init(); |
| 39 |
|
| 40 |
add_filter( |
| 41 |
'ens_bt_available_actions', function ( $actions ) { |
| 42 |
$actions = array( |
| 43 |
array( |
| 44 |
'trigger_label' => __( 'Order Created', 'booktics' ), |
| 45 |
'trigger_value' => 'order_created', |
| 46 |
'trigger_data' => array( |
| 47 |
array( |
| 48 |
'label' => __( 'Order No', 'booktics' ), |
| 49 |
'value' => 'order_no', |
| 50 |
'type' => 'string', |
| 51 |
), |
| 52 |
array( |
| 53 |
'label' => __( 'Order Status', 'booktics' ), |
| 54 |
'value' => 'order_status', |
| 55 |
'type' => 'string', |
| 56 |
), |
| 57 |
array( |
| 58 |
'label' => __( 'Order Date', 'booktics' ), |
| 59 |
'value' => 'order_date', |
| 60 |
'type' => 'date', |
| 61 |
), |
| 62 |
array( |
| 63 |
'label' => __( 'Service Name', 'booktics' ), |
| 64 |
'value' => 'service_name', |
| 65 |
'type' => 'string', |
| 66 |
), |
| 67 |
array( |
| 68 |
'label' => __( 'Team Name', 'booktics' ), |
| 69 |
'value' => 'team_name', |
| 70 |
'type' => 'string', |
| 71 |
), |
| 72 |
array( |
| 73 |
'label' => __( 'Appointment Date', 'booktics' ), |
| 74 |
'value' => 'appointment_date', |
| 75 |
'type' => 'date', |
| 76 |
), |
| 77 |
array( |
| 78 |
'label' => __( 'Appointment Status', 'booktics' ), |
| 79 |
'value' => 'appointment_status', |
| 80 |
'type' => 'string', |
| 81 |
), |
| 82 |
array( |
| 83 |
'label' => __( 'Start Time', 'booktics' ), |
| 84 |
'value' => 'start_time', |
| 85 |
'type' => 'string', |
| 86 |
), |
| 87 |
array( |
| 88 |
'label' => __( 'End Time', 'booktics' ), |
| 89 |
'value' => 'end_time', |
| 90 |
'type' => 'string', |
| 91 |
), |
| 92 |
array( |
| 93 |
'label' => __( 'Location Address', 'booktics' ), |
| 94 |
'value' => 'location_address', |
| 95 |
'type' => 'string', |
| 96 |
), |
| 97 |
array( |
| 98 |
'label' => __( 'Order Total', 'booktics' ), |
| 99 |
'value' => 'order_total', |
| 100 |
'type' => 'string', |
| 101 |
), |
| 102 |
array( |
| 103 |
'label' => __( 'Customer Name', 'booktics' ), |
| 104 |
'value' => 'customer_name', |
| 105 |
'type' => 'string', |
| 106 |
), |
| 107 |
array( |
| 108 |
'label' => __( 'Google meet Url', 'booktics' ), |
| 109 |
'value' => 'google_meet_url', |
| 110 |
'type' => 'string', |
| 111 |
), |
| 112 |
array( |
| 113 |
'label' => __( 'Appointment Reschedule Url', 'booktics' ), |
| 114 |
'value' => 'appointment_reschedule_url', |
| 115 |
'type' => 'string', |
| 116 |
), |
| 117 |
array( |
| 118 |
'label' => __( 'Appointment Cancel Url', 'booktics' ), |
| 119 |
'value' => 'appointment_cancel_url', |
| 120 |
'type' => 'string', |
| 121 |
), |
| 122 |
array( |
| 123 |
'label' => __( 'User Email', 'booktics' ), |
| 124 |
'value' => 'user_email', |
| 125 |
'type' => 'string', |
| 126 |
), |
| 127 |
), |
| 128 |
'delay_dependencies' => array( |
| 129 |
array( |
| 130 |
'label' => 'Order Date', |
| 131 |
'value' => 'order_date', |
| 132 |
), |
| 133 |
), |
| 134 |
'email_receivers' => array( |
| 135 |
array( |
| 136 |
'label' => __( 'User Email', 'booktics' ), |
| 137 |
'value' => 'user_email', |
| 138 |
), |
| 139 |
), |
| 140 |
), |
| 141 |
array( |
| 142 |
'trigger_label' => __( 'Appointment Scheduled', 'booktics' ), |
| 143 |
'trigger_value' => 'appointment_scheduled', |
| 144 |
'trigger_data' => array( |
| 145 |
array( |
| 146 |
'label' => __( 'Service Name', 'booktics' ), |
| 147 |
'value' => 'appointment_service', |
| 148 |
'type' => 'string', |
| 149 |
), |
| 150 |
array( |
| 151 |
'label' => __( 'Team Member Name', 'booktics' ), |
| 152 |
'value' => 'appointment_team_member', |
| 153 |
'type' => 'string', |
| 154 |
), |
| 155 |
array( |
| 156 |
'label' => __( 'Appointment Date', 'booktics' ), |
| 157 |
'value' => 'appointment_date', |
| 158 |
'type' => 'date', |
| 159 |
), |
| 160 |
array( |
| 161 |
'label' => __( 'Appointment Start Time', 'booktics' ), |
| 162 |
'value' => 'start_time', |
| 163 |
'type' => 'string', |
| 164 |
), |
| 165 |
array( |
| 166 |
'label' => __( 'Appointment Time', 'booktics' ), |
| 167 |
'value' => 'appointment_time', |
| 168 |
'type' => 'date', |
| 169 |
), |
| 170 |
array( |
| 171 |
'label' => __( 'Attendee Count', 'booktics' ), |
| 172 |
'value' => 'attendee_count', |
| 173 |
'type' => 'string', |
| 174 |
), |
| 175 |
array( |
| 176 |
'label' => __( 'Customer Name', 'booktics' ), |
| 177 |
'value' => 'customer_name', |
| 178 |
'type' => 'string', |
| 179 |
), |
| 180 |
array( |
| 181 |
'label' => __( 'User Email', 'booktics' ), |
| 182 |
'value' => 'user_email', |
| 183 |
'type' => 'string', |
| 184 |
), |
| 185 |
array( |
| 186 |
'label' => __( 'Google Meet URL', 'booktics' ), |
| 187 |
'value' => 'google_meet_url', |
| 188 |
'type' => 'string', |
| 189 |
), |
| 190 |
array( |
| 191 |
'label' => __( 'Extra Services', 'booktics' ), |
| 192 |
'value' => 'extra_services', |
| 193 |
'type' => 'string', |
| 194 |
), |
| 195 |
), |
| 196 |
'delay_dependencies' => array( |
| 197 |
array( |
| 198 |
'label' => __( 'Appointment Time', 'booktics' ), |
| 199 |
'value' => 'before_appointment_time', |
| 200 |
), |
| 201 |
), |
| 202 |
'email_receivers' => array( |
| 203 |
array( |
| 204 |
'label' => __( 'User Email', 'booktics' ), |
| 205 |
'value' => 'user_email', |
| 206 |
), |
| 207 |
array( |
| 208 |
'label' => __( 'Team Member Email', 'booktics' ), |
| 209 |
'value' => 'appointment_team_member_email', |
| 210 |
), |
| 211 |
), |
| 212 |
), |
| 213 |
array( |
| 214 |
'trigger_label' => __( 'Appointment Rescheduled', 'booktics' ), |
| 215 |
'trigger_value' => 'appointment_rescheduled', |
| 216 |
'trigger_data' => array( |
| 217 |
array( |
| 218 |
'label' => __( 'Service Name', 'booktics' ), |
| 219 |
'value' => 'appointment_service', |
| 220 |
'type' => 'string', |
| 221 |
), |
| 222 |
array( |
| 223 |
'label' => __( 'Date', 'booktics' ), |
| 224 |
'value' => 'date', |
| 225 |
'type' => 'date', |
| 226 |
), |
| 227 |
array( |
| 228 |
'label' => __( 'Team Member Name', 'booktics' ), |
| 229 |
'value' => 'appointment_team_member', |
| 230 |
'type' => 'string', |
| 231 |
), |
| 232 |
array( |
| 233 |
'label' => __( 'Start Time', 'booktics' ), |
| 234 |
'value' => 'start_time', |
| 235 |
'type' => 'string', |
| 236 |
), |
| 237 |
array( |
| 238 |
'label' => __( 'End Time', 'booktics' ), |
| 239 |
'value' => 'end_time', |
| 240 |
'type' => 'string', |
| 241 |
), |
| 242 |
array( |
| 243 |
'label' => __( 'Customer Name', 'booktics' ), |
| 244 |
'value' => 'customer_name', |
| 245 |
'type' => 'string', |
| 246 |
), |
| 247 |
array( |
| 248 |
'label' => __( 'User Email', 'booktics' ), |
| 249 |
'value' => 'user_email', |
| 250 |
'type' => 'string', |
| 251 |
), |
| 252 |
), |
| 253 |
'delay_dependencies' => array( |
| 254 |
array( |
| 255 |
'label' => __( 'Date', 'booktics' ), |
| 256 |
'value' => 'date', |
| 257 |
), |
| 258 |
), |
| 259 |
'email_receivers' => array( |
| 260 |
array( |
| 261 |
'label' => __( 'User Email', 'booktics' ), |
| 262 |
'value' => 'user_email', |
| 263 |
), |
| 264 |
array( |
| 265 |
'label' => __( 'Team Member Email', 'booktics' ), |
| 266 |
'value' => 'appointment_team_member_email', |
| 267 |
), |
| 268 |
), |
| 269 |
), |
| 270 |
array( |
| 271 |
'trigger_label' => __( 'Appointment Cancelled', 'booktics' ), |
| 272 |
'trigger_value' => 'appointment_cancelled', |
| 273 |
'trigger_data' => array( |
| 274 |
array( |
| 275 |
'label' => __( 'Service Name', 'booktics' ), |
| 276 |
'value' => 'appointment_service', |
| 277 |
'type' => 'string', |
| 278 |
), |
| 279 |
array( |
| 280 |
'label' => __( 'Date', 'booktics' ), |
| 281 |
'value' => 'date', |
| 282 |
'type' => 'date', |
| 283 |
), |
| 284 |
array( |
| 285 |
'label' => __( 'Team Member Name', 'booktics' ), |
| 286 |
'value' => 'appointment_team_member', |
| 287 |
'type' => 'string', |
| 288 |
), |
| 289 |
array( |
| 290 |
'label' => __( 'Start Time', 'booktics' ), |
| 291 |
'value' => 'start_time', |
| 292 |
'type' => 'string', |
| 293 |
), |
| 294 |
array( |
| 295 |
'label' => __( 'End Time', 'booktics' ), |
| 296 |
'value' => 'end_time', |
| 297 |
'type' => 'string', |
| 298 |
), |
| 299 |
array( |
| 300 |
'label' => __( 'Customer Name', 'booktics' ), |
| 301 |
'value' => 'customer_name', |
| 302 |
'type' => 'string', |
| 303 |
), |
| 304 |
array( |
| 305 |
'label' => __( 'User Email', 'booktics' ), |
| 306 |
'value' => 'user_email', |
| 307 |
'type' => 'string', |
| 308 |
), |
| 309 |
), |
| 310 |
'delay_dependencies' => array( |
| 311 |
array( |
| 312 |
'label' => __( 'Date', 'booktics' ), |
| 313 |
'value' => 'date', |
| 314 |
), |
| 315 |
), |
| 316 |
'email_receivers' => array( |
| 317 |
array( |
| 318 |
'label' => __( 'User Email', 'booktics' ), |
| 319 |
'value' => 'user_email', |
| 320 |
), |
| 321 |
array( |
| 322 |
'label' => __( 'Team Member Email', 'booktics' ), |
| 323 |
'value' => 'appointment_team_member_email', |
| 324 |
), |
| 325 |
), |
| 326 |
), |
| 327 |
array( |
| 328 |
'trigger_label' => __( 'Team Member Created', 'booktics' ), |
| 329 |
'trigger_value' => 'team_member_created', |
| 330 |
'trigger_data' => array( |
| 331 |
array( |
| 332 |
'label' => __( 'Team Member Name', 'booktics' ), |
| 333 |
'value' => 'team_member_name', |
| 334 |
'type' => 'string', |
| 335 |
), |
| 336 |
array( |
| 337 |
'label' => __( 'Team Member Email', 'booktics' ), |
| 338 |
'value' => 'team_member_email', |
| 339 |
'type' => 'string', |
| 340 |
), |
| 341 |
array( |
| 342 |
'label' => __( 'Password Reset URL', 'booktics' ), |
| 343 |
'value' => 'password_reset_url', |
| 344 |
'type' => 'string', |
| 345 |
), |
| 346 |
), |
| 347 |
'delay_dependencies' => array(), |
| 348 |
'email_receivers' => array( |
| 349 |
array( |
| 350 |
'label' => __( 'Team Member Email', 'booktics' ), |
| 351 |
'value' => 'team_member_email', |
| 352 |
), |
| 353 |
), |
| 354 |
), |
| 355 |
array( |
| 356 |
'trigger_label' => __( 'Customer Created', 'booktics' ), |
| 357 |
'trigger_value' => 'customer_created', |
| 358 |
'trigger_data' => array( |
| 359 |
array( |
| 360 |
'label' => __( 'Customer First Name', 'booktics' ), |
| 361 |
'value' => 'customer_first_name', |
| 362 |
'type' => 'string', |
| 363 |
), |
| 364 |
array( |
| 365 |
'label' => __( 'Customer Last Name', 'booktics' ), |
| 366 |
'value' => 'customer_last_name', |
| 367 |
'type' => 'string', |
| 368 |
), |
| 369 |
array( |
| 370 |
'label' => __( 'Customer Full Name', 'booktics' ), |
| 371 |
'value' => 'customer_full_name', |
| 372 |
'type' => 'string', |
| 373 |
), |
| 374 |
array( |
| 375 |
'label' => __( 'Customer Phone', 'booktics' ), |
| 376 |
'value' => 'customer_phone', |
| 377 |
'type' => 'string', |
| 378 |
), |
| 379 |
array( |
| 380 |
'label' => __( 'Customer User Name', 'booktics' ), |
| 381 |
'value' => 'customer_user_name', |
| 382 |
'type' => 'string', |
| 383 |
), |
| 384 |
array( |
| 385 |
'label' => __( 'Customer Email', 'booktics' ), |
| 386 |
'value' => 'customer_email', |
| 387 |
'type' => 'string', |
| 388 |
), |
| 389 |
array( |
| 390 |
'label' => __( 'Password Reset URL', 'booktics' ), |
| 391 |
'value' => 'password_reset_url', |
| 392 |
'type' => 'string', |
| 393 |
), |
| 394 |
), |
| 395 |
'delay_dependencies' => array(), |
| 396 |
'email_receivers' => array( |
| 397 |
array( |
| 398 |
'label' => __( 'Customer Email', 'booktics' ), |
| 399 |
'value' => 'customer_email', |
| 400 |
), |
| 401 |
), |
| 402 |
), |
| 403 |
); |
| 404 |
|
| 405 |
return $actions; |
| 406 |
} |
| 407 |
); |
| 408 |
} |
| 409 |
} |
| 410 |
|
| 411 |
/** |
| 412 |
* Wrap email body with custom template |
| 413 |
* |
| 414 |
* @param string $message |
| 415 |
* @return string |
| 416 |
*/ |
| 417 |
public function wrap_email_body( $message ) { |
| 418 |
|
| 419 |
$template_path = BOOKTICS_DIR . '/templates/email/team-member-create.html'; |
| 420 |
|
| 421 |
if ( ! file_exists( $template_path ) ) { |
| 422 |
return $message; |
| 423 |
} |
| 424 |
$template = file_get_contents( $template_path ); |
| 425 |
$default_image = get_template_directory_uri() . '/assets/images/placeholder.jpg'; |
| 426 |
$variables = array( |
| 427 |
'{{MESSAGE}}' => wp_kses_post( $message ), |
| 428 |
'{{COMPANY_NAME}}' => booktics_get_option( 'business_name', get_bloginfo( 'name' ) ), |
| 429 |
'{{COMPANY_LOGO}}' => booktics_get_option( 'business_logo', $default_image ), |
| 430 |
'{{COMPANY_ADDRESS}}' => booktics_get_option( 'business_address', 'California, USA' ), |
| 431 |
); |
| 432 |
|
| 433 |
return str_replace( array_keys( $variables ), array_values( $variables ), $template ); |
| 434 |
} |
| 435 |
} |
| 436 |
|