PluginProbe
YayMail – WooCommerce Email Customizer / 3.4
YayMail – WooCommerce Email Customizer v3.4
4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 3.4.2 3.4.3 All 55 releases
yaymail / includes / MailBuilder / Shortcodes.php

Shortcodes.php in YayMail – WooCommerce Email Customizer 3.4, at includes/MailBuilder/Shortcodes.php

2,013 lines 95.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YayMail\MailBuilder;
4
5 use YayMail\Helper\Helper;
6 use YayMail\Page\Source\CustomPostType;
7 use YayMail\Page\Source\UpdateElement;
8 use YayMail\Templates\Templates;
9 use YayMail\Helper\WooLatepoint;
10
11 defined( 'ABSPATH' ) || exit;
12 global $woocommerce, $wpdb, $current_user, $order;
13
14 class Shortcodes {
15
16 protected static $instance = null;
17 public $order_id = false;
18
19 public $order;
20 public $sent_to_admin = false;
21 public $order_data;
22 public $template = false;
23 public $customer_note = false;
24 public $shipping_address = null;
25 public $billing_address = null;
26 public $preview_mail = false;
27 public $args_email = array();
28 public $is_send_test_mail = false;
29
30 // public $array_content_template = false;
31 public $shortcodes_lists;
32 public static function getInstance() {
33 if ( null == self::$instance ) {
34 self::$instance = new self();
35 }
36 return self::$instance;
37 }
38
39 public function __construct( $template = false, $checkOrder = '', $preview_mail = true, $is_send_test_mail = false ) {
40 $this->preview_mail = $preview_mail;
41 $this->is_send_test_mail = $is_send_test_mail;
42 if ( $template ) {
43 $this->template = $template;
44 if ( 'sampleOrder' === $checkOrder ) {
45 $this->shortCodesOrderSample();
46 } else {
47 $this->shortCodesOrderDefined();
48 }
49 // style css
50 add_filter( 'woocommerce_email_styles', array( $this, 'customCss' ) );
51
52 add_filter( 'safe_style_css', array( $this, 'filter_safe_style_css' ), 10, 1 );
53
54 // Order Details
55 $order_details_list = array(
56 'items_downloadable_title',
57 'items_downloadable_product',
58 'items_border',
59 'items',
60 'items_products_quantity_price',
61 'order_date',
62 'order_fee',
63 'order_id',
64 'order_link',
65 'order_link_string',
66 'order_number',
67 'order_refund',
68 'order_sub_total',
69 'order_discount',
70 'order_total',
71 'order_total_numbers',
72 'orders_count',
73 'quantity_count',
74 'orders_count_double',
75 'order_tn',
76 'items_border_before',
77 'items_border_after',
78 'items_border_title',
79 'items_border_content',
80 'items_downloadable_product',
81 'items_downloadable_title',
82 'get_heading',
83 'woocommerce_email_order_meta',
84 'woocommerce_email_order_details',
85 'woocommerce_email_before_order_table',
86 'woocommerce_email_after_order_table',
87 );
88
89 // Payments
90 $payments_list = array(
91 'order_payment_method',
92 'order_payment_url',
93 'order_payment_url_string',
94 'payment_instruction',
95 'payment_method',
96 'transaction_id',
97 );
98
99 // Shippings
100 $shippings_list = array(
101 'order_shipping',
102 'shipping_address',
103 'shipping_address_1',
104 'shipping_address_2',
105 'shipping_city',
106 'shipping_company',
107 'shipping_country',
108 'shipping_first_name',
109 'shipping_last_name',
110 'shipping_method',
111 'shipping_postcode',
112 'shipping_state',
113 'shipping_phone',
114 );
115
116 // Billings
117 $billings_list = array(
118 'billing_address',
119 'billing_address_1',
120 'billing_address_2',
121 'billing_city',
122 'billing_company',
123 'billing_country',
124 'billing_email',
125 'billing_first_name',
126 'billing_last_name',
127 'billing_phone',
128 'billing_postcode',
129 'billing_state',
130 );
131
132 // Reset Password
133 $reset_password_list = array( 'password_reset_url', 'password_reset_url_string', 'wp_password_reset_url' );
134
135 // New Users
136 $new_users_list = array( 'user_new_password', 'user_activation_link', 'set_password_url_string' );
137
138 // General
139 $general_list = array(
140 'customer_note',
141 'customer_notes',
142 'customer_provided_note',
143 'site_name',
144 'site_url',
145 'site_url_string',
146 'user_email',
147 'user_id',
148 'user_name',
149 'customer_username',
150 'customer_roles',
151 'additional_content',
152 'customer_name',
153 'customer_first_name',
154 'customer_last_name',
155 'view_order_url',
156 'view_order_url_string',
157 'billing_shipping_address',
158 'domain',
159 'user_account_url',
160 'user_account_url_string',
161 //new
162 'billing_shipping_address_title',
163 'billing_shipping_address_content',
164 'check_billing_shipping_address',
165 'order_coupon_codes',
166 'jet_booking_details',
167
168 );
169 //WooCommerce for LatePoint
170 $woo_latepoint = array(
171 'woo_latepoint_booking_detail',
172 'woo_latepoint_calendar_start_date',
173 'woo_latepoint_selected_total_attendees',
174 'woo_latepoint_caption',
175 'woo_latepoint_bg_color',
176 'woo_latepoint_text_color',
177 'woo_latepoint_font_size',
178 'woo_latepoint_border',
179 'woo_latepoint_border_radius',
180 'woo_latepoint_margin',
181 'woo_latepoint_padding',
182 'woo_latepoint_css',
183 'woo_latepoint_show_locations',
184 'woo_latepoint_show_agents',
185 'woo_latepoint_show_services',
186 'woo_latepoint_show_service_categories',
187 'woo_latepoint_selected_location',
188 'woo_latepoint_selected_agent',
189 'woo_latepoint_selected_service',
190 'woo_latepoint_selected_service_category',
191 'woo_latepoint_selected_duration',
192 'woo_latepoint_hide_side_panel',
193 'woo_latepoint_hide_summary',
194 );
195
196 // Additional Order Meta.
197 $order = CustomPostType::getListOrders();
198
199 /* Define Shortcodes */
200 $shortcodes_lists = array();
201 $arrShortcodeCustoms = array();
202 $shortcode = array();
203 $yaymail_informations = Helper::inforShortcode( '', $template, array() );
204 $shortcodeCustom = array_keys( apply_filters( 'yaymail_customs_shortcode', $shortcode, $yaymail_informations, $this->args_email ) );
205
206 if ( ! empty( $shortcodeCustom ) ) {
207 foreach ( $shortcodeCustom as $item ) {
208 array_push( $arrShortcodeCustoms, str_replace( array( '[', ']' ), '', $item ) );
209 }
210 $shortcodes_lists = array_merge( $shortcodes_lists, $arrShortcodeCustoms );
211 }
212
213 $shortcodes_lists = array_merge( $shortcodes_lists, apply_filters( 'yaymail_shortcodes', $shortcodes_lists ) );
214 $shortcodes_lists = array_merge( $shortcodes_lists, $order_details_list );
215 $shortcodes_lists = array_merge( $shortcodes_lists, $payments_list );
216 $shortcodes_lists = array_merge( $shortcodes_lists, $shippings_list );
217 $shortcodes_lists = array_merge( $shortcodes_lists, $billings_list );
218 $shortcodes_lists = array_merge( $shortcodes_lists, $reset_password_list );
219 $shortcodes_lists = array_merge( $shortcodes_lists, $new_users_list );
220 $shortcodes_lists = array_merge( $shortcodes_lists, $general_list );
221 $shortcodes_lists = array_merge( $shortcodes_lists, $woo_latepoint );
222 $this->shortcodes_lists = $shortcodes_lists;
223 foreach ( $this->shortcodes_lists as $key => $shortcode_name ) {
224 if ( 'woocommerce_email_before_order_table' == $shortcode_name || 'woocommerce_email_after_order_table' == $shortcode_name || 'woocommerce_email_order_details' == $shortcode_name || 'woocommerce_email_order_meta' == $shortcode_name ) {
225 $function_name = $this->parseShortCodeToFunctionName( 'woocomme' . $shortcode_name );
226 if ( method_exists( $this, $function_name ) ) {
227 add_shortcode(
228 $shortcode_name,
229 function ( $atts, $content, $tag ) {
230 $function_name = $this->parseShortCodeToFunctionName( 'woocomme' . $tag );
231 return $this->$function_name( $atts, $this->order, $this->sent_to_admin, $this->args_email );
232 }
233 );
234 }
235 } else {
236 $function_name = $this->parseShortCodeToFunctionName( 'yaymail_' . $shortcode_name );
237 if ( method_exists( $this, $function_name ) || method_exists( WooLatepoint::class, $function_name ) ) {
238 if ( strpos( $shortcode_name, 'woo_latepoint' ) !== false ) {
239 add_shortcode(
240 'yaymail_' . $shortcode_name,
241 function ( $atts, $content, $tag ) {
242 $function_name = $this->parseShortCodeToFunctionName( $tag );
243 return WooLatepoint::$function_name( $atts, $this->order, $this->sent_to_admin, $this->args_email );
244 }
245 );
246 } else {
247 add_shortcode(
248 'yaymail_' . $shortcode_name,
249 function ( $atts, $content, $tag ) {
250 $function_name = $this->parseShortCodeToFunctionName( $tag );
251 return $this->$function_name( $atts, $this->order, $this->sent_to_admin, $this->args_email );
252 }
253 );
254 }
255 } elseif ( strpos( $shortcode_name, 'addon' ) !== false || strpos( $shortcode_name, 'custom_shortcode' ) !== false ) {
256 add_shortcode(
257 $shortcode_name,
258 function ( $atts, $content, $tag ) {
259 return $this->order_data[ '[' . $tag . ']' ];
260 }
261 );
262 } else {
263 add_shortcode( 'yaymail_' . $shortcode_name, array( $this, 'shortcodeCallBack' ) );
264 }
265 }
266 }
267 }
268 }
269
270 public function parseShortCodeToFunctionName( $shortcode_name ) {
271 $function_name = substr( $shortcode_name, 8 );
272 $offset = 0;
273 while ( false !== strpos( $function_name, '_', $offset ) ) {
274 $position = strpos( $function_name, '_', $offset );
275 $function_name[ $position + 1 ] = strtoupper( $function_name[ $position + 1 ] );
276 $offset = $position + 1;
277 }
278 $function_name = str_replace( '_', '', $function_name );
279 return $function_name;
280 }
281
282 public function applyCSSFormat( $defaultsCss = '' ) {
283 $templateEmail = \YayMail\Templates\Templates::getInstance();
284 $css = $templateEmail::getCssFortmat();
285 $cssDirection = '';
286 $cssDirection .= 'td{direction: rtl}';
287 $cssDirection .= 'td, th, td{text-align:right;}';
288
289 $css .= get_option( 'yaymail_direction' ) && get_option( 'yaymail_direction' ) === 'rtl' ? $cssDirection : '';
290 $css .= $defaultsCss;
291 $css .= '.td { color: inherit; }';
292 return $css;
293 }
294 public function customCss( $css = '' ) {
295 return $this->applyCSSFormat( $css );
296 }
297
298 public function filter_safe_style_css( $array ) {
299 if ( function_exists( 'is_plugin_active' ) && is_plugin_active( 'wp-social-reviews/wp-social-reviews.php' ) ) {
300 $style_css = array(
301 'background',
302 'background-color',
303 'border',
304 'border-width',
305 'border-color',
306 'border-style',
307 'border-right',
308 'border-right-color',
309 'border-right-style',
310 'border-right-width',
311 'border-bottom',
312 'border-bottom-color',
313 'border-bottom-style',
314 'border-bottom-width',
315 'border-left',
316 'border-left-color',
317 'border-left-style',
318 'border-left-width',
319 'border-top',
320 'border-top-color',
321 'border-top-style',
322 'border-top-width',
323 'border-spacing',
324 'border-collapse',
325 'caption-side',
326 'color',
327 'font',
328 'font-family',
329 'font-size',
330 'font-style',
331 'font-variant',
332 'font-weight',
333 'letter-spacing',
334 'line-height',
335 'text-decoration',
336 'text-indent',
337 'text-align',
338 'height',
339 'min-height',
340 'max-height',
341 'width',
342 'min-width',
343 'max-width',
344 'margin',
345 'margin-right',
346 'margin-bottom',
347 'margin-left',
348 'margin-top',
349 'padding',
350 'padding-right',
351 'padding-bottom',
352 'padding-left',
353 'padding-top',
354 'clear',
355 'cursor',
356 'direction',
357 'float',
358 'overflow',
359 'vertical-align',
360 'list-style-type',
361 'display',
362 );
363 return $style_css;
364 } else {
365 $additional_allowed_css_attributes = array( 'display' );
366 return array_merge( $array, $additional_allowed_css_attributes );
367 }
368
369 }
370
371 public function setOrderId( $order_id = '', $sent_to_admin = '', $args = '' ) {
372 $this->order_id = $order_id;
373 $this->args_email = $args;
374 $this->sent_to_admin = $sent_to_admin;
375 // Additional Order Meta.
376 $order_meta_list = array();
377 if ( ! empty( $this->order_id ) ) {
378 $order_metaArr = get_post_meta( $this->order_id );
379 if ( is_array( $order_metaArr ) && count( $order_metaArr ) > 0 ) {
380 foreach ( $order_metaArr as $k => $v ) {
381 $nameField = str_replace( ' ', '_', trim( $k ) );
382 $order_meta_list[] = 'order_meta:' . $nameField;
383 }
384 }
385 }
386 $shortcodes_lists = array();
387 $shortcodes_lists = array_merge( $shortcodes_lists, $order_meta_list );
388 $order = wc_get_order( $order_id );
389 $shortcode_order_taxes = array();
390 if ( ! empty( $order ) ) {
391 foreach ( $order->get_items( 'tax' ) as $item_id => $item_tax ) {
392 $tax_rate_id = $item_tax->get_rate_id();
393 $shortcode_order_taxes[] = 'order_taxes_' . $tax_rate_id;
394 }
395 $shortcodes_lists = array_merge( $shortcodes_lists, $shortcode_order_taxes );
396 }
397
398 foreach ( $shortcodes_lists as $key => $shortcode_name ) {
399 add_shortcode( 'yaymail_' . $shortcode_name, array( $this, 'shortcodeCallBack' ) );
400 }
401 }
402
403 protected function _shortcode_atts( $defaults = array(), $atts = array() ) {
404 if ( isset( $atts['class'] ) ) {
405 $atts['classname'] = $atts['class'];
406 }
407
408 return \shortcode_atts( $defaults, $atts );
409 }
410
411 // short Codes Order when select SampleOrder
412 public function shortCodesOrderSample( $sent_to_admin = '' ) {
413 $user = wp_get_current_user();
414 $useId = get_current_user_id();
415 $this->defaultSampleOrderData( $sent_to_admin );
416 }
417
418 public function shortCodesOrderDefined( $sent_to_admin = '', $args = array() ) {
419 if ( false !== $this->order_id && ! empty( $this->order_id ) && class_exists( 'WC_Order' ) ) {
420 $this->order = new \WC_Order( $this->order_id );
421 $this->collectOrderData( $sent_to_admin, $args );
422 }
423 if ( ! function_exists( 'get_user_by' ) ) {
424 return false;
425 }
426 $action = isset( $_REQUEST['action'] ) ? sanitize_key( $_REQUEST['action'] ) : '';
427 if ( empty( $this->order_id ) || ! $this->order_id ) {
428 $shortcode = $this->order_data;
429
430 if ( isset( $args['additional_content'] ) ) {
431 $shortcode['[yaymail_additional_content]'] = wp_kses_post( wpautop( wptexturize( $args['additional_content'] ) ) );
432 }
433 if ( isset( $_REQUEST['billing_email'] ) ) {
434 $shortcode['[yaymail_user_email]'] = sanitize_email( $_REQUEST['billing_email'] );
435 $user = get_user_by( 'email', sanitize_email( $_REQUEST['billing_email'] ) );
436 if ( ! empty( $user ) ) {
437 $shortcode['[yaymail_customer_username]'] = $user->user_login;
438 $shortcode['[yaymail_customer_name]'] = get_user_meta( $user->ID, 'first_name', true ) . ' ' . get_user_meta( $user->ID, 'last_name', true );
439 $shortcode['[yaymail_customer_first_name]'] = get_user_meta( $user->ID, 'first_name', true );
440 $shortcode['[yaymail_customer_last_name]'] = get_user_meta( $user->ID, 'last_name', true );
441 $shortcode['[yaymail_user_id]'] = $user->ID;
442 }
443 }
444 if ( empty( $shortcode['[yaymail_customer_username]'] ) ) {
445 if ( isset( $_REQUEST['user_email'] ) ) {
446 $user = get_user_by( 'email', sanitize_email( $_REQUEST['user_email'] ) );
447 if ( isset( $user->user_login ) ) {
448 $shortcode['[yaymail_customer_username]'] = $user->user_login;
449 }
450 if ( isset( $user->ID ) ) {
451 $shortcode['[yaymail_user_id]'] = $user->ID;
452 }
453 } elseif ( isset( $_REQUEST['email'] ) ) {
454 $user = get_user_by( 'email', sanitize_email( $_REQUEST['email'] ) );
455 if ( isset( $user->user_login ) ) {
456 $shortcode['[yaymail_customer_username]'] = $user->user_login;
457 }
458 if ( isset( $user->ID ) ) {
459 $shortcode['[yaymail_user_id]'] = $user->ID;
460 }
461 }
462 }
463 if ( empty( $shortcode['[yaymail_user_email]'] ) ) {
464 if ( isset( $_REQUEST['user_email'] ) ) {
465 $user = get_user_by( 'email', sanitize_email( $_REQUEST['user_email'] ) );
466 if ( isset( $user->user_email ) ) {
467 $shortcode['[yaymail_user_email]'] = $user->user_email;
468 }
469 if ( isset( $user->ID ) ) {
470 $shortcode['[yaymail_user_id]'] = $user->ID;
471 }
472 } elseif ( isset( $_REQUEST['email'] ) ) {
473 $user = get_user_by( 'email', sanitize_email( $_REQUEST['email'] ) );
474 if ( isset( $user->user_email ) ) {
475 $shortcode['[yaymail_user_email]'] = $user->user_email;
476 }
477 if ( isset( $user->ID ) ) {
478 $shortcode['[yaymail_user_id]'] = $user->ID;
479 }
480 }
481 }
482 if ( empty( $shortcode['[yaymail_customer_name]'] ) ) {
483 if ( isset( $_REQUEST['user_email'] ) ) {
484 $user = get_user_by( 'email', sanitize_email( $_REQUEST['user_email'] ) );
485 if ( isset( $user->user_email ) ) {
486 $shortcode['[yaymail_customer_name]'] = get_user_meta( $user->ID, 'first_name', true ) . ' ' . get_user_meta( $user->ID, 'last_name', true );
487 $shortcode['[yaymail_customer_first_name]'] = get_user_meta( $user->ID, 'first_name', true );
488 $shortcode['[yaymail_customer_last_name]'] = get_user_meta( $user->ID, 'last_name', true );
489 }
490 if ( isset( $user->ID ) ) {
491 $shortcode['[yaymail_user_id]'] = $user->ID;
492 }
493 } elseif ( isset( $_REQUEST['email'] ) ) {
494 $user = get_user_by( 'email', sanitize_email( $_REQUEST['email'] ) );
495 if ( isset( $user->user_email ) ) {
496 if ( ! empty( get_user_meta( $user->ID, 'first_name', true ) ) && ! empty( get_user_meta( $user->ID, 'last_name', true ) ) ) {
497 $shortcode['[yaymail_customer_name]'] = get_user_meta( $user->ID, 'first_name', true ) . ' ' . get_user_meta( $user->ID, 'last_name', true );
498 $shortcode['[yaymail_customer_first_name]'] = get_user_meta( $user->ID, 'first_name', true );
499 $shortcode['[yaymail_customer_last_name]'] = get_user_meta( $user->ID, 'last_name', true );
500 } elseif ( isset( $_REQUEST['first_name'] ) && isset( $_REQUEST['last_name'] ) ) {
501 $shortcode['[yaymail_customer_name]'] = sanitize_text_field( $_REQUEST['first_name'] ) . ' ' . sanitize_text_field( $_REQUEST['last_name'] );
502 $shortcode['[yaymail_customer_first_name]'] = sanitize_text_field( $_REQUEST['first_name'] );
503 $shortcode['[yaymail_customer_last_name]'] = sanitize_text_field( $_REQUEST['last_name'] );
504 }
505 }
506 if ( isset( $user->ID ) ) {
507 $shortcode['[yaymail_user_id]'] = $user->ID;
508 }
509 }
510 }
511 if ( ! empty( $args ) ) {
512 $postID = CustomPostType::postIDByTemplate( $this->template );
513 $text_link_color = get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) ? get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) : '#7f54b3';
514 $yaymail_settings = get_option( 'yaymail_settings' );
515 $yaymail_informations = Helper::inforShortcode( $postID, $this->template, array() );
516
517 /**
518 * Support Custom User Registration Fields - Addify
519 */
520 if ( isset( $args['customer'] ) && $args['customer'] instanceof \WP_User ) {
521 $user = $args['customer'];
522 $shortcode['[yaymail_customer_username]'] = $user->user_login;
523 $shortcode['[yaymail_customer_name]'] = get_user_meta( $user->ID, 'first_name', true ) . ' ' . get_user_meta( $user->ID, 'last_name', true );
524 $shortcode['[yaymail_customer_first_name]'] = get_user_meta( $user->ID, 'first_name', true );
525 $shortcode['[yaymail_customer_last_name]'] = get_user_meta( $user->ID, 'last_name', true );
526 $shortcode['[yaymail_user_email]'] = $user->user_email;
527 $shortcode['[yaymail_user_id]'] = $user->ID;
528 }
529
530 if ( isset( $args['email'] ) || isset( $args['admin_email'] ) || isset( $args['user'] ) ) {
531 if ( isset( $args['email']->id ) && 'customer_reset_password' == $args['email']->id ) {
532 $user = new \WP_User( intval( $args['email']->user_id ) );
533 $shortcode['[yaymail_customer_username]'] = $args['email']->user_login;
534 $shortcode['[yaymail_customer_name]'] = get_user_meta( $user->ID, 'first_name', true ) . ' ' . get_user_meta( $user->ID, 'last_name', true );
535 $shortcode['[yaymail_customer_first_name]'] = get_user_meta( $user->ID, 'first_name', true );
536 $shortcode['[yaymail_customer_last_name]'] = get_user_meta( $user->ID, 'last_name', true );
537 $shortcode['[yaymail_user_email]'] = $args['email']->user_email;
538 $shortcode['[yaymail_user_id]'] = $user->ID;
539 if ( isset( $args['reset_key'] ) ) {
540 $link_reset = add_query_arg(
541 array(
542 'key' => $args['reset_key'],
543 'id' => $user->ID,
544 ),
545 wc_get_endpoint_url( 'lost-password', '', wc_get_page_permalink( 'myaccount' ) )
546 );
547 $shortcode['[yaymail_password_reset_url]'] = '<a style="color: ' . esc_attr( $text_link_color ) . ';" href="' . esc_url( $link_reset ) . '">' . esc_html__( 'Click here to reset your password', 'woocommerce' ) . '</a>';
548 $shortcode['[yaymail_password_reset_url_string]'] = esc_url( $link_reset );
549 }
550
551 // link reset password send by wp
552 if ( isset( $args['email']->user_login ) && isset( $args['email']->user_data ) && isset( $args['email']->key ) ) {
553 $locale = get_user_locale( $args['email']->user_data );
554 $key = $args['email']->key;
555 $user_login = $args['email']->user_login;
556
557 if ( class_exists( '\Essential_Addons_Elementor\Classes\Bootstrap' ) ) {
558 $page_id = isset( $_REQUEST['page_id'] ) && ! empty( $_REQUEST['page_id'] ) ? intval( $_REQUEST['page_id'], 10 ) : null;
559 $widget_id = isset( $_REQUEST['widget_id'] ) && ! empty( $_REQUEST['widget_id'] ) ? sanitize_text_field( $_REQUEST['widget_id'] ) : null;
560 $page_id_for_popup = ! empty( $_REQUEST['page_id_for_popup'] ) ? intval( $_REQUEST['page_id_for_popup'], 10 ) : $page_id;
561 $resetpassword_in_popup_selector = ! empty( $_REQUEST['resetpassword_in_popup_selector'] ) ? sanitize_text_field( $_REQUEST['resetpassword_in_popup_selector'] ) : '';
562 $shortcode['[yaymail_wp_password_reset_url]'] = network_site_url( "wp-login.php?action=rp&eael-resetpassword=1&key=$key&login=" . rawurlencode( $user_login ), 'login' ) . '&page_id=' . $page_id_for_popup . '&widget_id=' . $widget_id . '&popup-selector=' . $resetpassword_in_popup_selector . '&wp_lang=' . $locale . "\r\n\r\n";
563
564 } else {
565 $shortcode['[yaymail_wp_password_reset_url]'] = network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) . '&wp_lang=' . $locale;
566 }
567 }
568
569 $shortcode['[yaymail_site_name]'] = esc_html( get_bloginfo( 'name' ) );
570 }
571
572 $shortcode['[yaymail_site_name]'] = esc_html( get_bloginfo( 'name' ) );
573 $shortcode['[yaymail_site_url]'] = '<a style="color: ' . esc_attr( $text_link_color ) . ';" href="' . esc_url( get_home_url() ) . '"> ' . esc_url( get_home_url() ) . ' </a>';
574 $shortcode['[yaymail_site_url_string]'] = esc_url( get_home_url() );
575 $shortcode['[yaymail_user_account_url]'] = '<a style="color:' . esc_attr( $text_link_color ) . '; font-weight: normal; text-decoration: underline;" href="' . wc_get_page_permalink( 'myaccount' ) . '">' . esc_url( wc_get_page_permalink( 'myaccount' ) ) . '</a>';
576 $shortcode['[yaymail_user_account_url_string]'] = wc_get_page_permalink( 'myaccount' );
577 if ( isset( $args['email']->user_pass ) && ! empty( $args['email']->user_pass ) ) {
578 $shortcode['[yaymail_user_new_password]'] = $args['email']->user_pass;
579 } else {
580 if ( isset( $_REQUEST['pass1-text'] ) && '' != $_REQUEST['pass1-text'] ) {
581 $shortcode['[yaymail_user_new_password]'] = sanitize_text_field( $_REQUEST['pass1-text'] );
582 } elseif ( isset( $_REQUEST['pass1'] ) && '' != $_REQUEST['pass1'] ) {
583 $shortcode['[yaymail_user_new_password]'] = sanitize_text_field( $_REQUEST['pass1'] );
584 } else {
585 $shortcode['[yaymail_user_new_password]'] = '';
586 }
587 }
588
589 if ( isset( $args['set_password_url'] ) && ! empty( $args['set_password_url'] ) ) {
590 $shortcode['[yaymail_set_password_url_string]'] = $args['set_password_url'];
591 }
592
593 if ( isset( $args['email']->user_login ) && ! empty( $args['email']->user_login ) ) {
594 $shortcode['[yaymail_customer_username]'] = $args['email']->user_login;
595 $user = get_user_by( 'email', $args['email']->user_email );
596 if ( ! empty( get_user_meta( $user->ID, 'first_name', true ) ) && ! empty( get_user_meta( $user->ID, 'last_name', true ) ) ) {
597 $shortcode['[yaymail_customer_name]'] = get_user_meta( $user->ID, 'first_name', true ) . ' ' . get_user_meta( $user->ID, 'last_name', true );
598 $shortcode['[yaymail_customer_first_name]'] = get_user_meta( $user->ID, 'first_name', true );
599 $shortcode['[yaymail_customer_last_name]'] = get_user_meta( $user->ID, 'last_name', true );
600 } elseif ( isset( $_REQUEST['first_name'] ) && isset( $_REQUEST['last_name'] ) ) {
601 $shortcode['[yaymail_customer_name]'] = sanitize_text_field( $_REQUEST['first_name'] ) . ' ' . sanitize_text_field( $_REQUEST['last_name'] );
602 $shortcode['[yaymail_customer_first_name]'] = sanitize_text_field( $_REQUEST['first_name'] );
603 $shortcode['[yaymail_customer_last_name]'] = sanitize_text_field( $_REQUEST['last_name'] );
604 }
605 }
606 if ( isset( $args['email']->user_email ) && ! empty( $args['email']->user_email ) ) {
607 $shortcode['[yaymail_user_email]'] = $args['email']->user_email;
608 }
609 if ( isset( $args['email']->id ) && ( 'customer_new_account_activation' == $args['email']->id ) ) { // customer_new_account_activation : Template of Germanized plugin, New Account template use shortcode [yaymail_set_password_url_string] is activation link
610 if ( 'customer_new_account_activation' == $args['email']->id ) {
611 if ( isset( $args['email']->user_activation_url ) && ! empty( $args['email']->user_activation_url ) ) {
612 $shortcode['[yaymail_user_activation_link]'] = $args['email']->user_activation_url;
613 }
614 } else {
615 if ( isset( $args['email']->user_login ) && ! empty( $args['email']->user_login ) ) {
616 global $wpdb, $wp_hasher;
617 $newHash = $wp_hasher;
618 // Generate something random for a password reset key.
619 $key = wp_generate_password( 20, false );
620
621 /**
622 *
623 * This action is documented in wp-login.php
624 */
625 do_action( 'retrieve_password_key', $args['email']->user_login, $key );
626
627 // Now insert the key, hashed, into the DB.
628 if ( empty( $wp_hasher ) ) {
629 if ( ! class_exists( 'PasswordHash' ) ) {
630 include_once ABSPATH . 'wp-includes/class-phpass.php';
631 }
632 $newHash = new \PasswordHash( 8, true );
633 }
634 $hashed = time() . ':' . $newHash->HashPassword( $key );
635 $wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $args['email']->user_login ) );
636 $activation_url = network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $args['email']->user_login ), 'login' );
637 $shortcode['[yaymail_user_activation_link]'] = $activation_url;
638 }
639 }
640 }
641
642 // Define shortcode from plugin addon
643 $shortcode = apply_filters( 'yaymail_do_shortcode', $shortcode, $yaymail_informations, $args );
644 // Define customs shortcode for user
645 $shortcode = apply_filters( 'yaymail_customs_shortcode', $shortcode, $yaymail_informations, $args );
646
647 } else {
648 // Define shortcode from plugin addon not have args[''email]
649 $shortcode = apply_filters( 'yaymail_do_shortcode', $shortcode, $yaymail_informations, $args );
650 // Define customs shortcode for user
651 $shortcode = apply_filters( 'yaymail_customs_shortcode', $shortcode, $yaymail_informations, $args );
652
653 }
654 }
655
656 // support plugin YITH WooCommerce Coupon Email System Premium
657 if ( class_exists( 'YITH_WC_Coupon_Email_System' ) ) {
658 $shortcode['[yaymail_site_name]'] = esc_html( get_bloginfo( 'name' ) );
659 }
660
661 $this->order_data = $shortcode;
662 }
663 }
664 public function shortcodeCallBack( $atts, $content, $tag ) {
665
666 return isset( $this->order_data[ '[' . $tag . ']' ] ) ? $this->order_data[ '[' . $tag . ']' ] : false;
667
668 }
669
670 public function templateParser() {
671 // Helper::checkNonce();
672 $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( $_POST['nonce'] ) : '';
673 if ( ! wp_verify_nonce( $nonce, 'email-nonce' ) ) {
674 wp_send_json_error( array( 'mess' => 'Nonce is invalid' ) );
675 } else {
676 $request = $_POST;
677 $this->order_id = false;
678 if ( isset( $request['order_id'] ) ) {
679 $order_id = sanitize_text_field( $request['order_id'] );
680 if ( 'sampleOrder' !== $order_id ) {
681 $order_id = intval( $order_id );
682 }
683 if ( ! $order_id ) {
684 $order_id = '';
685 }
686
687 $this->template = isset( $request['template'] ) ? sanitize_text_field( $request['template'] ) : false;
688 $this->order_id = $order_id;
689 }
690
691 if ( ! $this->order_id || ! $this->template ) {
692 return false;
693 }
694
695 if ( 'sampleOrder' !== $order_id ) {
696 $this->order = new \WC_Order( $this->order_id );
697 }
698
699 if ( 'sampleOrder' !== $order_id && ( is_null( $this->order ) || empty( $this->order ) || ! isset( $this->order ) ) ) {
700 return false;
701 }
702
703 if ( 'sampleOrder' !== $order_id ) {
704 $this->collectOrderData();
705 $this->collectOrderDataHasFunction();
706 } else {
707 $this->defaultSampleOrderData();
708 }
709
710 $result = (object) array();
711 $result->order_id = $this->order_id;
712 $result->order_data = $this->order_data;
713
714 $shortcode_order_meta = array();
715 $shortcode_order_custom_meta = array();
716 $shortcode_order_taxes = array();
717 if ( 'sampleOrder' !== $order_id ) {
718 $result->order = $this->order;
719 $result->order_items = $result->order->get_items();
720 $result->user_details = $result->order->get_user();
721
722 /*
723 @@@@ Get name field in custom field of order woocommerce.
724 */
725 $order_metaArr = get_post_meta( $order_id );
726 if ( is_array( $order_metaArr ) && count( $order_metaArr ) > 0 ) {
727 $pattern = '/^_.*/i';
728 $n = 0;
729 foreach ( $order_metaArr as $k => $v ) {
730 // @@@ starts with the "_" character of the woo field.
731 if ( ! preg_match( $pattern, $k ) ) {
732 $nameField = str_replace( ' ', '_', trim( $k ) );
733 $nameShorcode = '[yaymail_post_meta:' . $nameField . ']';
734 $key_order_meta = 'post_meta:' . $nameField . '_' . $n;
735 $shortcode_order_meta[] = array(
736 'key' => $key_order_meta,
737 $nameShorcode => 'Loads value of order meta key - ' . $nameField,
738 );
739 $n++;
740 }
741 }
742 }
743 if ( ! empty( $result->order ) ) {
744 foreach ( $result->order->get_meta_data() as $meta ) {
745 $nameField = str_replace( ' ', '_', trim( $meta->get_data()['key'] ) );
746 $nameShorcode = '[yaymail_order_meta:' . $nameField . ']';
747 $key_order_custom_meta = 'order_meta:' . $nameField;
748 $shortcode_order_custom_meta[] = array(
749 'key' => $key_order_custom_meta,
750 $nameShorcode => 'Loads value of order custom meta key - ' . $nameField,
751 );
752 }
753 foreach ( $result->order->get_items( 'tax' ) as $item_id => $item_tax ) {
754 $tax_rate_id = $item_tax->get_rate_id();
755 $shortcode_order_taxes[] = array(
756 'key' => '[yaymail_order_taxes_' . $tax_rate_id . ']',
757 'name' => $item_tax->get_label(),
758 );
759 }
760 }
761 } else {
762 $result->order = '';
763 $result->order_items = '';
764 $result->user_details = '';
765 }
766 $real_postID = '';
767 if ( isset( $request['template'] ) ) {
768 if ( CustomPostType::postIDByTemplate( $this->template ) ) {
769 $postID = CustomPostType::postIDByTemplate( $this->template );
770 $real_postID = $postID;
771 $emailTemplate = get_post( $postID );
772 $updateElement = new UpdateElement();
773 $yaymail_elements = get_post_meta( $postID, '_yaymail_elements', true );
774 $list_elements = Helper::preventXSS( $yaymail_elements );
775
776 $yaymailSettingsDefaultLogo = get_option( 'yaymail_settings_default_logo' );
777 $set_default_logo = false != $yaymailSettingsDefaultLogo ? $yaymailSettingsDefaultLogo['set_default'] : '0';
778 $yaymailSettingsDefaultFooter = get_option( 'yaymail_settings_default_footer' );
779 $set_default_footer = false != $yaymailSettingsDefaultFooter ? $yaymailSettingsDefaultFooter['set_default'] : '0';
780 $reviewYayMail = get_option( 'yaymail_review' );
781
782 $make_args['order'] = $this->order;
783 $array_element = array();
784 foreach ( $list_elements as $key => $element ) {
785 if ( has_filter( 'yaymail_addon_for_conditional_logic' ) && ! empty( $make_args['order'] ) && isset( $element['settingRow']['arrConditionLogic'] ) ) {
786 if ( ! empty( $element['settingRow']['arrConditionLogic'] ) ) {
787 $conditional_Logic = apply_filters( 'yaymail_addon_for_conditional_logic', false, $make_args, $element['settingRow'] );
788 if ( $conditional_Logic ) {
789 $array_element[] = $element;
790 }
791 } else {
792 if ( 'OneColumn' === $element['type'] || 'TwoColumns' === $element['type'] || 'ThreeColumns' === $element['type'] || 'FourColumns' === $element['type'] ) {
793 for ( $column = 1; $column <= 4; $column++ ) {
794 if ( isset( $element['settingRow'][ 'column' . $column ] ) ) {
795 foreach ( $element['settingRow'][ 'column' . $column ] as $column_key => $column_element ) {
796 if ( isset( $column_element['settingRow']['arrConditionLogic'] ) && ! empty( $column_element['settingRow']['arrConditionLogic'] ) ) {
797 $conditional_Logic = apply_filters( 'yaymail_addon_for_conditional_logic', false, $make_args, $column_element['settingRow'] );
798 if ( ! $conditional_Logic ) {
799 unset( $element['settingRow'][ 'column' . $column ][ $column_key ] );
800 }
801 }
802 }
803 }
804 }
805 }
806 $array_element[] = $element;
807 }
808 } else {
809 $array_element[] = $element;
810 }
811 }
812
813 // Check and update order items tilte
814 if ( ! metadata_exists( 'post', $postID, '_yaymail_email_order_item_title' ) || empty( get_post_meta( $postID, '_yaymail_email_order_item_title', true ) ) ) {
815 $orderItemsTitle = Helper::OrderItemsTitle();
816 update_post_meta( $postID, '_yaymail_email_order_item_title', $orderItemsTitle );
817 } else {
818 $orderItemsTitle = Helper::OrderItemsTitle();
819 $yaymail_email_order_item_title = get_post_meta( $postID, '_yaymail_email_order_item_title', true );
820 if ( ! empty( $yaymail_email_order_item_title ) && is_array( $yaymail_email_order_item_title ) ) {
821 $merge_yaymail_email_order_item_title = array();
822 foreach ( $orderItemsTitle as $key => $value ) {
823 if ( isset( $yaymail_email_order_item_title[ $key ] ) && '' !== $yaymail_email_order_item_title[ $key ] ) {
824 $merge_yaymail_email_order_item_title[ $key ] = $yaymail_email_order_item_title[ $key ];
825 } else {
826 $merge_yaymail_email_order_item_title[ $key ] = $value;
827 }
828 }
829 update_post_meta( $postID, '_yaymail_email_order_item_title', $merge_yaymail_email_order_item_title );
830 }
831 }
832 if ( ! metadata_exists( 'post', $postID, '_yaymail_email_order_item_download_title' ) || empty( get_post_meta( $postID, '_yaymail_email_order_item_download_title', true ) ) ) {
833 $orderItemsDownloadsTitle = Helper::OrderItemsDownloadsTitle();
834 update_post_meta( $postID, '_yaymail_email_order_item_download_title', $orderItemsDownloadsTitle );
835 }
836
837 $result->elements = Helper::unsanitize_array( $updateElement->merge_new_props_to_elements( $array_element ) );
838 $result->emailBackgroundColor = get_post_meta( $postID, '_email_backgroundColor_settings', true ) ? get_post_meta( $postID, '_email_backgroundColor_settings', true ) : 'rgb(236, 236, 236)';
839 $result->emailTextLinkColor = get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) ? get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) : '#7f54b3';
840 $result->titleShipping = get_post_meta( $postID, '_email_title_shipping', true ) ? get_post_meta( $postID, '_email_title_shipping', true ) : 'Shipping Address';
841 $result->titleBilling = get_post_meta( $postID, '_email_title_billing', true ) ? get_post_meta( $postID, '_email_title_billing', true ) : 'Billing Address';
842 $result->orderTitle = get_post_meta( $postID, '_yaymail_email_order_item_title', true );
843 $result->orderItemsDownloadTitle = get_post_meta( $postID, '_yaymail_email_order_item_download_title', true ) ? get_post_meta( $postID, '_yaymail_email_order_item_download_title', true ) : Helper::OrderItemsDownloadsTitle();
844 $result->customCSS = $this->applyCSSFormat();
845 $result->shortcode_order_meta = $shortcode_order_meta;
846 $result->shortcode_order_custom_meta = $shortcode_order_custom_meta;
847 $result->shortcode_order_taxes = $shortcode_order_taxes;
848 $result->set_default_logo = $set_default_logo;
849 $result->set_default_footer = $set_default_footer;
850 $result->review_yaymail = $reviewYayMail;
851
852 }
853 }
854 $result->yaymailAddonTemps = Helper::replaceCustomAllowedHTMLTags( apply_filters( 'yaymail_addon_templates', array(), $result->order, $real_postID ) );
855
856 echo json_encode( $result );
857 die();
858 }
859 }
860 public function collectOrderDataHasFunction( $sent_to_admin = '', $args = array() ) {
861 $order = $this->order;
862 if ( empty( $this->order_id ) || empty( $order ) ) {
863 return false;
864 }
865 // Link Downloadable Product
866 $shortcode['[yaymail_items_downloadable_title]'] = $this->itemsDownloadableTitle( '', $this->order, $sent_to_admin, '' ); // done
867 $shortcode['[yaymail_items_downloadable_product]'] = $this->itemsDownloadableProduct( '', $this->order, $sent_to_admin, '' ); // done
868
869 // ORDER DETAILS
870 $shortcode['[yaymail_items_border]'] = $this->itemsBorder( '', $this->order, $sent_to_admin ); // done
871 $shortcode['[yaymail_items_border_before]'] = $this->itemsBorderBefore( '', $this->order, $sent_to_admin ); // done
872 $shortcode['[yaymail_items_border_after]'] = $this->itemsBorderAfter( '', $this->order, $sent_to_admin ); // done
873 $shortcode['[yaymail_items_border_title]'] = $this->itemsBorderTitle( '', $this->order, $sent_to_admin ); // done
874 $shortcode['[yaymail_items_border_content]'] = $this->itemsBorderContent( '', $this->order, $sent_to_admin ); // done
875 $shortcode['[yaymail_get_heading]'] = $this->getHeading( $args, $this->order, $sent_to_admin, array() );
876
877 // WC HOOK
878 $shortcode['[woocommerce_email_order_meta]'] = $this->woocommerceEmailOrderMeta( $args, $sent_to_admin ); // not Changed
879 $shortcode['[woocommerce_email_order_details]'] = $this->woocommerceEmailOrderDetails( $args, $sent_to_admin ); // not Changed
880 $shortcode['[woocommerce_email_before_order_table]'] = $this->woocommerceEmailBeforeOrderTable( $args, $sent_to_admin ); // not Changed
881 $shortcode['[woocommerce_email_after_order_table]'] = $this->woocommerceEmailAfterOrderTable( $args, $sent_to_admin ); // not Changed
882
883 $shortcode['[yaymail_billing_shipping_address]'] = $this->billingShippingAddress( '', $this->order ); // done
884
885 $shortcode['[yaymail_billing_shipping_address_title]'] = $this->billingShippingAddressTitle( '', $this->order ); // done
886 $shortcode['[yaymail_billing_shipping_address_content]'] = $this->billingShippingAddressContent( '', $this->order ); // done
887 $shortcode['[yaymail_check_billing_shipping_address]'] = $this->checkBillingShippingAddress( '', $this->order );
888 $shortcode['[yaymail_order_coupon_codes]'] = $this->orderCouponCodes( '', $this->order );
889
890 //Support shortcode for WooCommerce for LatePoint
891 if ( class_exists( 'TechXelaLatePointPaymentsWooCommerce' ) ) {
892 $shortcode['[yaymail_woo_latepoint_booking_detail]'] = WooLatepoint::wooLatepointBookingDetail( $args, $this->order, $sent_to_admin );
893
894 $shortcode['[yaymail_woo_latepoint_caption]'] = WooLatepoint::wooLatepointCaption( $args, $this->order, $sent_to_admin );
895 $shortcode['[yaymail_woo_latepoint_bg_color]'] = WooLatepoint::wooLatepointBgColor( $args, $this->order, $sent_to_admin );
896 $shortcode['[yaymail_woo_latepoint_text_color]'] = WooLatepoint::wooLatepointTextColor( $args, $this->order, $sent_to_admin );
897 $shortcode['[yaymail_woo_latepoint_font_size]'] = WooLatepoint::wooLatepointFontSize( $args, $this->order, $sent_to_admin );
898 $shortcode['[yaymail_woo_latepoint_border]'] = WooLatepoint::wooLatepointBorder( $args, $this->order, $sent_to_admin );
899 $shortcode['[yaymail_woo_latepoint_border_radius]'] = WooLatepoint::wooLatepointBorderRadius( $args, $this->order, $sent_to_admin );
900 $shortcode['[yaymail_woo_latepoint_margin]'] = WooLatepoint::wooLatepointMargin( $args, $this->order, $sent_to_admin );
901 $shortcode['[yaymail_woo_latepoint_padding]'] = WooLatepoint::wooLatepointPaddings( $args, $this->order, $sent_to_admin );
902 $shortcode['[yaymail_woo_latepoint_css]'] = WooLatepoint::wooLatepointCss( $args, $this->order, $sent_to_admin );
903 $shortcode['[yaymail_woo_latepoint_show_locations]'] = WooLatepoint::wooLatepointShowLocations( $args, $this->order, $sent_to_admin );
904 $shortcode['[yaymail_woo_latepoint_show_agents]'] = WooLatepoint::wooLatepointShowAgents( $args, $this->order, $sent_to_admin );
905 $shortcode['[yaymail_woo_latepoint_show_services]'] = WooLatepoint::wooLatepointShowServices( $args, $this->order, $sent_to_admin );
906 $shortcode['[yaymail_woo_latepoint_show_service_categories]'] = WooLatepoint::wooLatepointShowServiceCategories( $args, $this->order, $sent_to_admin );
907
908 $shortcode['[yaymail_woo_latepoint_selected_location]'] = WooLatepoint::wooLatepointSelectedLocation( $args, $this->order, $sent_to_admin );
909 $shortcode['[yaymail_woo_latepoint_selected_agent]'] = WooLatepoint::wooLatepointSelectedAgent( $args, $this->order, $sent_to_admin );
910 $shortcode['[yaymail_woo_latepoint_selected_service]'] = WooLatepoint::wooLatepointSelectedService( $args, $this->order, $sent_to_admin );
911 $shortcode['[yaymail_woo_latepoint_selected_service_category]'] = WooLatepoint::wooLatepointSelectedServiceCategory( $args, $this->order, $sent_to_admin );
912 $shortcode['[yaymail_woo_latepoint_selected_duration]'] = WooLatepoint::wooLatepointSelectedDuration( $args, $this->order, $sent_to_admin );
913 $shortcode['[yaymail_woo_latepoint_selected_total_attendees]'] = WooLatepoint::wooLatepointSelectedTotalAttendees( $args, $this->order, $sent_to_admin );
914
915 $shortcode['[yaymail_woo_latepoint_calendar_start_date]'] = WooLatepoint::wooLatepointCalendarStartDate( $args, $this->order, $sent_to_admin );
916 $shortcode['[yaymail_woo_latepoint_hide_side_panel]'] = WooLatepoint::wooLatepointHideSidePanel( $args, $this->order, $sent_to_admin );
917 $shortcode['[yaymail_woo_latepoint_hide_summary]'] = WooLatepoint::wooLatepointHideSummary( $args, $this->order, $sent_to_admin );
918 }
919
920 if ( class_exists( '\JET_ABAF\WC_Integration' ) ) {
921 $shortcode['[yaymail_jet_booking_details]'] = $this->jetBookingDetails( $args, $this->order, $sent_to_admin );
922 }
923
924 $this->order_data = array_merge( $this->order_data, $shortcode );
925 }
926
927 public function collectOrderData( $sent_to_admin = '', $args = array() ) {
928 $shortcode = array();
929 $order = $this->order;
930 if ( empty( $this->order_id ) || empty( $order ) ) {
931 return false;
932 }
933
934 // Getting Fee & Refunds:
935 $fee = 0;
936 $refund = 0;
937 $totals = $order->get_order_item_totals();
938 foreach ( $totals as $index => $value ) {
939 if ( strpos( $index, 'fee' ) !== false ) {
940 $fees = $order->get_fees();
941 foreach ( $fees as $feeVal ) {
942 if ( method_exists( $feeVal, 'get_amount' ) ) {
943 $fee += (float) $feeVal->get_amount();
944 }
945 }
946 }
947 if ( strpos( $index, 'refund' ) !== false ) {
948 $refund = $order->get_total_refunded();
949 }
950 }
951 // User Info
952 $user_data = $order->get_user();
953 $created_date = $order->get_date_created();
954 $items = $order->get_items();
955 $yaymail_settings = get_option( 'yaymail_settings' );
956 $order_url = $order->get_edit_order_url();
957 // if ( class_exists( 'Flexible_Checkout_Fields_Disaplay_Options' ) ) {
958 // add_action(
959 // 'woocommerce_email_customer_details',
960 // function( $order ) {
961 // if ( 'Shortcodes.php' === basename( __FILE__ ) ) {
962 // $this->shipping_address = $order->get_formatted_shipping_address();
963 // $this->billing_address = $order->get_formatted_billing_address();
964 // }
965 // },
966 // 100,
967 // 1
968 // );
969 // ob_start();
970 // do_action( 'woocommerce_email_customer_details', $order );
971 // $delete_write = ob_get_contents();
972 // ob_end_clean();
973 // }
974 $this->shipping_address = $order->get_formatted_shipping_address();
975 $this->billing_address = $order->get_formatted_billing_address();
976 $shipping_address = class_exists( 'Flexible_Checkout_Fields_Disaplay_Options' ) ? $this->shipping_address : $order->get_formatted_shipping_address();
977 $billing_address = class_exists( 'Flexible_Checkout_Fields_Disaplay_Options' ) ? $this->billing_address : $order->get_formatted_billing_address();
978 $postID = CustomPostType::postIDByTemplate( $this->template );
979 $yaymail_informations = Helper::inforShortcode( $postID, $this->template, $order );
980
981 $text_link_color = get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) ? get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) : '#7f54b3';
982 if ( $order->get_billing_phone() ) {
983 $billing_address .= "<br/> <a href='tel:" . esc_html( $order->get_billing_phone() ) . "' style='color:" . esc_attr( $text_link_color ) . "; font-weight: normal; text-decoration: underline;'>" . esc_html( $order->get_billing_phone() ) . '</a>';
984 }
985 if ( $order->get_billing_email() ) {
986 $billing_address .= "<br/><a href='mailto:" . esc_html( $order->get_billing_email() ) . "' style='color:" . esc_attr( $text_link_color ) . ";font-weight: normal; text-decoration: underline;'>" . esc_html( $order->get_billing_email() ) . '</a>';
987 }
988 $customerNotes = $order->get_customer_order_notes();
989 $customerNoteHtmlList = '';
990 $customerNoteHtml = $customerNoteHtmlList;
991 if ( ! empty( $customerNotes ) && count( $customerNotes ) ) {
992 $customerNoteHtmlList = $this->getOrderCustomerNotes( $customerNotes );
993 $customerNote_single[] = $customerNotes[0];
994 $customerNoteHtml = $this->getOrderCustomerNotes( $customerNote_single );
995 }
996
997 $resetURL = '';
998 if ( isset( $args['email']->reset_key ) && ! empty( $args['email']->reset_key )
999 && isset( $args['email']->user_login ) && ! empty( $args['email']->user_login )
1000 ) {
1001 $user = new \WP_User( intval( $args['email']->user_id ) );
1002 $reset_key = get_password_reset_key( $user );
1003 $resetURL = esc_url(
1004 add_query_arg(
1005 array(
1006 'key' => $reset_key,
1007 'login' => rawurlencode( $args['email']->user_login ),
1008 ),
1009 wc_get_endpoint_url( 'lost-password', '', wc_get_page_permalink( 'myaccount' ) )
1010 )
1011 );
1012 }
1013
1014 if ( null != $created_date ) {
1015 $shortcode['[yaymail_order_date]'] = $order->get_date_created()->date_i18n( wc_date_format() );
1016 } else {
1017 $shortcode['[yaymail_order_date]'] = '';
1018 }
1019 $shortcode['[yaymail_order_fee]'] = $fee;
1020 if ( ! empty( $order->get_id() ) ) {
1021 if ( $this->sent_to_admin ) {
1022 $shortcode['[yaymail_order_id]'] = '<a class="yaymail-order-id" href="' . esc_url( $order_url ) . '" style="color:' . esc_attr( $text_link_color ) . ';">' . $order->get_id() . '</a>';
1023 } else {
1024 $shortcode['[yaymail_order_id]'] = $order->get_id();
1025 }
1026 } else {
1027 $shortcode['[yaymail_order_id]'] = '';
1028 }
1029 $shortcode['[yaymail_order_link]'] = '<a href="' . esc_url( $order_url ) . '" style="color:' . esc_attr( $text_link_color ) . ';">' . esc_html__( 'Order', 'yaymail' ) . '</a>';
1030 $shortcode['[yaymail_order_link]'] = str_replace( '[yaymail_order_id]', $order->get_id(), $shortcode['[yaymail_order_link]'] );
1031 $shortcode['[yaymail_order_link_string]'] = esc_url( $order_url );
1032 if ( ! empty( $order->get_order_number() ) ) {
1033 if ( $this->sent_to_admin ) {
1034 $shortcode['[yaymail_order_number]'] = '<a class="yaymail-order-id" href="' . esc_url( $order_url ) . '" style="color:' . esc_attr( $text_link_color ) . ';">' . $order->get_order_number() . '</a>';
1035 } else {
1036 $shortcode['[yaymail_order_number]'] = $order->get_order_number();
1037 }
1038 }
1039 $shortcode['[yaymail_order_refund]'] = $refund;
1040 if ( isset( $totals['cart_subtotal']['value'] ) ) {
1041 $shortcode['[yaymail_order_sub_total]'] = $totals['cart_subtotal']['value'];
1042 } else {
1043 $shortcode['[yaymail_order_sub_total]'] = '';
1044 }
1045
1046 if ( isset( $totals['discount']['value'] ) ) {
1047 $shortcode['[yaymail_order_discount]'] = $totals['discount']['value'];
1048 }
1049
1050 $shortcode['[yaymail_order_total]'] = wc_price( $order->get_total() );
1051 $shortcode['[yaymail_order_total_numbers]'] = $order->get_total();
1052 $shortcode['[yaymail_orders_count]'] = count( $order->get_items() );
1053 $shortcode['[yaymail_quantity_count]'] = $order->get_item_count();
1054 $shortcode['[yaymail_orders_count_double]'] = count( $order->get_items() ) * 2;
1055
1056 // PAYMENTS
1057 if ( isset( $totals['payment_method']['value'] ) ) {
1058 $shortcode['[yaymail_order_payment_method]'] = $totals['payment_method']['value'];
1059 } else {
1060 $shortcode['[yaymail_order_payment_method]'] = '';
1061 }
1062 $shortcode['[yaymail_order_payment_url]'] = '<a href="' . esc_url( $order->get_checkout_payment_url() ) . '">' . esc_html__( 'Payment page', 'yaymail' ) . '</a>';
1063 $shortcode['[yaymail_order_payment_url_string]'] = esc_url( $order->get_checkout_payment_url() );
1064 $shortcode['[yaymail_payment_instruction]'] = $this->orderPaymentInstructions( $this->order, $sent_to_admin );
1065 foreach ( $order->get_items( 'tax' ) as $item_id => $item_tax ) {
1066 $tax_rate_id = $item_tax->get_rate_id();
1067
1068 $shortcode_order_taxes = '[yaymail_order_taxes_' . $tax_rate_id . ']';
1069 $tax_amount_total = $item_tax->get_tax_total(); // Tax rate total
1070 $tax_shipping_total = $item_tax->get_shipping_tax_total(); // Tax shipping total
1071 $totals_taxes = $tax_amount_total + $tax_shipping_total;
1072
1073 $shortcode[ $shortcode_order_taxes ] = wc_price( $totals_taxes );
1074 }
1075 if ( ! empty( $order->get_payment_method_title() ) ) {
1076 $shortcode['[yaymail_payment_method]'] = $order->get_payment_method_title();
1077 } else {
1078 $shortcode['[yaymail_payment_method]'] = '';
1079 }
1080 if ( ! empty( $order->get_transaction_id() ) ) {
1081 $shortcode['[yaymail_transaction_id]'] = $order->get_transaction_id();
1082 } else {
1083 $shortcode['[yaymail_transaction_id]'] = '';
1084 }
1085
1086 // SHIPPINGS
1087 if ( isset( $order->get_data()['shipping_total'] ) && ! empty( $order->get_data()['shipping_total'] ) ) {
1088 $shortcode['[yaymail_order_shipping]'] = $order->get_data()['shipping_total'];
1089 } else {
1090 $shortcode['[yaymail_order_shipping]'] = 0;
1091 }
1092 $shortcode['[yaymail_shipping_address]'] = $shipping_address;
1093 if ( ! empty( $order->get_shipping_address_1() ) ) {
1094 $shortcode['[yaymail_shipping_address_1]'] = $order->get_shipping_address_1();
1095 } else {
1096 $shortcode['[yaymail_shipping_address_1]'] = '';
1097 }
1098 if ( ! empty( $order->get_shipping_address_2() ) ) {
1099 $shortcode['[yaymail_shipping_address_2]'] = $order->get_shipping_address_2();
1100 } else {
1101 $shortcode['[yaymail_shipping_address_2]'] = '';
1102 }
1103 if ( ! empty( $order->get_shipping_city() ) ) {
1104 $shortcode['[yaymail_shipping_city]'] = $order->get_shipping_city();
1105 } else {
1106 $shortcode['[yaymail_shipping_city]'] = '';
1107 }
1108 if ( ! empty( $order->get_shipping_company() ) ) {
1109 $shortcode['[yaymail_shipping_company]'] = $order->get_shipping_company();
1110 } else {
1111 $shortcode['[yaymail_shipping_company]'] = '';
1112 }
1113 if ( ! empty( $order->get_shipping_country() ) ) {
1114 $country_code_bym = $order->get_shipping_country();
1115 $wc_countries = WC()->countries;
1116 $shipping_country_name_bym = $wc_countries->countries[ $country_code_bym ];
1117 $shortcode['[yaymail_shipping_country]'] = $shipping_country_name_bym;
1118 } else {
1119 $shortcode['[yaymail_shipping_country]'] = '';
1120 }
1121 if ( ! empty( $order->get_shipping_first_name() ) ) {
1122 $shortcode['[yaymail_shipping_first_name]'] = $order->get_shipping_first_name();
1123 } else {
1124 $shortcode['[yaymail_shipping_first_name]'] = '';
1125
1126 }
1127 if ( ! empty( $order->get_shipping_last_name() ) ) {
1128 $shortcode['[yaymail_shipping_last_name]'] = $order->get_shipping_last_name();
1129 } else {
1130 $shortcode['[yaymail_shipping_last_name]'] = '';
1131
1132 }
1133 if ( ! empty( $order->get_shipping_method() ) ) {
1134 $shortcode['[yaymail_shipping_method]'] = $order->get_shipping_method();
1135 } else {
1136 $shortcode['[yaymail_shipping_method]'] = '';
1137 }
1138 if ( ! empty( $order->get_shipping_postcode() ) ) {
1139 $shortcode['[yaymail_shipping_postcode]'] = $order->get_shipping_postcode();
1140 } else {
1141 $shortcode['[yaymail_shipping_postcode]'] = '';
1142 }
1143 if ( ! empty( $order->get_shipping_state() ) ) {
1144 $shortcode['[yaymail_shipping_state]'] = $order->get_shipping_state();
1145 } else {
1146 $shortcode['[yaymail_shipping_state]'] = '';
1147 }
1148 if ( method_exists( $order, 'get_shipping_phone' ) && ! empty( $order->get_shipping_phone() ) ) {
1149 $shortcode['[yaymail_shipping_phone]'] = $order->get_shipping_phone();
1150 } else {
1151 $shortcode['[yaymail_shipping_phone]'] = '';
1152 }
1153
1154 // BILLINGS
1155 $shortcode['[yaymail_billing_address]'] = $billing_address;
1156 if ( ! empty( $order->get_billing_address_1() ) ) {
1157 $shortcode['[yaymail_billing_address_1]'] = $order->get_billing_address_1();
1158 } else {
1159 $shortcode['[yaymail_billing_address_1]'] = '';
1160 }
1161 if ( ! empty( $order->get_billing_address_2() ) ) {
1162 $shortcode['[yaymail_billing_address_2]'] = $order->get_billing_address_2();
1163 } else {
1164 $shortcode['[yaymail_billing_address_2]'] = '';
1165 }
1166 if ( ! empty( $order->get_billing_city() ) ) {
1167 $shortcode['[yaymail_billing_city]'] = $order->get_billing_city();
1168 } else {
1169 $shortcode['[yaymail_billing_city]'] = $order->get_billing_city();
1170 }
1171 if ( ! empty( $order->get_billing_company() ) ) {
1172 $shortcode['[yaymail_billing_company]'] = $order->get_billing_company();
1173 } else {
1174 $shortcode['[yaymail_billing_company]'] = '';
1175 }
1176 if ( ! empty( $order->get_billing_country() ) ) {
1177 $country_code_bym = $order->get_billing_country();
1178 $wc_countries = WC()->countries;
1179 $billing_country_name_bym = $wc_countries->countries[ $country_code_bym ];
1180 $shortcode['[yaymail_billing_country]'] = $billing_country_name_bym;
1181 } else {
1182 $shortcode['[yaymail_billing_country]'] = '';
1183 }
1184 if ( ! empty( $order->get_billing_email() ) ) {
1185 $shortcode['[yaymail_billing_email]'] = '<a style="color: inherit" href="mailto:' . $order->get_billing_email() . '">' . $order->get_billing_email() . '</a>';
1186 } else {
1187 $shortcode['[yaymail_billing_email]'] = '';
1188 }
1189 if ( ! empty( $order->get_billing_first_name() ) ) {
1190 $shortcode['[yaymail_billing_first_name]'] = $order->get_billing_first_name();
1191 } else {
1192 $shortcode['[yaymail_billing_first_name]'] = '';
1193 }
1194 if ( ! empty( $order->get_billing_last_name() ) ) {
1195 $shortcode['[yaymail_billing_last_name]'] = $order->get_billing_last_name();
1196 } else {
1197 $shortcode['[yaymail_billing_last_name]'] = '';
1198 }
1199 if ( ! empty( $order->get_billing_phone() ) ) {
1200 $shortcode['[yaymail_billing_phone]'] = $order->get_billing_phone();
1201 } else {
1202 $shortcode['[yaymail_billing_phone]'] = '';
1203 }
1204 if ( ! empty( $order->get_billing_postcode() ) ) {
1205 $shortcode['[yaymail_billing_postcode]'] = $order->get_billing_postcode();
1206 } else {
1207 $shortcode['[yaymail_billing_postcode]'] = '';
1208 }
1209 if ( ! empty( $order->get_billing_state() ) ) {
1210 $shortcode['[yaymail_billing_state]'] = $order->get_billing_state();
1211 } else {
1212 $shortcode['[yaymail_billing_state]'] = '';
1213 }
1214
1215 // Reset Passwords
1216 $shortcode['[yaymail_password_reset_url]'] = '<a style="color: ' . esc_attr( $text_link_color ) . ';" href="' . esc_url( $resetURL ) . '">' . esc_html__( 'Click here to reset your password', 'woocommerce' ) . '</a>';
1217 $shortcode['[yaymail_password_reset_url_string]'] = esc_url( $resetURL );
1218
1219 // New Users
1220 if ( isset( $args['email']->user_pass ) && ! empty( $args['email']->user_pass ) ) {
1221 $shortcode['[yaymail_user_new_password]'] = $args['email']->user_pass;
1222 } else {
1223 if ( isset( $_REQUEST['pass1-text'] ) && '' != $_REQUEST['pass1-text'] ) {
1224 $shortcode['[yaymail_user_new_password]'] = sanitize_text_field( $_REQUEST['pass1-text'] );
1225 } elseif ( isset( $_REQUEST['pass1'] ) && '' != $_REQUEST['pass1'] ) {
1226 $shortcode['[yaymail_user_new_password]'] = sanitize_text_field( $_REQUEST['pass1'] );
1227 } else {
1228 $shortcode['[yaymail_user_new_password]'] = '';
1229 }
1230 }
1231 // Review this code ??
1232 if ( isset( $args['email']->user_activation_url ) && ! empty( $args['email']->user_activation_url ) ) {
1233 $shortcode['[yaymail_user_activation_link]'] = $args['email']->user_activation_url;
1234 } else {
1235 $shortcode['[yaymail_user_activation_link]'] = '';
1236 }
1237
1238 // GENERALS
1239 $shortcode['[yaymail_customer_note]'] = ( $customerNoteHtml ); // add strip_tags() to remove link
1240 $shortcode['[yaymail_customer_notes]'] = $customerNoteHtmlList;
1241 if ( ! empty( $order->get_customer_note() ) ) {
1242 $shortcode['[yaymail_customer_provided_note]'] = $order->get_customer_note();
1243 } else {
1244 $shortcode['[yaymail_customer_provided_note]'] = '';
1245 }
1246 $shortcode['[yaymail_site_name]'] = esc_html( get_bloginfo( 'name' ) );
1247 $shortcode['[yaymail_site_url]'] = '<a style="color: ' . esc_attr( $text_link_color ) . ';" href="' . esc_url( get_home_url() ) . '"> ' . esc_url( get_home_url() ) . ' </a>';
1248 $shortcode['[yaymail_site_url_string]'] = esc_url( get_home_url() );
1249 if ( isset( $user_data->user_email ) ) {
1250 $shortcode['[yaymail_user_email]'] = $user_data->user_email;
1251 } else {
1252 $shortcode['[yaymail_user_email]'] = $order->get_billing_email();
1253 }
1254 if ( isset( $shortcode['[yaymail_user_email]'] ) && '' != $shortcode['[yaymail_user_email]'] ) {
1255 $user = get_user_by( 'email', $shortcode['[yaymail_user_email]'] );
1256 $shortcode['[yaymail_user_id]'] = ( isset( $user->ID ) ) ? $user->ID : '';
1257 }
1258 if ( isset( $user_data->user_login ) && ! empty( $user_data->user_login ) ) {
1259 $shortcode['[yaymail_customer_username]'] = $user_data->user_login;
1260 } elseif ( isset( $user_data->user_nicename ) ) {
1261 $shortcode['[yaymail_customer_username]'] = $user_data->user_nicename;
1262 } else {
1263 $shortcode['[yaymail_customer_username]'] = $order->get_billing_first_name();
1264 }
1265 if ( isset( $user_data->roles ) && ! empty( $user_data->roles ) ) {
1266 $shortcode['[yaymail_customer_roles]'] = implode( ', ', $user_data->roles );
1267 }
1268 if ( isset( $user->ID ) && ! empty( $user->ID ) ) {
1269 $shortcode['[yaymail_customer_name]'] = get_user_meta( $user->ID, 'first_name', true ) . ' ' . get_user_meta( $user->ID, 'last_name', true );
1270 $shortcode['[yaymail_customer_first_name]'] = get_user_meta( $user->ID, 'first_name', true );
1271 $shortcode['[yaymail_customer_last_name]'] = get_user_meta( $user->ID, 'last_name', true );
1272 } elseif ( isset( $user_data->user_nicename ) ) {
1273 $shortcode['[yaymail_customer_name]'] = $user_data->user_nicename;
1274 } else {
1275 $shortcode['[yaymail_customer_name]'] = $order->get_billing_first_name() . ' ' . $order->get_billing_last_name();
1276 }
1277 if ( ! empty( $order->get_view_order_url() ) ) {
1278 $text_your_order = esc_html__( 'Your Order', 'yaymail' );
1279 $shortcode['[yaymail_view_order_url]'] = '<a href="' . esc_url( $order->get_view_order_url() ) . '" style="color:' . esc_attr( $text_link_color ) . ';">' . esc_html( $text_your_order ) . '</a>';
1280 $shortcode['[yaymail_view_order_url_string]'] = $order->get_view_order_url();
1281 } else {
1282 $shortcode['[yaymail_view_order_url]'] = '';
1283 }
1284
1285 if ( ! empty( parse_url( get_site_url() )['host'] ) ) {
1286 $shortcode['[yaymail_domain]'] = parse_url( get_site_url() )['host'];
1287 } else {
1288 $shortcode['[yaymail_domain]'] = '';
1289 }
1290
1291 $shortcode['[yaymail_user_account_url]'] = '<a style="color:' . esc_attr( $text_link_color ) . '; font-weight: normal; text-decoration: underline;" href="' . esc_url( wc_get_page_permalink( 'myaccount' ) ) . '">' . esc_url( wc_get_page_permalink( 'myaccount' ) ) . '</a>';
1292 $shortcode['[yaymail_user_account_url_string]'] = esc_url( wc_get_page_permalink( 'myaccount' ) );
1293
1294 // ADDITIONAL ORDER META:
1295 $order_metaArr = get_post_meta( $this->order_id );
1296 if ( is_array( $order_metaArr ) && count( $order_metaArr ) > 0 ) {
1297 foreach ( $order_metaArr as $k => $v ) {
1298 $nameField = str_replace( ' ', '_', trim( $k ) );
1299 $nameShorcode = '[yaymail_post_meta:' . $nameField . ']';
1300
1301 // when array $v has tow value ???
1302 if ( is_array( $v ) && count( $v ) > 0 ) {
1303 $shortcode[ $nameShorcode ] = trim( $v[0] );
1304 } else {
1305 $shortcode[ $nameShorcode ] = trim( $v );
1306 }
1307 }
1308 }
1309
1310 /*
1311 To get custom fields support Checkout Field Editor for WooCommerce */
1312 // funtion wc_get_custom_checkout_fields of Plugin Checkout Field Editor ????
1313 if ( ! empty( $order ) ) {
1314 if ( function_exists( 'wc_get_custom_checkout_fields' ) ) {
1315 $custom_fields = wc_get_custom_checkout_fields( $order );
1316 if ( ! empty( $custom_fields ) ) {
1317 foreach ( $custom_fields as $key => $custom_field ) {
1318 $shortcode[ '[yaymail_' . $key . ']' ] = get_post_meta( $order->get_id(), $key, true );
1319 }
1320 }
1321 }
1322 }
1323 if ( ! empty( $order ) ) {
1324 foreach ( $order->get_meta_data() as $meta ) {
1325 $nameField = str_replace( ' ', '_', trim( $meta->get_data()['key'] ) );
1326 $nameShorcode = '[yaymail_order_meta:' . $nameField . ']';
1327 if ( '_local_pickup_time_select' == $nameField ) {
1328 $plugin = \Local_Pickup_Time::get_instance();
1329 $shortcode[ $nameShorcode ] = $plugin->pickup_time_select_translatable( $meta->get_data()['value'] );
1330 } else {
1331 if ( is_array( $meta->get_data()['value'] ) ) {
1332 $checkNestedArray = false;
1333 foreach ( $meta->get_data()['value'] as $value ) {
1334 if ( is_object( $value ) || is_array( $value ) ) {
1335 $checkNestedArray = true;
1336 break;
1337 }
1338 }
1339 if ( false == $checkNestedArray ) {
1340 if ( isset( $meta->get_data()['value']['extra'] ) ) {
1341 $shortcode[ $nameShorcode ] = str_replace( '|', '<br />', $meta->get_data()['value']['extra'] );
1342 } else {
1343 $shortcode[ $nameShorcode ] = str_replace( '|', '<br />', implode( ', ', $meta->get_data()['value'] ) );
1344 }
1345 } else {
1346 $shortcode[ $nameShorcode ] = '';
1347 if ( class_exists( 'WCPFC_Country' ) ) {
1348 $arr_values = \wcpfc_get_value_if_set( $meta->get_data(), array( 'value', 'value' ), '' );
1349 if ( is_object( $arr_values ) || is_array( $arr_values ) ) {
1350 $shortcode[ $nameShorcode ] = implode( ',', $arr_values );
1351 } else {
1352 $shortcode[ $nameShorcode ] = $arr_values;
1353 }
1354 }
1355 }
1356 } else {
1357 if ( is_string( $meta->get_data()['value'] ) ) {
1358 $value = $meta->get_data()['value'];
1359 $time = strtotime( $value );
1360 if ( $time ) {
1361 $date = \DateTime::createFromFormat( 'Y-m-d', $value );
1362 if ( $date ) {
1363 $date_format = date_i18n( wc_date_format(), $date->getTimestamp() );
1364 $shortcode[ $nameShorcode ] = $date_format;
1365 } else {
1366 $shortcode[ $nameShorcode ] = nl2br( $value );
1367 }
1368 } else {
1369 $shortcode[ $nameShorcode ] = nl2br( $value );
1370 }
1371 } else {
1372 $shortcode[ $nameShorcode ] = $meta->get_data()['value'];
1373 }
1374 }
1375 }
1376 }
1377 }
1378
1379 $shortcode['[yaymail_items]'] = $this->orderItems( $items, $sent_to_admin, '', true );
1380 $shortcode['[yaymail_items_products_quantity_price]'] = $this->orderItems( $items, $sent_to_admin, '', false );
1381
1382 // Define shortcode from plugin addon
1383 $shortcode = apply_filters( 'yaymail_do_shortcode', $shortcode, $yaymail_informations, $this->args_email );
1384 // Define customs shortcode for user
1385 $shortcode = apply_filters( 'yaymail_customs_shortcode', $shortcode, $yaymail_informations, $this->args_email );
1386
1387 $this->order_data = $shortcode;
1388 }
1389
1390 public function defaultSampleOrderData( $sent_to_admin = '' ) {
1391 $current_user = wp_get_current_user();
1392 $postID = CustomPostType::postIDByTemplate( $this->template );
1393 $text_link_color = get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) ? get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) : '#7f54b3';
1394 $billing_address = "John Doe<br/>YayCommerce<br/>7400 Edwards Rd<br/>Edwards Rd<br/><a href='tel:+18587433828' style='color: " . esc_attr( $text_link_color ) . "; font-weight: normal; text-decoration: underline;'>(910) 529-1147</a><br/>";
1395 $shipping_address = "John Doe<br/>YayCommerce<br/>755 E North Grove Rd<br/>Mayville, Michigan<br/><a href='tel:+18587433828' style='color: " . esc_attr( $text_link_color ) . "; font-weight: normal; text-decoration: underline;'>(910) 529-1147</a><br/>";
1396 $user_id = get_current_user_id();
1397 $yaymail_settings = get_option( 'yaymail_settings' );
1398 $yaymail_informations = Helper::inforShortcode( $postID, $this->template, array() );
1399
1400 // Link Downloadable Product
1401 $shortcode['[yaymail_items_downloadable_title]'] = $this->itemsDownloadableTitle( '', $this->order, $sent_to_admin, '' ); // done
1402 $shortcode['[yaymail_items_downloadable_product]'] = $this->itemsDownloadableProduct( '', $this->order, $sent_to_admin, '' ); // done
1403
1404 // ORDER DETAILS
1405 $shortcode['[yaymail_items_border]'] = $this->itemsBorder( '', $this->order, $sent_to_admin ); // done
1406
1407 $shortcode['[yaymail_items_border_before]'] = $this->itemsBorderBefore( '', $this->order, $sent_to_admin ); // done
1408 $shortcode['[yaymail_items_border_after]'] = $this->itemsBorderAfter( '', $this->order, $sent_to_admin ); // done
1409 $shortcode['[yaymail_items_border_title]'] = $this->itemsBorderTitle( '', 'sampleOrder', $sent_to_admin ); // done
1410 $shortcode['[yaymail_items_border_content]'] = $this->itemsBorderContent( '', 'sampleOrder', $sent_to_admin ); // done
1411 $shortcode['[yaymail_get_heading]'] = $this->getHeading( '', $this->order, $sent_to_admin, array() );
1412
1413 // WC HOOK
1414 $shortcode['[woocommerce_email_order_meta]'] = $this->woocommerceEmailOrderMeta( array(), $sent_to_admin, 'sampleOrder' ); // not Changed
1415 $shortcode['[woocommerce_email_order_details]'] = $this->woocommerceEmailOrderDetails( array(), $sent_to_admin, 'sampleOrder' ); // not Changed
1416 $shortcode['[woocommerce_email_before_order_table]'] = $this->woocommerceEmailBeforeOrderTable( array(), $sent_to_admin, 'sampleOrder' ); // not changed
1417 $shortcode['[woocommerce_email_after_order_table]'] = $this->woocommerceEmailAfterOrderTable( array(), $sent_to_admin, 'sampleOrder' ); // not changed
1418
1419 // Define shortcode from plugin addon
1420 $shortcode = apply_filters( 'yaymail_do_shortcode', $shortcode, $yaymail_informations, '' );
1421 // Define customs shortcode for user
1422 $shortcode = apply_filters( 'yaymail_customs_shortcode', $shortcode, $yaymail_informations, '' );
1423
1424 $shortcode['[yaymail_items]'] = $this->orderItems( array(), $sent_to_admin, 'sampleOrder', true );
1425 $shortcode['[yaymail_items_products_quantity_price]'] = $this->orderItems( array(), $sent_to_admin, 'sampleOrder', false );
1426 $shortcode['[yaymail_order_date]'] = date_i18n( wc_date_format() );
1427 $shortcode['[yaymail_order_fee]'] = 0;
1428 $shortcode['[yaymail_order_id]'] = 1;
1429 $shortcode['[yaymail_order_link]'] = '<a href="" style="color:' . esc_attr( $text_link_color ) . ';">' . esc_html__( 'Order', 'yaymail' ) . '</a>';
1430 $shortcode['[yaymail_order_link_string]'] = esc_url( get_home_url() );
1431 $shortcode['[yaymail_order_number]'] = '1';
1432 $shortcode['[yaymail_order_refund]'] = 0;
1433 $shortcode['[yaymail_order_sub_total]'] = wc_price( '18.00' );
1434 $shortcode['[yaymail_order_discount]'] = wc_price( '18.00' );
1435 $shortcode['[yaymail_order_total]'] = wc_price( '18.00' );
1436 $shortcode['[yaymail_order_total_numbers]'] = '18.00';
1437 $shortcode['[yaymail_orders_count]'] = '1';
1438 $shortcode['[yaymail_quantity_count]'] = '1';
1439 $shortcode['[yaymail_orders_count_double]'] = '2';
1440
1441 // PAYMENTS
1442 $shortcode['[yaymail_order_payment_method]'] = esc_html__( 'Direct bank transfer', 'yaymail' );
1443 $shortcode['[yaymail_order_payment_url]'] = '<a href="">' . esc_html__( 'Payment page', 'yaymail' ) . '</a>';
1444 $shortcode['[yaymail_order_payment_url_string]'] = '';
1445 $shortcode['[yaymail_payment_instruction]'] = __( 'Payment Instructions', 'yaymail' );
1446 $shortcode['[yaymail_payment_method]'] = esc_html__( 'Check payments', 'yaymail' );
1447 $shortcode['[yaymail_transaction_id]'] = 1;
1448
1449 // SHIPPINGS
1450 $shortcode['[yaymail_order_shipping]'] = esc_html__( '333', 'yaymail' );
1451 $shortcode['[yaymail_shipping_address]'] = $shipping_address;
1452 $shortcode['[yaymail_shipping_address_1]'] = esc_html__( '755 E North Grove Rd', 'yaymail' );
1453 $shortcode['[yaymail_shipping_address_2]'] = esc_html__( '755 E North Grove Rd', 'yaymail' );
1454 $shortcode['[yaymail_shipping_city]'] = esc_html__( 'Mayville, Michigan', 'yaymail' );
1455 $shortcode['[yaymail_shipping_company]'] = esc_html__( 'YayCommerce', 'yaymail' );
1456 $shortcode['[yaymail_shipping_country]'] = '';
1457 $shortcode['[yaymail_shipping_first_name]'] = esc_html__( 'John', 'yaymail' );
1458 $shortcode['[yaymail_shipping_last_name]'] = esc_html__( 'John', 'yaymail' );
1459 $shortcode['[yaymail_shipping_method]'] = '';
1460 $shortcode['[yaymail_shipping_postcode]'] = esc_html__( '48744', 'yaymail' );
1461 $shortcode['[yaymail_shipping_state]'] = esc_html__( 'Random', 'yaymail' );
1462 $shortcode['[yaymail_shipping_phone]'] = esc_html__( '(910) 529-1147', 'yaymail' );
1463
1464 // BILLING
1465 $shortcode['[yaymail_billing_address]'] = $billing_address;
1466 $shortcode['[yaymail_billing_address_1]'] = esc_html__( '7400 Edwards Rd', 'yaymail' );
1467 $shortcode['[yaymail_billing_address_2]'] = esc_html__( '7400 Edwards Rd', 'yaymail' );
1468 $shortcode['[yaymail_billing_city]'] = esc_html__( 'Edwards Rd', 'yaymail' );
1469 $shortcode['[yaymail_billing_company]'] = esc_html__( 'YayCommerce', 'yaymail' );
1470 $shortcode['[yaymail_billing_country]'] = '';
1471 $shortcode['[yaymail_billing_email]'] = esc_html__( 'johndoe@gmail.com', 'yaymail' );
1472 $shortcode['[yaymail_billing_first_name]'] = esc_html__( 'John', 'yaymail' );
1473 $shortcode['[yaymail_billing_last_name]'] = esc_html__( 'Doe', 'yaymail' );
1474 $shortcode['[yaymail_billing_phone]'] = esc_html__( '(910) 529-1147', 'yaymail' );
1475 $shortcode['[yaymail_billing_postcode]'] = esc_html__( '48744', 'yaymail' );
1476 $shortcode['[yaymail_billing_state]'] = esc_html__( 'Random', 'yaymail' );
1477
1478 // RESET PASSWORD:
1479 $shortcode['[yaymail_password_reset_url]'] = '<a style="color:' . esc_attr( $text_link_color ) . ';" href="">' . esc_html__( 'Click here to reset your password', 'woocommerce' ) . '</a>';
1480 $shortcode['[yaymail_password_reset_url_string]'] = esc_url( get_home_url() ) . '/my-account/lost-password/?login';
1481 $shortcode['[yaymail_wp_password_reset_url]'] = esc_url( get_home_url() ) . '/my-account/lost-password/?login';
1482
1483 // NEW USERS:
1484 $shortcode['[yaymail_user_new_password]'] = esc_html__( 'G(UAM1(eIX#G', 'yaymail' );
1485 $shortcode['[yaymail_set_password_url_string]'] = esc_url( get_home_url() ) . '/my-account/set-password/';
1486 $shortcode['[yaymail_user_activation_link]'] = '';
1487
1488 // GENERALS
1489 $shortcode['[yaymail_customer_note]'] = esc_html__( 'note', 'yaymail' );
1490 $shortcode['[yaymail_customer_notes]'] = esc_html__( 'notes', 'yaymail' );
1491 $shortcode['[yaymail_customer_provided_note]'] = esc_html__( 'provided note', 'yaymail' );
1492 $shortcode['[yaymail_site_name]'] = esc_html( get_bloginfo( 'name' ) );
1493 $shortcode['[yaymail_site_url]'] = '<a style="color: ' . esc_attr( $text_link_color ) . ';" href="' . esc_url( get_home_url() ) . '"> ' . esc_url( get_home_url() ) . ' </a>';
1494 $shortcode['[yaymail_site_url_string]'] = esc_url( get_home_url() );
1495 $shortcode['[yaymail_user_email]'] = $current_user->data->user_email;
1496 $shortcode['[yaymail_user_id]'] = $user_id;
1497 $shortcode['[yaymail_customer_username]'] = $current_user->data->user_login;
1498 $shortcode['[yaymail_customer_roles]'] = implode( ', ', $current_user->roles );
1499 $shortcode['[yaymail_customer_name]'] = get_user_meta( $current_user->data->ID, 'first_name', true ) . ' ' . get_user_meta( $current_user->data->ID, 'last_name', true );
1500 $shortcode['[yaymail_customer_first_name]'] = get_user_meta( $current_user->data->ID, 'first_name', true );
1501 $shortcode['[yaymail_customer_last_name]'] = get_user_meta( $current_user->data->ID, 'last_name', true );
1502 $shortcode['[yaymail_view_order_url]'] = '';
1503 $shortcode['[yaymail_view_order_url_string]'] = '';
1504 $shortcode['[yaymail_billing_shipping_address]'] = $this->billingShippingAddress( '', $this->order ); // done
1505
1506 $shortcode['[yaymail_billing_shipping_address_title]'] = $this->billingShippingAddressTitle( '', $this->order ); // done
1507 $shortcode['[yaymail_billing_shipping_address_content]'] = $this->billingShippingAddressContent( '', $this->order ); // done
1508 $shortcode['[yaymail_check_billing_shipping_address]'] = $this->checkBillingShippingAddress( '', $this->order ); // done
1509
1510 $shortcode['[yaymail_domain]'] = parse_url( get_site_url() )['host'];
1511 $shortcode['[yaymail_user_account_url]'] = '<a style="color:' . esc_attr( $text_link_color ) . '; font-weight: normal; text-decoration: underline;" href="' . esc_url( wc_get_page_permalink( 'myaccount' ) ) . '">' . esc_url( wc_get_page_permalink( 'myaccount' ) ) . '</a>';
1512 $shortcode['[yaymail_user_account_url_string]'] = esc_url( wc_get_page_permalink( 'myaccount' ) );
1513 $shortcode['[yaymail_order_coupon_codes]'] = esc_html__( 'yaymail_code', 'yaymail' );
1514
1515 //Support shortcode for WooCommerce for LatePoint
1516 if ( class_exists( 'TechXelaLatePointPaymentsWooCommerce' ) ) {
1517 $shortcode['[yaymail_woo_latepoint_booking_detail]'] = WooLatepoint::wooLatepointBookingDetail( '', $this->order, false );
1518
1519 $shortcode['[yaymail_woo_latepoint_caption]'] = WooLatepoint::wooLatepointCaption( '', $this->order, false );
1520 $shortcode['[yaymail_woo_latepoint_bg_color]'] = WooLatepoint::wooLatepointBgColor( '', $this->order, false );
1521 $shortcode['[yaymail_woo_latepoint_text_color]'] = WooLatepoint::wooLatepointTextColor( '', $this->order, false );
1522 $shortcode['[yaymail_woo_latepoint_font_size]'] = WooLatepoint::wooLatepointFontSize( '', $this->order, false );
1523 $shortcode['[yaymail_woo_latepoint_border]'] = WooLatepoint::wooLatepointBorder( '', $this->order, false );
1524 $shortcode['[yaymail_woo_latepoint_border_radius]'] = WooLatepoint::wooLatepointBorderRadius( '', $this->order, false );
1525 $shortcode['[yaymail_woo_latepoint_margin]'] = WooLatepoint::wooLatepointMargin( '', $this->order, false );
1526 $shortcode['[yaymail_woo_latepoint_padding]'] = WooLatepoint::wooLatepointPaddings( '', $this->order, false );
1527 $shortcode['[yaymail_woo_latepoint_css]'] = WooLatepoint::wooLatepointCss( '', $this->order, false );
1528 $shortcode['[yaymail_woo_latepoint_show_locations]'] = WooLatepoint::wooLatepointShowLocations( '', $this->order, false );
1529 $shortcode['[yaymail_woo_latepoint_show_agents]'] = WooLatepoint::wooLatepointShowAgents( '', $this->order, false );
1530 $shortcode['[yaymail_woo_latepoint_show_services]'] = WooLatepoint::wooLatepointShowServices( '', $this->order, false );
1531 $shortcode['[yaymail_woo_latepoint_show_service_categories]'] = WooLatepoint::wooLatepointShowServiceCategories( '', $this->order, false );
1532
1533 $shortcode['[yaymail_woo_latepoint_selected_location]'] = WooLatepoint::wooLatepointSelectedLocation( '', $this->order, false );
1534 $shortcode['[yaymail_woo_latepoint_selected_agent]'] = WooLatepoint::wooLatepointSelectedAgent( '', $this->order, false );
1535 $shortcode['[yaymail_woo_latepoint_selected_service]'] = WooLatepoint::wooLatepointSelectedService( '', $this->order, false );
1536 $shortcode['[yaymail_woo_latepoint_selected_service_category]'] = WooLatepoint::wooLatepointSelectedServiceCategory( '', $this->order, false );
1537 $shortcode['[yaymail_woo_latepoint_selected_duration]'] = WooLatepoint::wooLatepointSelectedDuration( '', $this->order, false );
1538 $shortcode['[yaymail_woo_latepoint_selected_total_attendees]'] = WooLatepoint::wooLatepointSelectedTotalAttendees( '', $this->order, false );
1539
1540 $shortcode['[yaymail_woo_latepoint_calendar_start_date]'] = WooLatepoint::wooLatepointCalendarStartDate( '', $this->order, false );
1541 $shortcode['[yaymail_woo_latepoint_hide_side_panel]'] = WooLatepoint::wooLatepointHideSidePanel( '', $this->order, false );
1542 $shortcode['[yaymail_woo_latepoint_hide_summary]'] = WooLatepoint::wooLatepointHideSummary( '', $this->order, false );
1543 }
1544
1545 if ( class_exists( '\JET_ABAF\WC_Integration' ) ) {
1546 $shortcode['[yaymail_jet_booking_details]'] = $this->jetBookingDetails( '', $this->order, false );
1547 }
1548
1549 // ADDITIONAL ORDER META:
1550 $order = CustomPostType::getListOrders();
1551 $order_metaArr = get_post_meta( isset( $order[0]['id'] ) ? $order[0]['id'] : '' );
1552 if ( is_array( $order_metaArr ) && count( $order_metaArr ) > 0 ) {
1553 foreach ( $order_metaArr as $k => $v ) {
1554 $nameField = str_replace( ' ', '_', trim( $k ) );
1555 $nameShorcode = '[yaymail_post_meta:' . $nameField . ']';
1556
1557 // when array $v has tow value ???
1558 if ( is_array( $v ) && count( $v ) > 0 ) {
1559 $shortcode[ $nameShorcode ] = trim( $v[0] );
1560 } else {
1561 $shortcode[ $nameShorcode ] = trim( $v );
1562 }
1563 }
1564 }
1565
1566 $this->order_data = $shortcode;
1567 }
1568
1569 public function ordetItemTables( $order, $default_args ) {
1570 $is_preview = Helper::isPreview( $this->preview_mail );
1571 $postID = CustomPostType::postIDByTemplate( $this->template );
1572 $text_link_color = get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) ? get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) : '#7f54b3';
1573 $items = $order->get_items();
1574 if ( $is_preview ) {
1575 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-order-items-preview.php';
1576 } else {
1577 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-order-items.php';
1578 }
1579
1580 $yaymail_settings = get_option( 'yaymail_settings' );
1581
1582 $show_product_image = isset( $yaymail_settings['product_image'] ) ? $yaymail_settings['product_image'] : 0;
1583 $show_product_sku = isset( $yaymail_settings['product_sku'] ) ? $yaymail_settings['product_sku'] : 0;
1584 $show_product_des = isset( $yaymail_settings['product_des'] ) ? $yaymail_settings['product_des'] : 0;
1585 $default_args['image_size'][0] = isset( $yaymail_settings['image_width'] ) ? $yaymail_settings['image_width'] : 32;
1586 $default_args['image_size'][1] = isset( $yaymail_settings['image_height'] ) ? $yaymail_settings['image_height'] : 32;
1587 $default_args['image_size'][2] = isset( $yaymail_settings['image_size'] ) ? $yaymail_settings['image_size'] : 'thumbnail';
1588
1589 $args = array(
1590 'order' => $order,
1591 'items' => $order->get_items(),
1592 'show_download_links' => $order->is_download_permitted() && ! $default_args['sent_to_admin'],
1593 'show_sku' => $show_product_sku,
1594 'show_des' => $show_product_des,
1595 'show_purchase_note' => $order->is_paid() && ! $default_args['sent_to_admin'],
1596 'show_image' => $show_product_image,
1597 'image_size' => $default_args['image_size'],
1598 'plain_text' => $default_args['plain_text'],
1599 'sent_to_admin' => $default_args['sent_to_admin'],
1600 'order_item_table_border_color' => isset( $yaymail_settings['background_color_table_items'] ) ? $yaymail_settings['background_color_table_items'] : '#dddddd',
1601 'text_link_color' => $text_link_color,
1602 );
1603 include apply_filters( 'yaymail_get_template', $path );
1604 }
1605 public function itemsBorder( $atts, $order, $sent_to_admin = '' ) {
1606 if ( null === $order ) {
1607 ob_start();
1608 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/sampleOrder/email-order-details-border.php';
1609 include $path;
1610 $html = ob_get_contents();
1611 ob_end_clean();
1612 return $html;
1613 } else {
1614 ob_start();
1615 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-order-details-border.php';
1616 include $path;
1617 $html = ob_get_contents();
1618 ob_end_clean();
1619 return $html;
1620 }
1621
1622 }
1623
1624 /* Link Downloadable Product - start */
1625 public function itemsDownloadableTitle( $atts, $order, $sent_to_admin = '', $items = array() ) {
1626 if ( null !== $order ) {
1627 $items = $order->get_items();
1628 $downloads = $order->get_downloadable_items();
1629 }
1630 ob_start();
1631 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-order-item-download-title.php';
1632 include $path;
1633 $html = ob_get_contents();
1634 ob_end_clean();
1635 return $html;
1636 }
1637 public function itemsDownloadableProduct( $atts, $order, $sent_to_admin = '', $items = array() ) {
1638 if ( null === $order ) {
1639 ob_start();
1640 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/sampleOrder/email-order-item-download.php';
1641 include $path;
1642 $html = ob_get_contents();
1643 ob_end_clean();
1644 return $html;
1645 } else {
1646 if ( class_exists( 'WC_Subscription' ) ) {
1647 add_filter(
1648 'woocommerce_order_is_download_permitted',
1649 function( $value ) {
1650 return true;
1651 },
1652 100
1653 );
1654 }
1655
1656 $items = $order->get_items();
1657 ob_start();
1658 $downloads = $order->get_downloadable_items();
1659 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-order-item-download.php';
1660 include $path;
1661 $html = ob_get_contents();
1662 ob_end_clean();
1663 return $html;
1664 }
1665 }
1666
1667 /* Order items border - start */
1668 public function itemsBorderBefore( $atts, $order, $sent_to_admin = '' ) {
1669 if ( null === $order ) {
1670 return '';
1671 } else {
1672 ob_start();
1673 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-order-details-border-before.php';
1674 include $path;
1675 $html = ob_get_contents();
1676 ob_end_clean();
1677 return $html;
1678 }
1679 }
1680
1681 public function itemsBorderAfter( $atts, $order, $sent_to_admin = '' ) {
1682 if ( null === $order ) {
1683 return '';
1684 } else {
1685 ob_start();
1686 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-order-details-border-after.php';
1687 include $path;
1688 $html = ob_get_contents();
1689 ob_end_clean();
1690 return $html;
1691 }
1692 }
1693
1694 public function itemsBorderTitle( $atts, $order, $sent_to_admin = '' ) {
1695 if ( null === $order && $this->is_send_test_mail || 'sampleOrder' == $order ) {
1696 ob_start();
1697 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/sampleOrder/email-order-details-border-title.php';
1698 include $path;
1699 $html = ob_get_contents();
1700 ob_end_clean();
1701 return $html;
1702 }
1703 if ( ! empty( $order ) ) {
1704 ob_start();
1705 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-order-details-border-title.php';
1706 include $path;
1707 $html = ob_get_contents();
1708 ob_end_clean();
1709 return $html;
1710 }
1711 }
1712
1713 public function itemsBorderContent( $atts, $order, $sent_to_admin = '' ) {
1714 if ( null === $order && $this->is_send_test_mail || 'sampleOrder' == $order ) {
1715 ob_start();
1716 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/sampleOrder/email-order-details-border-content.php';
1717 include $path;
1718 $html = ob_get_contents();
1719 ob_end_clean();
1720 return $html;
1721 }
1722 if ( ! empty( $order ) ) {
1723 ob_start();
1724 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-order-details-border-content.php';
1725 include $path;
1726 $html = ob_get_contents();
1727 ob_end_clean();
1728 return $html;
1729 }
1730 }
1731 /* Order items border - end */
1732
1733 public function billingShippingAddress( $atts, $order ) {
1734 $postID = CustomPostType::postIDByTemplate( $this->template );
1735 $text_link_color = get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) ? get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) : '#7f54b3';
1736 if ( null !== $order ) {
1737 $shipping_address = class_exists( 'Flexible_Checkout_Fields_Disaplay_Options' ) ? $this->shipping_address : $order->get_formatted_shipping_address();
1738 $billing_address = class_exists( 'Flexible_Checkout_Fields_Disaplay_Options' ) ? $this->billing_address : $order->get_formatted_billing_address();
1739 if ( $order->get_billing_phone() ) {
1740 $billing_address .= "<br/> <a href='tel:" . esc_html( $order->get_billing_phone() ) . "' style='color:" . esc_attr( $text_link_color ) . "; font-weight: normal; text-decoration: underline;'>" . esc_html( $order->get_billing_phone() ) . '</a>';
1741 }
1742 if ( $order->get_billing_email() ) {
1743 $billing_address .= "<br/><a href='mailto:" . esc_html( $order->get_billing_email() ) . "' style='color:" . esc_attr( $text_link_color ) . ";font-weight: normal; text-decoration: underline;'>" . esc_html( $order->get_billing_email() ) . '</a>';
1744 }
1745 } else {
1746 $billing_address = "John Doe<br/>YayCommerce<br/>7400 Edwards Rd<br/>Edwards Rd<br/><a href='tel:+18587433828' style='color: " . esc_attr( $text_link_color ) . "; font-weight: normal; text-decoration: underline;'>(910) 529-1147</a><br/>";
1747 $shipping_address = "John Doe<br/>YayCommerce<br/>755 E North Grove Rd<br/>Mayville, Michigan<br/><a href='tel:+18587433828' style='color: " . esc_attr( $text_link_color ) . "; font-weight: normal; text-decoration: underline;'>(910) 529-1147</a><br/>";
1748 }
1749 ob_start();
1750 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-billing-shipping-address.php';
1751 $order = $this->order;
1752 include $path;
1753 $html = ob_get_contents();
1754 ob_end_clean();
1755 return $html;
1756
1757 }
1758
1759 /* Billing Shipping Address - start */
1760 public function billingShippingAddressTitle( $atts, $order ) {
1761 $postID = CustomPostType::postIDByTemplate( $this->template );
1762 $text_link_color = get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) ? get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) : '#7f54b3';
1763 if ( null !== $order ) {
1764 $shipping_address = class_exists( 'Flexible_Checkout_Fields_Disaplay_Options' ) ? $this->shipping_address : $order->get_formatted_shipping_address();
1765 $billing_address = class_exists( 'Flexible_Checkout_Fields_Disaplay_Options' ) ? $this->billing_address : $order->get_formatted_billing_address();
1766 } else {
1767 $billing_address = "John Doe<br/>YayCommerce<br/>7400 Edwards Rd<br/>Edwards Rd<br/><a href='tel:+18587433828' style='color: " . esc_attr( $text_link_color ) . "; font-weight: normal; text-decoration: underline;'>(910) 529-1147</a><br/>";
1768 $shipping_address = "John Doe<br/>YayCommerce<br/>755 E North Grove Rd<br/>Mayville, Michigan<br/><a href='tel:+18587433828' style='color: " . esc_attr( $text_link_color ) . "; font-weight: normal; text-decoration: underline;'>(910) 529-1147</a><br/>";
1769 }
1770 ob_start();
1771 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-billing-shipping-address-title.php';
1772 $order = $this->order;
1773 include $path;
1774 $html = ob_get_contents();
1775 ob_end_clean();
1776 return $html;
1777 }
1778
1779 public function checkBillingShippingAddress( $atts, $order_id ) {
1780 $isShippingAddress = false;
1781 $isBillingAddress = false;
1782
1783 if ( ! empty( $billing_address ) ) {
1784 $isBillingAddress = true;
1785 }
1786 if ( ! empty( $shipping_address ) ) {
1787 $isShippingAddress = true;
1788 }
1789
1790 $args = array(
1791 'isShippingAddress' => $isShippingAddress,
1792 'isBillingAddress' => $isBillingAddress,
1793 );
1794
1795 return 'Checking_here';
1796 }
1797
1798 public function billingShippingAddressContent( $atts, $order ) {
1799 $postID = CustomPostType::postIDByTemplate( $this->template );
1800 $text_link_color = get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) ? get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) : '#7f54b3';
1801 $is_preview = Helper::isPreview( $this->preview_mail );
1802 if ( $is_preview ) {
1803 if ( null !== $order ) {
1804 $shipping_address = class_exists( 'Flexible_Checkout_Fields_Disaplay_Options' ) ? $this->shipping_address : $order->get_formatted_shipping_address();
1805 $billing_address = class_exists( 'Flexible_Checkout_Fields_Disaplay_Options' ) ? $this->billing_address : $order->get_formatted_billing_address();
1806 } else {
1807 $billing_address = 'John Doe<br/>YayCommerce<br/>7400 Edwards Rd<br/>Edwards Rd<br/>';
1808 $shipping_address = 'John Doe<br/>YayCommerce<br/>755 E North Grove Rd<br/>Mayville, Michigan<br/>';
1809 }
1810 ob_start();
1811 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-billing-shipping-address-content-preview.php';
1812 $order = $this->order;
1813 include $path;
1814 $html = ob_get_contents();
1815 ob_end_clean();
1816 return $html;
1817 } else {
1818 if ( null !== $order ) {
1819 $shipping_address = class_exists( 'Flexible_Checkout_Fields_Disaplay_Options' ) ? $this->shipping_address : $order->get_formatted_shipping_address();
1820 $billing_address = class_exists( 'Flexible_Checkout_Fields_Disaplay_Options' ) ? $this->billing_address : $order->get_formatted_billing_address();
1821 if ( $order->get_billing_phone() ) {
1822 $billing_address .= "<br/> <a href='tel:" . esc_html( $order->get_billing_phone() ) . "' style='color:" . esc_attr( $text_link_color ) . "; font-weight: normal; text-decoration: underline;'>" . esc_html( $order->get_billing_phone() ) . '</a>';
1823 }
1824 if ( $order->get_billing_email() ) {
1825 $billing_address .= "<br/><a href='mailto:" . esc_html( $order->get_billing_email() ) . "' style='color:" . esc_attr( $text_link_color ) . ";font-weight: normal; text-decoration: underline;'>" . esc_html( $order->get_billing_email() ) . '</a>';
1826 }
1827 if ( method_exists( $order, 'get_shipping_phone' ) && ! empty( $order->get_shipping_phone() ) ) {
1828 if ( false === strpos( $shipping_address, $order->get_shipping_phone() ) ) {
1829 $shipping_address .= "<br/> <a href='tel:" . esc_html( $order->get_shipping_phone() ) . "' style='color:" . esc_attr( $text_link_color ) . "; font-weight: normal; text-decoration: underline;'>" . esc_html( $order->get_shipping_phone() ) . '</a>';
1830 }
1831 }
1832 if ( metadata_exists( 'post', $order->get_id(), '_shipping_email' ) ) {
1833 if ( false === strpos( $shipping_address, get_post_meta( $order->get_id(), '_shipping_email', true ) ) ) {
1834 $shipping_address .= "<br/><a href='mailto:" . esc_html( get_post_meta( $order->get_id(), '_shipping_email', true ) ) . "' style='color:" . esc_attr( $text_link_color ) . ";font-weight: normal; text-decoration: underline;'>" . esc_html( get_post_meta( $order->get_id(), '_shipping_email', true ) ) . '</a>';
1835 }
1836 }
1837 } else {
1838 $billing_address = "John Doe<br/>YayCommerce<br/>7400 Edwards Rd<br/>Edwards Rd<br/><a href='tel:+18587433828' style='color: " . esc_attr( $text_link_color ) . "; font-weight: normal; text-decoration: underline;'>(910) 529-1147</a><br/>";
1839 $shipping_address = "John Doe<br/>YayCommerce<br/>755 E North Grove Rd<br/>Mayville, Michigan<br/><a href='tel:+18587433828' style='color: " . esc_attr( $text_link_color ) . "; font-weight: normal; text-decoration: underline;'>(910) 529-1147</a><br/>";
1840 }
1841 ob_start();
1842 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-billing-shipping-address-content.php';
1843 $order = $this->order;
1844 include $path;
1845 $html = ob_get_contents();
1846 ob_end_clean();
1847 return $html;
1848 }
1849 }
1850 /* Billing Shipping Address - end */
1851
1852 public function orderItems( $items, $sent_to_admin = '', $checkOrder = '', $is_display = true ) {
1853 if ( 'sampleOrder' === $checkOrder ) {
1854 ob_start();
1855 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/sampleOrder/email-order-details.php';
1856 $order = $this->order;
1857 include $path;
1858 $html = ob_get_contents();
1859 ob_end_clean();
1860 return $html;
1861
1862 } else {
1863 ob_start();
1864 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-order-details.php';
1865 $order = $this->order;
1866 include $path;
1867 $html = ob_get_contents();
1868 ob_end_clean();
1869 return $html;
1870 }
1871
1872 }
1873 public function getOrderCustomerNotes( $customerNotes ) {
1874 ob_start();
1875 foreach ( $customerNotes as $customerNote ) {
1876 ?>
1877
1878 <?php echo wp_kses_post( wpautop( wptexturize( make_clickable( $customerNote->comment_content ) ) ) ); ?>
1879
1880 <?php
1881 }
1882 $html = ob_get_contents();
1883 ob_end_clean();
1884 return $html;
1885 }
1886
1887 /* Woocommerce Hook - End */
1888
1889 public function woocommerceEmailOrderMeta( $attr, $sent_to_admin = '', $checkOrder = '', $args = '' ) {
1890 if ( 'sampleOrder' === $checkOrder ) {
1891 return '[woocommerce_email_order_meta]';
1892 } else {
1893 $order = $this->order;
1894 if ( ! empty( $order ) ) {
1895 ob_start();
1896 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/wc-email-order-meta.php';
1897 include $path;
1898 $html = ob_get_contents();
1899 ob_end_clean();
1900 return $html;
1901 }
1902 }
1903 }
1904
1905 public function woocommerceEmailOrderDetails( $attr, $sent_to_admin = '', $checkOrder = '', $args = '' ) {
1906 if ( 'sampleOrder' === $checkOrder ) {
1907 return '[woocommerce_email_order_details]';
1908 } else {
1909 $order = $this->order;
1910 if ( ! empty( $order ) ) {
1911 ob_start();
1912 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/wc-email-order-detail.php';
1913 include $path;
1914 $html = ob_get_contents();
1915 ob_end_clean();
1916 return $html;
1917 }
1918 }
1919 }
1920 public function woocommerceEmailBeforeOrderTable( $attr, $sent_to_admin = '', $checkOrder = '', $args = '' ) {
1921 if ( 'sampleOrder' === $checkOrder ) {
1922 return '[woocommerce_email_before_order_table]';
1923 } else {
1924 $order = $this->order;
1925 if ( ! empty( $order ) ) {
1926 ob_start();
1927 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/wc-email-before.php';
1928 include $path;
1929 $html = ob_get_contents();
1930 ob_end_clean();
1931 return $html;
1932 }
1933 }
1934 }
1935 public function woocommerceEmailAfterOrderTable( $attr, $sent_to_admin = '', $checkOrder = '', $args = '' ) {
1936 if ( 'sampleOrder' === $checkOrder ) {
1937 return '[woocommerce_email_after_order_table]';
1938 } else {
1939 $order = $this->order;
1940 if ( ! empty( $order ) ) {
1941 ob_start();
1942 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/wc-email-after.php';
1943 include $path;
1944 $html = ob_get_contents();
1945 ob_end_clean();
1946 return $html;
1947 }
1948 }
1949 }
1950 public function getHeading( $atts, $order, $sent_to_admin, $args ) {
1951 if ( isset( $args['email_heading'] ) && ! empty( $args ) ) {
1952 $email_heading = $args['email_heading'];
1953 } else {
1954 if ( isset( $order ) ) {
1955 $orderID = $order->get_id();
1956 $email_heading = 'Order Refunded: ' . $orderID;
1957 } else {
1958 $email_heading = 'Order Refunded: 1';
1959 }
1960 }
1961 return $email_heading;
1962 }
1963 public function orderCouponCodes( $args, $order ) {
1964 if ( isset( $order ) && method_exists( $order, 'get_coupon_codes' ) && ! empty( $order->get_coupon_codes() ) ) {
1965 $coupon_codes = $order->get_coupon_codes();
1966 ob_start();
1967 foreach ( $coupon_codes as $key => $value ) {
1968 ?>
1969 <?php echo wp_kses_post( $value ); ?>
1970 <?php
1971 }
1972 $html = ob_get_contents();
1973 ob_end_clean();
1974 return $html;
1975 }
1976
1977 }
1978 public function orderPaymentInstructions( $order, $sent_to_admin = false ) {
1979 if ( null === $order ) {
1980 return '';
1981 } else {
1982 ob_start();
1983 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-order-payment-gateways.php';
1984 include $path;
1985 $html = ob_get_contents();
1986 ob_end_clean();
1987 return $html;
1988 }
1989 }
1990
1991 public function jetBookingDetails( $args, $order, $sent_to_admin ) {
1992 if ( null === $order ) {
1993 ob_start();
1994 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/sampleOrder/jet-booking-details.php';
1995 include $path;
1996 $html = ob_get_contents();
1997 ob_end_clean();
1998 return $html;
1999 } else {
2000 $WC_Integration = new \JET_ABAF\WC_Integration();
2001 $get_booking_order_details = $WC_Integration->get_booking_order_details( $order->get_id() );
2002 ob_start();
2003 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/jet-booking-details.php';
2004 include $path;
2005 $html = ob_get_contents();
2006 ob_end_clean();
2007 return $html;
2008 }
2009
2010 }
2011
2012 }
2013