PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.2.11
LatePoint – Calendar Booking Plugin for Appointments and Events v5.2.11
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 3 months ago agent_helper.php 3 months ago analytics_helper.php 4 months ago auth_helper.php 3 months ago blocks_helper.php 3 months ago booking_helper.php 3 months ago bricks_helper.php 3 months ago bundles_helper.php 3 months ago calendar_helper.php 3 months ago carts_helper.php 3 months ago connector_helper.php 3 months ago csv_helper.php 3 months ago customer_helper.php 3 months ago customer_import_helper.php 3 months ago database_helper.php 3 months ago debug_helper.php 3 months ago defaults_helper.php 3 months ago elementor_helper.php 3 months ago email_helper.php 3 months ago encrypt_helper.php 3 months ago events_helper.php 3 months ago form_helper.php 3 months ago icalendar_helper.php 3 months ago image_helper.php 3 months ago invoices_helper.php 3 months ago license_helper.php 3 months ago location_helper.php 3 months ago marketing_systems_helper.php 3 months ago meeting_systems_helper.php 3 months ago menu_helper.php 3 months ago meta_helper.php 3 months ago migrations_helper.php 3 months ago money_helper.php 3 months ago notifications_helper.php 3 months ago nps_survey_helper.php 3 months ago order_intent_helper.php 3 months ago orders_helper.php 3 months ago otp_helper.php 3 months ago pages_helper.php 3 months ago params_helper.php 3 months ago payments_helper.php 3 months ago price_breakdown_helper.php 3 months ago process_jobs_helper.php 3 months ago processes_helper.php 3 months ago replacer_helper.php 3 months ago resource_helper.php 3 months ago roles_helper.php 3 months ago router_helper.php 3 months ago service_helper.php 3 months ago sessions_helper.php 3 months ago settings_helper.php 3 months ago short_links_systems_helper.php 3 months ago shortcodes_helper.php 3 months ago sms_helper.php 3 months ago steps_helper.php 3 months ago stripe_connect_helper.php 3 months ago styles_helper.php 3 months ago support_topics_helper.php 3 months ago time_helper.php 3 months ago timeline_helper.php 3 months ago transaction_helper.php 3 months ago transaction_intent_helper.php 3 months ago util_helper.php 3 months ago version_specific_updates_helper.php 3 months ago whatsapp_helper.php 3 months ago work_periods_helper.php 3 months ago wp_datetime.php 3 months ago wp_user_helper.php 3 months ago
replacer_helper.php
652 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 );
267 $replacements = array(
268 $customer->full_name,
269 $customer->first_name,
270 $customer->last_name,
271 $customer->email,
272 $customer->phone,
273 $customer->notes,
274 );
275 $original_text = $text;
276 $text = str_replace( $needles, $replacements, $text );
277
278 /**
279 * Returns a string with variables replaced, based on supplied <code>OsCustomerModel</code> instance
280 *
281 * @param {string} $text Current string with variables replaced
282 * @param {OsCustomerModel} $customer Instance of <code>OsCustomerModel</code> to replace variables for
283 * @param {string} $original_text Original string before any customer-related replacements were performed
284 * @param {array} $needles Array of default needles to be replaced
285 * @param {array} $replacements Array of default replacement values to supplant each needle
286 *
287 * @returns {string} Filtered string with variables replaced
288 * @since 4.3.2
289 * @hook latepoint_replace_customer_vars
290 *
291 */
292 return apply_filters( 'latepoint_replace_customer_vars', $text, $customer, $original_text, $needles, $replacements );
293 }
294
295
296 public static function replace_payment_request_vars( string $text, OsPaymentRequestModel $payment_request ) {
297 $needles = [
298 '{{payment_request_amount}}',
299 '{{payment_request_due_at}}',
300 '{{payment_request_portion}}',
301 '{{payment_request_pay_url}}',
302 ];
303 $replacements = [
304 OsMoneyHelper::format_price( $payment_request->charge_amount, true, false ),
305 $payment_request->get_readable_due_at(),
306 $payment_request->portion,
307 $payment_request->get_invoice()->get_pay_url(),
308 ];
309 $text = str_replace( $needles, $replacements, $text );
310
311 /**
312 * Returns a string with payment request variables replaced, based on supplied <code>OsPaymentRequestModel</code> instance
313 *
314 * @param {string} $text Current string with variables replaced
315 * @param {OsPaymentRequestModel} $payment_request Instance of <code>OsPaymentRequestModel</code> to replace variables for
316 *
317 * @returns {string} Filtered string with variables replaced
318 * @since 5.1.0
319 * @hook latepoint_replace_payment_request_vars
320 *
321 */
322 $text = apply_filters( 'latepoint_replace_payment_request_vars', $text, $payment_request );
323
324 return $text;
325 }
326
327 public static function replace_transaction_vars( $text, $transaction ) {
328 $needles = [
329 '{{transaction_token}}',
330 '{{transaction_amount}}',
331 '{{transaction_processor}}',
332 '{{transaction_payment_method}}',
333 '{{transaction_kind}}',
334 '{{transaction_status}}',
335 '{{transaction_notes}}',
336 '{{transaction_payment_portion}}',
337 ];
338 $replacements = [
339 $transaction->token,
340 OsMoneyHelper::format_price( $transaction->amount ),
341 $transaction->processor,
342 $transaction->payment_method,
343 $transaction->kind,
344 $transaction->status,
345 $transaction->notes,
346 $transaction->payment_portion,
347 ];
348 $text = str_replace( $needles, $replacements, $text );
349
350 /**
351 * Returns a string with transaction variables replaced, based on supplied <code>OsTransactionModel</code> instance
352 *
353 * @param {string} $text Current string with variables replaced
354 * @param {OsTransactionModel} $transaction Instance of <code>OsTransactionModel</code> to replace variables for
355 *
356 * @returns {string} Filtered string with variables replaced
357 * @since 5.1.0
358 * @hook latepoint_replace_transaction_vars
359 *
360 */
361 $text = apply_filters( 'latepoint_replace_transaction_vars', $text, $transaction );
362
363 return $text;
364 }
365
366 public static function replace_agent_vars( $text, $agent ) {
367 $needles = array(
368 '{{agent_first_name}}',
369 '{{agent_last_name}}',
370 '{{agent_full_name}}',
371 '{{agent_display_name}}',
372 '{{agent_email}}',
373 '{{agent_phone}}',
374 '{{agent_additional_emails}}',
375 '{{agent_additional_phones}}',
376 );
377 $replacements = array(
378 $agent->first_name,
379 $agent->last_name,
380 $agent->full_name,
381 $agent->display_name,
382 $agent->email,
383 $agent->phone,
384 $agent->extra_emails,
385 $agent->extra_phones,
386 );
387 $original_text = $text;
388 $text = str_replace( $needles, $replacements, $text );
389
390 /**
391 * Returns a string with variables replaced, based on supplied <code>OsAgentModel</code> instance
392 *
393 * @param {string} $text Current string with variables replaced
394 * @param {OsAgentModel} $agent Instance of <code>OsAgentModel</code> to replace variables for
395 * @param {string} $original_text Original string before any agent-related replacements were performed
396 * @param {array} $needles Array of default needles to be replaced
397 * @param {array} $replacements Array of default replacement values to supplant each needle
398 *
399 * @returns {string} Filtered string with variables replaced
400 * @since 4.7.0
401 * @hook latepoint_replace_agent_vars
402 *
403 */
404 return apply_filters( 'latepoint_replace_agent_vars', $text, $agent, $original_text, $needles, $replacements );
405 }
406
407 public static function replace_business_vars( $text ) {
408 $needles = [
409 '{{business_logo_image}}',
410 '{{business_logo_url}}',
411 '{{business_address}}',
412 '{{business_phone}}',
413 '{{business_name}}',
414 '{{customer_dashboard_url}}',
415 ];
416 $replacements = [
417 OsSettingsHelper::get_business_logo_image(),
418 OsSettingsHelper::get_business_logo_url(),
419 OsSettingsHelper::get_settings_value( 'business_address', '' ),
420 OsSettingsHelper::get_settings_value( 'business_phone', '' ),
421 OsSettingsHelper::get_settings_value( 'business_name', '' ),
422 OsSettingsHelper::get_customer_dashboard_url(),
423 ];
424 $original_text = $text;
425 $text = str_replace( $needles, $replacements, $text );
426
427 /**
428 * Returns a string with business-related variables replaced
429 *
430 * @param {string} $text Current string with variables replaced
431 * @param {string} $original_text Original string before any business-related replacements were performed
432 * @param {array} $needles Array of default needles to be replaced
433 * @param {array} $replacements Array of default replacement values to supplant each needle
434 *
435 * @returns {string} Filtered string with variables replaced
436 * @since 4.7.0
437 * @hook latepoint_replace_business_vars
438 *
439 */
440 return apply_filters( 'latepoint_replace_business_vars', $text, $original_text, $needles, $replacements );
441 }
442
443 public static function replace_tracking_vars( $text, $order ) {
444 $needles = [
445 '{{order_id}}',
446 '{{customer_id}}',
447 '{{order_total}}',
448 '{{service_ids}}',
449 '{{agent_ids}}',
450 '{{bundle_ids}}',
451 '{{location_ids}}',
452 ];
453 $replacements = [
454 $order->id,
455 $order->customer_id,
456 OsMoneyHelper::format_price( $order->get_total() ),
457 OsOrdersHelper::extract_property_by_name( $order, 'service_ids' ),
458 OsOrdersHelper::extract_property_by_name( $order, 'agent_ids' ),
459 OsOrdersHelper::extract_property_by_name( $order, 'bundle_ids' ),
460 OsOrdersHelper::extract_property_by_name( $order, 'location_ids' ),
461 ];
462 $original_text = $text;
463 $text = str_replace( $needles, $replacements, $text );
464
465 /**
466 * Returns a string with tracking-related variables replaced, based on supplied OsOrderModel instance
467 *
468 * @param {string} $text Current string with variables replaced
469 * @param {OsBookingModel} $order Instance of OsOrderModel to replace variables for
470 * @param {string} $original_text Original string before any tracking-related replacements were performed
471 * @param {array} $needles Array of default needles to be replaced
472 * @param {array} $replacements Array of default replacement values to supplant each needle
473 *
474 * @returns {string} Filtered string with variables replaced
475 * @since 5.0.7
476 * @hook latepoint_replace_tracking_vars
477 *
478 */
479 return apply_filters( 'latepoint_replace_tracking_vars', $text, $order, $original_text, $needles, $replacements );
480 }
481
482
483 public static function replace_order_vars( $text, OsOrderModel $order ) {
484 $needles = [
485 '{{order_id}}',
486 '{{order_confirmation_code}}',
487 '{{order_coupon_code}}',
488 '{{order_tax_total}}',
489 '{{order_coupon_discount}}',
490 '{{order_subtotal}}',
491 '{{order_total}}',
492 '{{order_status}}',
493 '{{order_fulfillment_status}}',
494 '{{order_payment_status}}',
495 '{{order_payments_total}}',
496 '{{order_balance_due_total}}',
497 '{{order_transactions_breakdown}}',
498 '{{order_summary_breakdown}}',
499 '{{order_items}}',
500 '{{order_agents_emails}}',
501 '{{order_agents_full_names}}',
502 '{{manage_order_url_agent}}',
503 '{{manage_order_url_customer}}',
504 ];
505 $replacements = [
506 $order->id,
507 $order->confirmation_code,
508 $order->coupon_code,
509 $order->tax_total,
510 OsMoneyHelper::format_price( $order->coupon_discount ),
511 OsMoneyHelper::format_price( $order->get_subtotal() ),
512 OsMoneyHelper::format_price( $order->get_total() ),
513 OsOrdersHelper::get_nice_order_status_name( $order->status ),
514 OsOrdersHelper::get_nice_order_fulfillment_status_name( $order->fulfillment_status ),
515 OsOrdersHelper::get_nice_order_payment_status_name( $order->payment_status ),
516 OsMoneyHelper::format_price( $order->get_total_amount_paid_from_transactions() ),
517 OsMoneyHelper::format_price( $order->get_total_balance_due() ),
518 OsOrdersHelper::generate_transactions_breakdown_html( $order ),
519 OsOrdersHelper::generate_summary_breakdown_html( $order ),
520 OsOrdersHelper::generate_order_items_html( $order ),
521 OsOrdersHelper::extract_agent_emails( $order ),
522 OsOrdersHelper::extract_agent_full_names( $order ),
523 OsOrdersHelper::generate_direct_manage_order_url( $order, 'agent' ),
524 OsOrdersHelper::generate_direct_manage_order_url( $order, 'customer' ),
525 ];
526 $original_text = $text;
527 $text = str_replace( $needles, $replacements, $text );
528
529 /**
530 * Returns a string with variables replaced, based on supplied <code>OsOrderModel</code> instance
531 *
532 * @param {string} $text Current string with variables replaced
533 * @param {OsOrderModel} $order Instance of <code>OsOrderModel</code> to replace variables for
534 * @param {string} $original_text Original string before any order-related replacements were performed
535 * @param {array} $needles Array of default needles to be replaced
536 * @param {array} $replacements Array of default replacement values to supplant each needle
537 *
538 * @returns {string} Filtered string with variables replaced
539 * @since 5.0.0
540 * @hook latepoint_replace_order_vars
541 *
542 */
543 return apply_filters( 'latepoint_replace_order_vars', $text, $order, $original_text, $needles, $replacements );
544 }
545
546 public static function replace_booking_vars( $text, OsBookingModel $booking ) {
547 $needles = [
548 '{{booking_id}}',
549 '{{booking_code}}',
550 '{{booking_price}}',
551 '{{service_name}}',
552 '{{service_category}}',
553 '{{start_date}}',
554 '{{start_time}}',
555 '{{end_time}}',
556 '{{booking_status}}',
557 '{{location_name}}',
558 '{{location_full_address}}',
559 '{{booking_duration}}',
560 '{{manage_booking_url_agent}}',
561 '{{manage_booking_url_customer}}',
562 ];
563 $total_duration = ( $booking->get_total_duration() > 0 ) ? $booking->get_total_duration() . ' ' . __( 'minutes', 'latepoint' ) : __( 'n/a', 'latepoint' );
564 $order_item = new OsOrderItemModel( $booking->order_item_id );
565 $replacements = [
566 $booking->id,
567 $booking->booking_code,
568 OsMoneyHelper::format_price( $order_item->get_total() ),
569 $booking->service->name,
570 $booking->service->category_name,
571 $booking->format_start_date_and_time( OsSettingsHelper::get_readable_date_format(), false ),
572 $booking->nice_start_time,
573 $booking->nice_end_time,
574 $booking->nice_status,
575 $booking->location->name,
576 $booking->location->full_address,
577 $total_duration,
578 OsBookingHelper::generate_direct_manage_booking_url( $booking, 'agent' ),
579 OsBookingHelper::generate_direct_manage_booking_url( $booking, 'customer' ),
580 ];
581 $original_text = $text;
582 $text = str_replace( $needles, $replacements, $text );
583
584 /**
585 * Returns a string with variables replaced, based on supplied <code>OsBookingModel</code> instance
586 *
587 * @param {string} $text Current string with variables replaced
588 * @param {OsBookingModel} $booking Instance of <code>OsBookingModel</code> to replace variables for
589 * @param {string} $original_text Original string before any booking-related replacements were performed
590 * @param {array} $needles Array of default needles to be replaced
591 * @param {array} $replacements Array of default replacement values to supplant each needle
592 *
593 * @returns {string} Filtered string with variables replaced
594 * @since 3.0.4
595 * @hook latepoint_replace_booking_vars
596 *
597 */
598 return apply_filters( 'latepoint_replace_booking_vars', $text, $booking, $original_text, $needles, $replacements );
599 }
600
601 public static function replace_other_vars( $text, $other_vars ): string {
602 if ( isset( $other_vars['old_status'] ) ) {
603 $text = str_replace( '{{booking_old_status}}', $other_vars['old_status'], $text );
604 }
605 if ( isset( $other_vars['token'] ) ) {
606 $text = str_replace( '{{token}}', $other_vars['token'], $text );
607 }
608
609 return $text;
610 }
611
612 public static function replace_all_vars( string $text, array $vars ): string {
613 $original_text = $text;
614 if ( isset( $vars['order'] ) ) {
615 $text = self::replace_order_vars( $text, $vars['order'] );
616 }
617 if ( isset( $vars['booking'] ) ) {
618 $text = self::replace_booking_vars( $text, $vars['booking'] );
619 }
620 if ( isset( $vars['customer'] ) ) {
621 $text = self::replace_customer_vars( $text, $vars['customer'] );
622 }
623 if ( isset( $vars['agent'] ) ) {
624 $text = self::replace_agent_vars( $text, $vars['agent'] );
625 }
626 if ( isset( $vars['transaction'] ) ) {
627 $text = self::replace_transaction_vars( $text, $vars['transaction'] );
628 }
629 if ( isset( $vars['payment_request'] ) ) {
630 $text = self::replace_payment_request_vars( $text, $vars['payment_request'] );
631 }
632 if ( isset( $vars['other_vars'] ) ) {
633 $text = self::replace_other_vars( $text, $vars['other_vars'] );
634 }
635 $text = self::replace_business_vars( $text );
636
637 /**
638 * Returns a string with needles replaced, based on supplied variables
639 *
640 * @param {string} $text Current string with variables replaced
641 * @param {array} $vars Array of variables to perform replacements for
642 * @param {string} $original_text Original string before any replacements were performed
643 *
644 * @returns {string} Filtered string with variables replaced
645 * @since 4.3.2
646 * @hook latepoint_replace_all_vars_in_template
647 *
648 */
649 return apply_filters( 'latepoint_replace_all_vars_in_template', $text, $vars, $original_text );
650 }
651 }
652