PluginProbe
YayMail – WooCommerce Email Customizer / 3.3
YayMail – WooCommerce Email Customizer v3.3
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.3, at includes/MailBuilder/Shortcodes.php

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