PluginProbe
YayMail – WooCommerce Email Customizer / 3.3.7
YayMail – WooCommerce Email Customizer v3.3.7
4.4.6 4.4.5 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 All 57 releases
yaymail / includes / MailBuilder / Shortcodes.php

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

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