PluginProbe ʕ •ᴥ•ʔ
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.6.11
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.6.11
5.6.11 5.6.10 5.6.9 5.6.8 5.6.7 5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / helpers / replacer_helper.php
latepoint / lib / helpers Last commit date
activities_helper.php 5 months ago admin_nudges_helper.php 1 month ago agent_helper.php 5 months ago analytics_helper.php 1 month ago auth_helper.php 2 months ago blocks_helper.php 2 months ago booking_helper.php 3 days ago bricks_helper.php 5 months ago bundles_helper.php 2 months ago calendar_helper.php 1 month ago carts_helper.php 5 months ago connector_helper.php 5 months ago csv_helper.php 5 months ago customer_helper.php 3 months ago customer_import_helper.php 3 months ago database_helper.php 1 month ago debug_helper.php 5 months ago defaults_helper.php 5 months ago elementor_helper.php 5 months ago email_helper.php 5 months ago encrypt_helper.php 5 months ago events_helper.php 5 months ago form_helper.php 3 days ago icalendar_helper.php 5 months ago image_helper.php 5 months ago invoices_helper.php 1 month ago license_helper.php 5 months ago location_helper.php 5 months ago marketing_systems_helper.php 5 months ago meeting_systems_helper.php 5 months ago menu_helper.php 2 months ago meta_helper.php 5 months ago migrations_helper.php 5 months ago money_helper.php 5 months ago notifications_helper.php 5 months ago nps_survey_helper.php 5 months ago order_intent_helper.php 4 months ago orders_helper.php 1 month ago otp_helper.php 5 months ago pages_helper.php 3 days ago params_helper.php 5 months ago payments_helper.php 1 month ago paypal_connect_helper.php 1 month ago plugin_version_update_helper.php 4 months ago price_breakdown_helper.php 5 months ago process_jobs_helper.php 1 month ago processes_helper.php 3 days ago razorpay_connect_helper.php 1 month ago replacer_helper.php 3 days ago resource_helper.php 2 months ago roles_helper.php 1 month ago router_helper.php 5 months ago service_helper.php 5 months ago sessions_helper.php 5 months ago settings_helper.php 2 months ago short_links_systems_helper.php 5 months ago shortcodes_helper.php 2 months ago sms_helper.php 5 months ago steps_helper.php 3 days ago stripe_connect_helper.php 2 months ago styles_helper.php 5 months ago support_topics_helper.php 5 months ago time_helper.php 3 days ago timeline_helper.php 4 months ago transaction_helper.php 3 months ago transaction_intent_helper.php 5 months ago util_helper.php 1 month ago version_specific_updates_helper.php 1 month ago whatsapp_helper.php 3 months ago work_periods_helper.php 3 days ago wp_datetime.php 5 months ago wp_user_helper.php 5 months ago
replacer_helper.php
654 lines
1 <?php
2
3 class OsReplacerHelper {
4
5 /**
6 * @param array $data_objects
7 * @param array $other_vars
8 *
9 * @return array
10 */
11 public static function generate_replacement_vars_from_data_objects( array $data_objects, array $other_vars = [] ): array {
12 $vars = [];
13 foreach ( $data_objects as $data_object ) {
14 switch ( $data_object['model'] ) {
15 case 'old_booking':
16 $old_booking = $data_object['model_ready'] ?? new OsBookingModel( $data_object['id'] );
17 $temp_vars = self::generate_replacement_vars_from_booking( $old_booking );
18 foreach ( $temp_vars as $key => $data ) {
19 $vars[ 'old_' . $key ] = $data;
20 }
21 break;
22 case 'booking':
23 $booking = $data_object['model_ready'] ?? new OsBookingModel( $data_object['id'] );
24 $vars = array_merge( $vars, self::generate_replacement_vars_from_booking( $booking ) );
25 break;
26 case 'old_order':
27 $old_order = $data_object['model_ready'] ?? new OsOrderModel( $data_object['id'] );
28 $temp_vars = self::generate_replacement_vars_from_order( $old_order );
29 foreach ( $temp_vars as $key => $data ) {
30 $vars[ 'old_' . $key ] = $data;
31 }
32 break;
33 case 'order':
34 $order = $data_object['model_ready'] ?? new OsOrderModel( $data_object['id'] );
35 $vars = array_merge( $vars, self::generate_replacement_vars_from_order( $order ) );
36 break;
37 case 'agent':
38 $agent = $data_object['model_ready'] ?? new OsAgentModel( $data_object['id'] );
39 $vars = array_merge( $vars, self::generate_replacement_vars_from_agent( $agent ) );
40 break;
41 case 'customer':
42 $customer = $data_object['model_ready'] ?? new OsCustomerModel( $data_object['id'] );
43 $vars = array_merge( $vars, self::generate_replacement_vars_from_customer( $customer ) );
44 break;
45 case 'transaction':
46 $transaction = $data_object['model_ready'] ?? new OsTransactionModel( $data_object['id'] );
47 $vars = array_merge( $vars, self::generate_replacement_vars_from_transaction( $transaction ) );
48 break;
49 case 'payment_request':
50 $payment_request = $data_object['model_ready'] ?? new OsPaymentRequestModel( $data_object['id'] );
51 $vars = array_merge( $vars, self::generate_replacement_vars_from_payment_request( $payment_request ) );
52 break;
53 }
54 }
55 if ( ! empty( $other_vars ) ) {
56 $vars = array_merge( $vars, $other_vars );
57 }
58
59 /**
60 * Returns an array of replacement variables, based on supplied data objects
61 *
62 * @param {array} $vars Current array of replacement variables
63 * @param {array} $data_objects Array of data objects to generate replacement variables for
64 * @param {array} $other_vars Array of additional (pre-prepared) replacement variables
65 *
66 * @returns {array} Filtered array of replacement variables
67 * @since 4.7.0
68 * @hook latepoint_prepare_replacement_vars_from_data_objects
69 *
70 */
71 return apply_filters( 'latepoint_prepare_replacement_vars_from_data_objects', $vars, $data_objects, $other_vars );
72 }
73
74 /**
75 *
76 * Prepares an array of variables to be used in replacer method from a customer object
77 *
78 * @param OsCustomerModel $customer
79 * @param array $other_vars
80 *
81 * @return array
82 */
83 public static function generate_replacement_vars_from_customer( OsCustomerModel $customer, array $other_vars = [] ): array {
84 $vars = [];
85 $vars['customer'] = $customer;
86 if ( ! empty( $other_vars ) ) {
87 $vars = array_merge( $vars, $other_vars );
88 }
89
90 /**
91 * Returns an array of replacement variables, based on supplied <code>OsCustomerModel</code> instance
92 *
93 * @param {array} $vars Current array of replacement variables
94 * @param {OsCustomerModel} $customer Instance of <code>OsCustomerModel</code> to generate replacement variables for
95 * @param {array} $other_vars Array of additional (pre-prepared) replacement variables
96 *
97 * @returns {array} Filtered array of replacement variables
98 * @since 4.7.0
99 * @hook latepoint_prepare_replacement_vars_from_customer
100 *
101 */
102 return apply_filters( 'latepoint_prepare_replacement_vars_from_customer', $vars, $customer, $other_vars );
103 }
104
105
106 /**
107 *
108 * Prepares an array of variables to be used in replacer method from a transaction object
109 *
110 * @param OsTransactionModel $transaction
111 * @param array $other_vars
112 *
113 * @return array
114 */
115 public static function generate_replacement_vars_from_transaction( OsTransactionModel $transaction, array $other_vars = [] ): array {
116 $vars = [];
117 $vars['transaction'] = $transaction;
118 $vars['order'] = $transaction->order;
119 $vars['customer'] = $transaction->order->customer;
120 if ( ! empty( $other_vars ) ) {
121 $vars = array_merge( $vars, $other_vars );
122 }
123
124 return apply_filters( 'latepoint_prepare_replacement_vars_from_transaction', $vars, $transaction, $other_vars );
125 }
126
127
128 /**
129 *
130 * Prepares an array of variables to be used in replacer method from a payment_request object
131 *
132 * @param OsPaymentRequestModel $payment_request
133 * @param array $other_vars
134 *
135 * @return array
136 */
137 public static function generate_replacement_vars_from_payment_request( OsPaymentRequestModel $payment_request, array $other_vars = [] ): array {
138 $vars = [];
139 $vars['payment_request'] = $payment_request;
140 $vars['order'] = $payment_request->get_order();
141 $vars['customer'] = $payment_request->get_customer();
142 if ( ! empty( $other_vars ) ) {
143 $vars = array_merge( $vars, $other_vars );
144 }
145
146 return apply_filters( 'latepoint_prepare_replacement_vars_from_payment_request', $vars, $payment_request, $other_vars );
147 }
148
149
150 /**
151 *
152 * Prepares an array of variables to be used in replacer method from an agent object
153 *
154 * @param OsAgentModel $agent
155 * @param array $other_vars
156 *
157 * @return array
158 */
159 public static function generate_replacement_vars_from_agent( OsAgentModel $agent, array $other_vars = [] ): array {
160 $vars = [];
161 $vars['agent'] = $agent;
162 if ( ! empty( $other_vars ) ) {
163 $vars = array_merge( $vars, $other_vars );
164 }
165
166 /**
167 * Returns an array of replacement variables, based on supplied <code>OsAgentModel</code> instance
168 *
169 * @param {array} $vars Current array of replacement variables
170 * @param {OsAgentModel} $agent Instance of <code>OsAgentModel</code> to generate replacement variables for
171 * @param {array} $other_vars Array of additional (pre-prepared) replacement variables
172 *
173 * @returns {array} Filtered array of replacement variables
174 * @since 4.7.0
175 * @hook latepoint_prepare_replacement_vars_from_agent
176 *
177 */
178 return apply_filters( 'latepoint_prepare_replacement_vars_from_agent', $vars, $agent, $other_vars );
179 }
180
181 /**
182 *
183 * Prepares an array of variables to be used in replacer method from a order object
184 *
185 * @param OsOrderModel $order
186 * @param array $other_vars
187 *
188 * @return array
189 */
190 public static function generate_replacement_vars_from_order( OsOrderModel $order, array $other_vars = [] ): array {
191 $vars = [];
192 $vars['order'] = $order;
193 $vars['customer'] = $order->get_customer();
194 if ( ! empty( $other_vars ) ) {
195 $vars = array_merge( $vars, $other_vars );
196 }
197
198 /**
199 * Returns an array of replacement variables, based on supplied <code>OsOrderModel</code> instance
200 *
201 * @param {array} $vars Current array of replacement variables
202 * @param {OsOrderModel} $order Instance of <code>OsOrderModel</code> to generate replacement variables for
203 * @param {array} $other_vars Array of additional (pre-prepared) replacement variables
204 *
205 * @returns {array} Filtered array of replacement variables
206 * @since 4.7.0
207 * @hook latepoint_prepare_replacement_vars_from_order
208 *
209 */
210 return apply_filters( 'latepoint_prepare_replacement_vars_from_order', $vars, $order, $other_vars );
211 }
212
213 /**
214 *
215 * Prepares an array of variables to be used in replacer method from a booking object
216 *
217 * @param OsBookingModel $booking
218 * @param array $other_vars
219 *
220 * @return array
221 */
222 public static function generate_replacement_vars_from_booking( OsBookingModel $booking, array $other_vars = [] ): array {
223 $vars = [];
224 $vars['booking'] = $booking;
225 $vars['customer'] = $booking->customer;
226 $vars['agent'] = $booking->agent;
227 $vars['order'] = $booking->order;
228 if ( ! empty( $other_vars ) ) {
229 $vars = array_merge( $vars, $other_vars );
230 }
231
232 /**
233 * Returns an array of replacement variables, based on supplied <code>OsBookingModel</code> instance
234 *
235 * @param {array} $vars Current array of replacement variables
236 * @param {OsBookingModel} $customer Instance of <code>OsBookingModel</code> to generate replacement variables for
237 * @param {array} $other_vars Array of additional (pre-prepared) replacement variables
238 *
239 * @returns {array} Filtered array of replacement variables
240 * @since 4.7.0
241 * @hook latepoint_prepare_replacement_vars_from_booking
242 *
243 */
244 return apply_filters( 'latepoint_prepare_replacement_vars_from_booking', $vars, $booking, $other_vars );
245 }
246
247 public static function stylize_vars( $html ) {
248 $html = self::replace_business_vars( $html );
249 $html = str_replace( '{{', '<span class="os-template-var">{{', $html );
250 $html = str_replace( '}}', '}}</span>', $html );
251 // fix issue when the template variable is inside of an href="{{var}}", we don't want to replace those
252 $html = str_replace( '"<span class="os-template-var">{{', '"{{', $html );
253 $html = str_replace( '}}</span>"', '}}"', $html );
254
255 return $html;
256 }
257
258 public static function replace_customer_vars( $text, $customer ) {
259 $needles = array(
260 '{{customer_full_name}}',
261 '{{customer_first_name}}',
262 '{{customer_last_name}}',
263 '{{customer_email}}',
264 '{{customer_phone}}',
265 '{{customer_notes}}',
266 '{{customer_admin_notes}}',
267 );
268 $replacements = array(
269 $customer->full_name,
270 $customer->first_name,
271 $customer->last_name,
272 $customer->email,
273 $customer->phone,
274 $customer->notes,
275 $customer->admin_notes,
276 );
277 $original_text = $text;
278 $text = str_replace( $needles, $replacements, $text );
279
280 /**
281 * Returns a string with variables replaced, based on supplied <code>OsCustomerModel</code> instance
282 *
283 * @param {string} $text Current string with variables replaced
284 * @param {OsCustomerModel} $customer Instance of <code>OsCustomerModel</code> to replace variables for
285 * @param {string} $original_text Original string before any customer-related replacements were performed
286 * @param {array} $needles Array of default needles to be replaced
287 * @param {array} $replacements Array of default replacement values to supplant each needle
288 *
289 * @returns {string} Filtered string with variables replaced
290 * @since 4.3.2
291 * @hook latepoint_replace_customer_vars
292 *
293 */
294 return apply_filters( 'latepoint_replace_customer_vars', $text, $customer, $original_text, $needles, $replacements );
295 }
296
297
298 public static function replace_payment_request_vars( string $text, OsPaymentRequestModel $payment_request ) {
299 $needles = [
300 '{{payment_request_amount}}',
301 '{{payment_request_due_at}}',
302 '{{payment_request_portion}}',
303 '{{payment_request_pay_url}}',
304 ];
305 $replacements = [
306 OsMoneyHelper::format_price( $payment_request->charge_amount, true, false ),
307 $payment_request->get_readable_due_at(),
308 $payment_request->portion,
309 $payment_request->get_invoice()->get_pay_url(),
310 ];
311 $text = str_replace( $needles, $replacements, $text );
312
313 /**
314 * Returns a string with payment request variables replaced, based on supplied <code>OsPaymentRequestModel</code> instance
315 *
316 * @param {string} $text Current string with variables replaced
317 * @param {OsPaymentRequestModel} $payment_request Instance of <code>OsPaymentRequestModel</code> to replace variables for
318 *
319 * @returns {string} Filtered string with variables replaced
320 * @since 5.1.0
321 * @hook latepoint_replace_payment_request_vars
322 *
323 */
324 $text = apply_filters( 'latepoint_replace_payment_request_vars', $text, $payment_request );
325
326 return $text;
327 }
328
329 public static function replace_transaction_vars( $text, $transaction ) {
330 $needles = [
331 '{{transaction_token}}',
332 '{{transaction_amount}}',
333 '{{transaction_processor}}',
334 '{{transaction_payment_method}}',
335 '{{transaction_kind}}',
336 '{{transaction_status}}',
337 '{{transaction_notes}}',
338 '{{transaction_payment_portion}}',
339 ];
340 $replacements = [
341 $transaction->token,
342 OsMoneyHelper::format_price( $transaction->amount ),
343 $transaction->processor,
344 $transaction->payment_method,
345 $transaction->kind,
346 $transaction->status,
347 $transaction->notes,
348 $transaction->payment_portion,
349 ];
350 $text = str_replace( $needles, $replacements, $text );
351
352 /**
353 * Returns a string with transaction variables replaced, based on supplied <code>OsTransactionModel</code> instance
354 *
355 * @param {string} $text Current string with variables replaced
356 * @param {OsTransactionModel} $transaction Instance of <code>OsTransactionModel</code> to replace variables for
357 *
358 * @returns {string} Filtered string with variables replaced
359 * @since 5.1.0
360 * @hook latepoint_replace_transaction_vars
361 *
362 */
363 $text = apply_filters( 'latepoint_replace_transaction_vars', $text, $transaction );
364
365 return $text;
366 }
367
368 public static function replace_agent_vars( $text, $agent ) {
369 $needles = array(
370 '{{agent_first_name}}',
371 '{{agent_last_name}}',
372 '{{agent_full_name}}',
373 '{{agent_display_name}}',
374 '{{agent_email}}',
375 '{{agent_phone}}',
376 '{{agent_additional_emails}}',
377 '{{agent_additional_phones}}',
378 );
379 $replacements = array(
380 $agent->first_name,
381 $agent->last_name,
382 $agent->full_name,
383 $agent->display_name,
384 $agent->email,
385 $agent->phone,
386 $agent->extra_emails,
387 $agent->extra_phones,
388 );
389 $original_text = $text;
390 $text = str_replace( $needles, $replacements, $text );
391
392 /**
393 * Returns a string with variables replaced, based on supplied <code>OsAgentModel</code> instance
394 *
395 * @param {string} $text Current string with variables replaced
396 * @param {OsAgentModel} $agent Instance of <code>OsAgentModel</code> to replace variables for
397 * @param {string} $original_text Original string before any agent-related replacements were performed
398 * @param {array} $needles Array of default needles to be replaced
399 * @param {array} $replacements Array of default replacement values to supplant each needle
400 *
401 * @returns {string} Filtered string with variables replaced
402 * @since 4.7.0
403 * @hook latepoint_replace_agent_vars
404 *
405 */
406 return apply_filters( 'latepoint_replace_agent_vars', $text, $agent, $original_text, $needles, $replacements );
407 }
408
409 public static function replace_business_vars( $text ) {
410 $needles = [
411 '{{business_logo_image}}',
412 '{{business_logo_url}}',
413 '{{business_address}}',
414 '{{business_phone}}',
415 '{{business_name}}',
416 '{{customer_dashboard_url}}',
417 ];
418 $replacements = [
419 OsSettingsHelper::get_business_logo_image(),
420 OsSettingsHelper::get_business_logo_url(),
421 OsSettingsHelper::get_settings_value( 'business_address', '' ),
422 OsSettingsHelper::get_settings_value( 'business_phone', '' ),
423 OsSettingsHelper::get_settings_value( 'business_name', '' ),
424 OsSettingsHelper::get_customer_dashboard_url(),
425 ];
426 $original_text = $text;
427 $text = str_replace( $needles, $replacements, $text );
428
429 /**
430 * Returns a string with business-related variables replaced
431 *
432 * @param {string} $text Current string with variables replaced
433 * @param {string} $original_text Original string before any business-related replacements were performed
434 * @param {array} $needles Array of default needles to be replaced
435 * @param {array} $replacements Array of default replacement values to supplant each needle
436 *
437 * @returns {string} Filtered string with variables replaced
438 * @since 4.7.0
439 * @hook latepoint_replace_business_vars
440 *
441 */
442 return apply_filters( 'latepoint_replace_business_vars', $text, $original_text, $needles, $replacements );
443 }
444
445 public static function replace_tracking_vars( $text, $order ) {
446 $needles = [
447 '{{order_id}}',
448 '{{customer_id}}',
449 '{{order_total}}',
450 '{{service_ids}}',
451 '{{agent_ids}}',
452 '{{bundle_ids}}',
453 '{{location_ids}}',
454 ];
455 $replacements = [
456 $order->id,
457 $order->customer_id,
458 OsMoneyHelper::format_price( $order->get_total() ),
459 OsOrdersHelper::extract_property_by_name( $order, 'service_ids' ),
460 OsOrdersHelper::extract_property_by_name( $order, 'agent_ids' ),
461 OsOrdersHelper::extract_property_by_name( $order, 'bundle_ids' ),
462 OsOrdersHelper::extract_property_by_name( $order, 'location_ids' ),
463 ];
464 $original_text = $text;
465 $text = str_replace( $needles, $replacements, $text );
466
467 /**
468 * Returns a string with tracking-related variables replaced, based on supplied OsOrderModel instance
469 *
470 * @param {string} $text Current string with variables replaced
471 * @param {OsBookingModel} $order Instance of OsOrderModel to replace variables for
472 * @param {string} $original_text Original string before any tracking-related replacements were performed
473 * @param {array} $needles Array of default needles to be replaced
474 * @param {array} $replacements Array of default replacement values to supplant each needle
475 *
476 * @returns {string} Filtered string with variables replaced
477 * @since 5.0.7
478 * @hook latepoint_replace_tracking_vars
479 *
480 */
481 return apply_filters( 'latepoint_replace_tracking_vars', $text, $order, $original_text, $needles, $replacements );
482 }
483
484
485 public static function replace_order_vars( $text, OsOrderModel $order ) {
486 $needles = [
487 '{{order_id}}',
488 '{{order_confirmation_code}}',
489 '{{order_coupon_code}}',
490 '{{order_tax_total}}',
491 '{{order_coupon_discount}}',
492 '{{order_subtotal}}',
493 '{{order_total}}',
494 '{{order_status}}',
495 '{{order_fulfillment_status}}',
496 '{{order_payment_status}}',
497 '{{order_payments_total}}',
498 '{{order_balance_due_total}}',
499 '{{order_transactions_breakdown}}',
500 '{{order_summary_breakdown}}',
501 '{{order_items}}',
502 '{{order_agents_emails}}',
503 '{{order_agents_full_names}}',
504 '{{manage_order_url_agent}}',
505 '{{manage_order_url_customer}}',
506 ];
507 $replacements = [
508 $order->id,
509 $order->confirmation_code,
510 $order->coupon_code,
511 $order->tax_total,
512 OsMoneyHelper::format_price( $order->coupon_discount ),
513 OsMoneyHelper::format_price( $order->get_subtotal() ),
514 OsMoneyHelper::format_price( $order->get_total() ),
515 OsOrdersHelper::get_nice_order_status_name( $order->status ),
516 OsOrdersHelper::get_nice_order_fulfillment_status_name( $order->fulfillment_status ),
517 OsOrdersHelper::get_nice_order_payment_status_name( $order->payment_status ),
518 OsMoneyHelper::format_price( $order->get_total_amount_paid_from_transactions() ),
519 OsMoneyHelper::format_price( $order->get_total_balance_due() ),
520 OsOrdersHelper::generate_transactions_breakdown_html( $order ),
521 OsOrdersHelper::generate_summary_breakdown_html( $order ),
522 OsOrdersHelper::generate_order_items_html( $order ),
523 OsOrdersHelper::extract_agent_emails( $order ),
524 OsOrdersHelper::extract_agent_full_names( $order ),
525 OsOrdersHelper::generate_direct_manage_order_url( $order, 'agent' ),
526 OsOrdersHelper::generate_direct_manage_order_url( $order, 'customer' ),
527 ];
528 $original_text = $text;
529 $text = str_replace( $needles, $replacements, $text );
530
531 /**
532 * Returns a string with variables replaced, based on supplied <code>OsOrderModel</code> instance
533 *
534 * @param {string} $text Current string with variables replaced
535 * @param {OsOrderModel} $order Instance of <code>OsOrderModel</code> to replace variables for
536 * @param {string} $original_text Original string before any order-related replacements were performed
537 * @param {array} $needles Array of default needles to be replaced
538 * @param {array} $replacements Array of default replacement values to supplant each needle
539 *
540 * @returns {string} Filtered string with variables replaced
541 * @since 5.0.0
542 * @hook latepoint_replace_order_vars
543 *
544 */
545 return apply_filters( 'latepoint_replace_order_vars', $text, $order, $original_text, $needles, $replacements );
546 }
547
548 public static function replace_booking_vars( $text, OsBookingModel $booking ) {
549 $needles = [
550 '{{booking_id}}',
551 '{{booking_code}}',
552 '{{booking_price}}',
553 '{{service_name}}',
554 '{{service_category}}',
555 '{{start_date}}',
556 '{{start_time}}',
557 '{{end_time}}',
558 '{{booking_status}}',
559 '{{location_name}}',
560 '{{location_full_address}}',
561 '{{booking_duration}}',
562 '{{manage_booking_url_agent}}',
563 '{{manage_booking_url_customer}}',
564 ];
565 $total_duration = ( $booking->get_total_duration() > 0 ) ? $booking->get_total_duration() . ' ' . __( 'minutes', 'latepoint' ) : __( 'n/a', 'latepoint' );
566 $order_item = new OsOrderItemModel( $booking->order_item_id );
567 $replacements = [
568 $booking->id,
569 $booking->booking_code,
570 OsMoneyHelper::format_price( $order_item->get_total() ),
571 $booking->service->name,
572 $booking->service->category_name,
573 $booking->format_start_date_and_time( OsSettingsHelper::get_readable_date_format(), false ),
574 $booking->nice_start_time,
575 $booking->nice_end_time,
576 $booking->nice_status,
577 $booking->location->name,
578 $booking->location->full_address,
579 $total_duration,
580 OsBookingHelper::generate_direct_manage_booking_url( $booking, 'agent' ),
581 OsBookingHelper::generate_direct_manage_booking_url( $booking, 'customer' ),
582 ];
583 $original_text = $text;
584 $text = str_replace( $needles, $replacements, $text );
585
586 /**
587 * Returns a string with variables replaced, based on supplied <code>OsBookingModel</code> instance
588 *
589 * @param {string} $text Current string with variables replaced
590 * @param {OsBookingModel} $booking Instance of <code>OsBookingModel</code> to replace variables for
591 * @param {string} $original_text Original string before any booking-related replacements were performed
592 * @param {array} $needles Array of default needles to be replaced
593 * @param {array} $replacements Array of default replacement values to supplant each needle
594 *
595 * @returns {string} Filtered string with variables replaced
596 * @since 3.0.4
597 * @hook latepoint_replace_booking_vars
598 *
599 */
600 return apply_filters( 'latepoint_replace_booking_vars', $text, $booking, $original_text, $needles, $replacements );
601 }
602
603 public static function replace_other_vars( $text, $other_vars ): string {
604 if ( isset( $other_vars['old_status'] ) ) {
605 $text = str_replace( '{{booking_old_status}}', $other_vars['old_status'], $text );
606 }
607 if ( isset( $other_vars['token'] ) ) {
608 $text = str_replace( '{{token}}', $other_vars['token'], $text );
609 }
610
611 return $text;
612 }
613
614 public static function replace_all_vars( string $text, array $vars ): string {
615 $original_text = $text;
616 if ( isset( $vars['order'] ) ) {
617 $text = self::replace_order_vars( $text, $vars['order'] );
618 }
619 if ( isset( $vars['booking'] ) ) {
620 $text = self::replace_booking_vars( $text, $vars['booking'] );
621 }
622 if ( isset( $vars['customer'] ) ) {
623 $text = self::replace_customer_vars( $text, $vars['customer'] );
624 }
625 if ( isset( $vars['agent'] ) ) {
626 $text = self::replace_agent_vars( $text, $vars['agent'] );
627 }
628 if ( isset( $vars['transaction'] ) ) {
629 $text = self::replace_transaction_vars( $text, $vars['transaction'] );
630 }
631 if ( isset( $vars['payment_request'] ) ) {
632 $text = self::replace_payment_request_vars( $text, $vars['payment_request'] );
633 }
634 if ( isset( $vars['other_vars'] ) ) {
635 $text = self::replace_other_vars( $text, $vars['other_vars'] );
636 }
637 $text = self::replace_business_vars( $text );
638
639 /**
640 * Returns a string with needles replaced, based on supplied variables
641 *
642 * @param {string} $text Current string with variables replaced
643 * @param {array} $vars Array of variables to perform replacements for
644 * @param {string} $original_text Original string before any replacements were performed
645 *
646 * @returns {string} Filtered string with variables replaced
647 * @since 4.3.2
648 * @hook latepoint_replace_all_vars_in_template
649 *
650 */
651 return apply_filters( 'latepoint_replace_all_vars_in_template', $text, $vars, $original_text );
652 }
653 }
654