PluginProbe
YayMail – WooCommerce Email Customizer / 2.1.5
YayMail – WooCommerce Email Customizer v2.1.5
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 2.1.5, at includes/MailBuilder/Shortcodes.php

1,438 lines 63.8 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
10 defined( 'ABSPATH' ) || exit;
11 global $woocommerce, $wpdb, $current_user, $order;
12
13 class Shortcodes {
14
15 protected static $instance = null;
16 public $order_id = false;
17 public $args_email = false;
18 public $order;
19 public $sent_to_admin = false;
20 public $order_data;
21 public $template = false;
22 public $customer_note = false;
23 public $shipping_address = null;
24 public $billing_address = null;
25 // public $array_content_template = false;
26 public $shortcodes_lists;
27 public static function getInstance() {
28 if ( null == self::$instance ) {
29 self::$instance = new self();
30 }
31 return self::$instance;
32 }
33
34 public function __construct( $template = false, $checkOrder = '' ) {
35 if ( $template ) {
36 $this->template = $template;
37 if ( 'sampleOrder' === $checkOrder ) {
38 $this->shortCodesOrderSample();
39 } else {
40 $this->shortCodesOrderDefined();
41 }
42 // style css
43 add_filter( 'woocommerce_email_styles', array( $this, 'customCss' ) );
44
45 // Order Details
46 $order_details_list = array(
47 'items_downloadable_title',
48 'items_downloadable_product',
49 'items_border',
50 'items',
51 'order_date',
52 'order_fee',
53 'order_id',
54 'order_link',
55 'order_number',
56 'order_refund',
57 'order_sub_total',
58 'order_total',
59 'order_tn',
60 'items_border_before',
61 'items_border_after',
62 'items_border_title',
63 'items_border_content',
64 'items_downloadable_product',
65 'items_downloadable_title',
66 'get_heading',
67 'woocommerce_email_before_order_table',
68 'woocommerce_email_after_order_table',
69 );
70
71 // Payments
72 $payments_list = array(
73 'order_payment_method',
74 'order_payment_url',
75 'order_payment_url_string',
76 'payment_method',
77 'transaction_id',
78 );
79
80 // Shippings
81 $shippings_list = array(
82 'order_shipping',
83 'shipping_address',
84 'shipping_address_1',
85 'shipping_address_2',
86 'shipping_city',
87 'shipping_company',
88 'shipping_country',
89 'shipping_first_name',
90 'shipping_last_name',
91 'shipping_method',
92 'shipping_postcode',
93 'shipping_state',
94 );
95
96 // Billings
97 $billings_list = array(
98 'billing_address',
99 'billing_address_1',
100 'billing_address_2',
101 'billing_city',
102 'billing_company',
103 'billing_country',
104 'billing_email',
105 'billing_first_name',
106 'billing_last_name',
107 'billing_phone',
108 'billing_postcode',
109 'billing_state',
110 );
111
112 // Reset Password
113 $reset_password_list = array( 'password_reset_url', 'password_reset_url_string' );
114
115 // New Users
116 $new_users_list = array( 'user_new_password', 'user_activation_link' );
117
118 // General
119 $general_list = array(
120 'customer_note',
121 'customer_notes',
122 'customer_provided_note',
123 'site_name',
124 'site_url',
125 'site_url_string',
126 'user_email',
127 'user_id',
128 'user_name',
129 'customer_username',
130 'customer_name',
131 'view_order_url',
132 'view_order_url_string',
133 'billing_shipping_address',
134 'domain',
135 'user_account_url',
136 'user_account_url_string',
137 // new
138 'billing_shipping_address_title',
139 'billing_shipping_address_content',
140 'check_billing_shipping_address',
141
142 );
143
144 // Additional Order Meta.
145 $order = CustomPostType::getListOrders();
146
147 /* Define Shortcodes */
148 $shortcodes_lists = array();
149 $shortcodes_lists = array_merge( $shortcodes_lists, apply_filters( 'yaymail_shortcodes', $shortcodes_lists ) );
150 $shortcodes_lists = array_merge( $shortcodes_lists, $order_details_list );
151 // $shortcodes_lists = array_merge( $shortcodes_lists, $order_subscription_list );
152 $shortcodes_lists = array_merge( $shortcodes_lists, $payments_list );
153 $shortcodes_lists = array_merge( $shortcodes_lists, $shippings_list );
154 $shortcodes_lists = array_merge( $shortcodes_lists, $billings_list );
155 $shortcodes_lists = array_merge( $shortcodes_lists, $reset_password_list );
156 $shortcodes_lists = array_merge( $shortcodes_lists, $new_users_list );
157 $shortcodes_lists = array_merge( $shortcodes_lists, $general_list );
158 $this->shortcodes_lists = $shortcodes_lists;
159 foreach ( $this->shortcodes_lists as $key => $shortcode_name ) {
160 if ( 'woocommerce_email_before_order_table' == $shortcode_name || 'woocommerce_email_after_order_table' == $shortcode_name ) {
161 add_shortcode( $shortcode_name, array( $this, 'shortcodeCallBack' ) );
162 } else {
163 $function_name = $this->parseShortCodeToFunctionName( 'yaymail_' . $shortcode_name );
164 if ( method_exists( $this, $function_name ) ) {
165 add_shortcode(
166 'yaymail_' . $shortcode_name,
167 function ( $atts, $content, $tag ) {
168 $function_name = $this->parseShortCodeToFunctionName( $tag );
169 return $this->$function_name( $atts, $this->order, $this->sent_to_admin, $this->args_email );
170 }
171 );
172 } elseif ( strpos( $shortcode_name, 'addon' ) !== false ) {
173 add_shortcode(
174 $shortcode_name,
175 function ( $atts, $content, $tag ) {
176 return $this->order_data[ '[' . $tag . ']' ];
177 }
178 );
179 } else {
180 add_shortcode( 'yaymail_' . $shortcode_name, array( $this, 'shortcodeCallBack' ) );
181 }
182 }
183 }
184
185 // add_shortcode( 'yaymail_billing_shipping_address_content', array( $this, 'billing_shipping_address_content' ) );
186 // add_shortcode( 'yaymail_items_border_content', array( $this, 'items_border_content' ) );
187 // add_shortcode( 'yaymail_items_border_title', array( $this, 'items_border_title' ) );
188 }
189 }
190
191 public function parseShortCodeToFunctionName( $shortcode_name ) {
192 $function_name = substr( $shortcode_name, 8 );
193 $offset = 0;
194 while ( false !== strpos( $function_name, '_', $offset ) ) {
195 $position = strpos( $function_name, '_', $offset );
196 $function_name[ $position + 1 ] = strtoupper( $function_name[ $position + 1 ] );
197 $offset = $position + 1;
198 }
199 $function_name = str_replace( '_', '', $function_name );
200 return $function_name;
201 }
202
203 public function applyCSSFormat( $defaultsCss = '' ) {
204 $templateEmail = \YayMail\Templates\Templates::getInstance();
205 $css = $templateEmail::getCssFortmat();
206 $cssDirection = '';
207 $cssDirection .= 'td{direction: rtl}';
208 $cssDirection .= 'td, th, td{text-align:right;}';
209
210 $css .= get_option( 'yaymail_direction' ) && get_option( 'yaymail_direction' ) === 'rtl' ? $cssDirection : '';
211 $css .= $defaultsCss;
212 $css .= '.td { color: inherit; }';
213 return $css;
214 }
215 public function customCss( $css = '' ) {
216 return $this->applyCSSFormat( $css );
217 }
218 public function setOrderId( $order_id = '', $sent_to_admin = '', $args = '' ) {
219 $this->order_id = $order_id;
220 $this->args_email = $args;
221 $this->sent_to_admin = $sent_to_admin;
222 // Additional Order Meta.
223 $order_meta_list = array();
224 if ( ! empty( $this->order_id ) ) {
225 $order_metaArr = get_post_meta( $this->order_id );
226 if ( is_array( $order_metaArr ) && count( $order_metaArr ) > 0 ) {
227 foreach ( $order_metaArr as $k => $v ) {
228 $nameField = str_replace( ' ', '_', trim( $k ) );
229 $order_meta_list[] = 'order_meta:' . $nameField;
230 }
231 }
232 }
233 $shortcodes_lists = array();
234 $shortcodes_lists = array_merge( $shortcodes_lists, $order_meta_list );
235 foreach ( $shortcodes_lists as $key => $shortcode_name ) {
236 add_shortcode( 'yaymail_' . $shortcode_name, array( $this, 'shortcodeCallBack' ) );
237 }
238 }
239
240 protected function _shortcode_atts( $defaults = array(), $atts = array() ) {
241 if ( isset( $atts['class'] ) ) {
242 $atts['classname'] = $atts['class'];
243 }
244
245 return \shortcode_atts( $defaults, $atts );
246 }
247
248 // short Codes Order when select SampleOrder
249 public function shortCodesOrderSample( $sent_to_admin = '' ) {
250 $user = wp_get_current_user();
251 $useId = get_current_user_id();
252 $this->defaultSampleOrderData( $sent_to_admin );
253 }
254
255 public function shortCodesOrderDefined( $sent_to_admin = '', $args = array() ) {
256 // if ( false === $this->order_id && class_exists( 'WC_Order' ) ) {
257 // $this->shortCodesOrderSample( $sent_to_admin );
258 // }
259 if ( false !== $this->order_id && ! empty( $this->order_id ) && class_exists( 'WC_Order' ) ) {
260 $this->order = new \WC_Order( $this->order_id );
261 $this->collectOrderData( $sent_to_admin, $args );
262 }
263 if ( ! function_exists( 'get_user_by' ) ) {
264 return false;
265 }
266 $action = isset( $_REQUEST['action'] ) ? sanitize_key( $_REQUEST['action'] ) : '';
267 if ( empty( $this->order_id ) || ! $this->order_id ) {
268 $shortcode = $this->order_data;
269 if ( isset( $_REQUEST['billing_email'] ) ) {
270 $shortcode['[yaymail_user_email]'] = sanitize_email( $_REQUEST['billing_email'] );
271 $user = get_user_by( 'email', sanitize_email( $_REQUEST['billing_email'] ) );
272 if ( ! empty( $user ) ) {
273 $shortcode['[yaymail_customer_username]'] = $user->user_login;
274 $shortcode['[yaymail_customer_name]'] = get_user_meta( $user->ID, 'first_name', true ) . ' ' . get_user_meta( $user->ID, 'last_name', true );
275 $shortcode['[yaymail_user_id]'] = $user->ID;
276 }
277 }
278 if ( empty( $shortcode['[yaymail_customer_username]'] ) ) {
279 if ( isset( $_REQUEST['user_email'] ) ) {
280 $user = get_user_by( 'email', sanitize_email( $_REQUEST['user_email'] ) );
281 if ( isset( $user->user_login ) ) {
282 $shortcode['[yaymail_customer_username]'] = $user->user_login;
283 }
284 if ( isset( $user->ID ) ) {
285 $shortcode['[yaymail_user_id]'] = $user->ID;
286 }
287 } elseif ( isset( $_REQUEST['email'] ) ) {
288 $user = get_user_by( 'email', sanitize_email( $_REQUEST['email'] ) );
289 if ( isset( $user->user_login ) ) {
290 $shortcode['[yaymail_customer_username]'] = $user->user_login;
291 }
292 if ( isset( $user->ID ) ) {
293 $shortcode['[yaymail_user_id]'] = $user->ID;
294 }
295 }
296 }
297 if ( empty( $shortcode['[yaymail_user_email]'] ) ) {
298 if ( isset( $_REQUEST['user_email'] ) ) {
299 $user = get_user_by( 'email', sanitize_email( $_REQUEST['user_email'] ) );
300 if ( isset( $user->user_email ) ) {
301 $shortcode['[yaymail_user_email]'] = $user->user_email;
302 }
303 if ( isset( $user->ID ) ) {
304 $shortcode['[yaymail_user_id]'] = $user->ID;
305 }
306 } elseif ( isset( $_REQUEST['email'] ) ) {
307 $user = get_user_by( 'email', sanitize_email( $_REQUEST['email'] ) );
308 if ( isset( $user->user_email ) ) {
309 $shortcode['[yaymail_user_email]'] = $user->user_email;
310 }
311 if ( isset( $user->ID ) ) {
312 $shortcode['[yaymail_user_id]'] = $user->ID;
313 }
314 }
315 }
316 if ( empty( $shortcode['[yaymail_customer_name]'] ) ) {
317 if ( isset( $_REQUEST['user_email'] ) ) {
318 $user = get_user_by( 'email', sanitize_email( $_REQUEST['user_email'] ) );
319 if ( isset( $user->user_email ) ) {
320 $shortcode['[yaymail_customer_name]'] = get_user_meta( $user->ID, 'first_name', true ) . ' ' . get_user_meta( $user->ID, 'last_name', true );
321 }
322 if ( isset( $user->ID ) ) {
323 $shortcode['[yaymail_user_id]'] = $user->ID;
324 }
325 } elseif ( isset( $_REQUEST['email'] ) ) {
326 $user = get_user_by( 'email', sanitize_email( $_REQUEST['email'] ) );
327 if ( isset( $user->user_email ) ) {
328 if ( ! empty( get_user_meta( $user->ID, 'first_name', true ) ) && ! empty( get_user_meta( $user->ID, 'last_name', true ) ) ) {
329 $shortcode['[yaymail_customer_name]'] = get_user_meta( $user->ID, 'first_name', true ) . ' ' . get_user_meta( $user->ID, 'last_name', true );
330 } elseif ( isset( $_REQUEST['first_name'] ) && isset( $_REQUEST['last_name'] ) ) {
331 $shortcode['[yaymail_customer_name]'] = sanitize_text_field( $_REQUEST['first_name'] ) . ' ' . sanitize_text_field( $_REQUEST['last_name'] );
332 }
333 }
334 if ( isset( $user->ID ) ) {
335 $shortcode['[yaymail_user_id]'] = $user->ID;
336 }
337 }
338 }
339 if ( ! empty( $args ) ) {
340 $postID = CustomPostType::postIDByTemplate( $this->template );
341 $text_link_color = get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) ? get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) : '#96588A';
342 $yaymail_settings = get_option( 'yaymail_settings' );
343 $yaymail_informations = array(
344 'post_id' => $postID,
345 'template' => $this->template,
346 'yaymail_elements' => get_post_meta( $postID, '_yaymail_elements', true ),
347 'general_settings' => array(
348 'tableWidth' => $yaymail_settings['container_width'],
349 'emailBackgroundColor' => get_post_meta( $postID, '_email_backgroundColor_settings', true ) ? get_post_meta( $postID, '_email_backgroundColor_settings', true ) : '#ECECEC',
350 'textLinkColor' => get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) ? get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) : '#96588A',
351 ),
352 );
353 if ( isset( $args['email'] ) || isset( $args['admin_email'] ) || isset( $args['user'] ) ) {
354 if ( isset( $args['email']->id ) && 'customer_reset_password' == $args['email']->id ) {
355 $user = new \WP_User( intval( $args['email']->user_id ) );
356 $shortcode['[yaymail_customer_username]'] = $args['email']->user_login;
357 $shortcode['[yaymail_customer_name]'] = get_user_meta( $user->ID, 'first_name', true ) . ' ' . get_user_meta( $user->ID, 'last_name', true );
358 $shortcode['[yaymail_user_email]'] = $args['email']->user_email;
359 $shortcode['[yaymail_user_id]'] = $user->ID;
360 $reset_key = get_password_reset_key( $user );
361 $resetURL = esc_url(
362 add_query_arg(
363 array(
364 'key' => $reset_key,
365 'login' => rawurlencode( $args['email']->user_login ),
366 ),
367 wc_get_endpoint_url( 'lost-password', '', wc_get_page_permalink( 'myaccount' ) )
368 )
369 );
370 $shortcode['[yaymail_password_reset_url]'] = '<a style="color: ' . $text_link_color . ';" href="' . esc_url( $resetURL ) . '">' . esc_html__( 'Click here to reset your password', 'woocommerce' ) . '</a>';
371 $shortcode['[yaymail_password_reset_url_string]'] = esc_url( $resetURL );
372 $shortcode['[yaymail_site_name]'] = get_bloginfo( 'name' );
373 }
374
375 $shortcode['[yaymail_site_name]'] = get_bloginfo( 'name' );
376 $shortcode['[yaymail_site_url]'] = '<a href="' . get_site_url() . '"> ' . get_site_url() . ' </a>';
377 $shortcode['[yaymail_site_url_string]'] = get_site_url();
378 $shortcode['[yaymail_user_account_url]'] = '<a style="color:' . $text_link_color . '; font-weight: normal; text-decoration: underline;" href="' . wc_get_page_permalink( 'myaccount' ) . '">' . esc_url( wc_get_page_permalink( 'myaccount' ) ) . '</a>';
379 $shortcode['[yaymail_user_account_url_string]'] = wc_get_page_permalink( 'myaccount' );
380 if ( isset( $args['email']->user_pass ) && ! empty( $args['email']->user_pass ) ) {
381 $shortcode['[yaymail_user_new_password]'] = $args['email']->user_pass;
382 } else {
383 if ( isset( $_REQUEST['pass1-text'] ) && '' != $_REQUEST['pass1-text'] ) {
384 $shortcode['[yaymail_user_new_password]'] = sanitize_text_field( $_REQUEST['pass1-text'] );
385 } elseif ( isset( $_REQUEST['pass1'] ) && '' != $_REQUEST['pass1'] ) {
386 $shortcode['[yaymail_user_new_password]'] = sanitize_text_field( $_REQUEST['pass1-text'] );
387 } else {
388 $shortcode['[yaymail_user_new_password]'] = '';
389 }
390 }
391 if ( isset( $args['email']->user_login ) && ! empty( $args['email']->user_login ) ) {
392 $shortcode['[yaymail_customer_username]'] = $args['email']->user_login;
393 $user = get_user_by( 'email', $args['email']->user_email );
394 if ( ! empty( get_user_meta( $user->ID, 'first_name', true ) ) && ! empty( get_user_meta( $user->ID, 'last_name', true ) ) ) {
395 $shortcode['[yaymail_customer_name]'] = get_user_meta( $user->ID, 'first_name', true ) . ' ' . get_user_meta( $user->ID, 'last_name', true );
396 } elseif ( isset( $_REQUEST['first_name'] ) && isset( $_REQUEST['last_name'] ) ) {
397 $shortcode['[yaymail_customer_name]'] = sanitize_text_field( $_REQUEST['first_name'] ) . ' ' . sanitize_text_field( $_REQUEST['last_name'] );
398 }
399 }
400 if ( isset( $args['email']->user_email ) && ! empty( $args['email']->user_email ) ) {
401 $shortcode['[yaymail_user_email]'] = $args['email']->user_email;
402 }
403 if ( isset( $args['email']->id ) && ( 'customer_new_account' == $args['email']->id || 'customer_new_account_activation' == $args['email']->id ) ) {
404 if ( 'customer_new_account_activation' == $args['email']->id ) {
405 if ( isset( $args['email']->user_activation_url ) && ! empty( $args['email']->user_activation_url ) ) {
406 $shortcode['[yaymail_user_activation_link]'] = $args['email']->user_activation_url;
407 }
408 } else {
409 if ( isset( $args['email']->user_login ) && ! empty( $args['email']->user_login ) ) {
410 global $wpdb, $wp_hasher;
411 $newHash = $wp_hasher;
412 // Generate something random for a password reset key.
413 $key = wp_generate_password( 20, false );
414
415 /**
416 *
417 * This action is documented in wp-login.php
418 */
419 do_action( 'retrieve_password_key', $args['email']->user_login, $key );
420
421 // Now insert the key, hashed, into the DB.
422 if ( empty( $wp_hasher ) ) {
423 if ( ! class_exists( 'PasswordHash' ) ) {
424 include_once ABSPATH . 'wp-includes/class-phpass.php';
425 }
426 $newHash = new \PasswordHash( 8, true );
427 }
428 $hashed = time() . ':' . $newHash->HashPassword( $key );
429 $wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $args['email']->user_login ) );
430 $activation_url = network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $args['email']->user_login ), 'login' );
431 $shortcode['[yaymail_user_activation_link]'] = $activation_url;
432 }
433 }
434 }
435
436 // Define shortcode from plugin addon
437 $shortcode = apply_filters( 'yaymail_do_shortcode', $shortcode, $yaymail_informations, $args );
438 } else {
439 // Define shortcode from plugin addon not have args[''email]
440 $shortcode = apply_filters( 'yaymail_do_shortcode', $shortcode, $yaymail_informations, $args );
441 }
442 }
443
444 $this->order_data = $shortcode;
445 }
446 }
447 public function shortcodeCallBack( $atts, $content, $tag ) {
448
449 return isset( $this->order_data[ '[' . $tag . ']' ] ) ? $this->order_data[ '[' . $tag . ']' ] : false;
450
451 }
452
453 public function templateParser() {
454 // Helper::checkNonce();
455 $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( $_POST['nonce'] ) : '';
456 if ( ! wp_verify_nonce( $nonce, 'email-nonce' ) ) {
457 wp_send_json_error( array( 'mess' => 'Nonce is invalid' ) );
458 } else {
459 $request = $_POST;
460 $this->order_id = false;
461 if ( isset( $request['order_id'] ) ) {
462 $order_id = sanitize_text_field( $request['order_id'] );
463 if ( 'sampleOrder' !== $order_id ) {
464 $order_id = intval( $order_id );
465 }
466 if ( ! $order_id ) {
467 $order_id = '';
468 }
469
470 $this->template = isset( $request['template'] ) ? $request['template'] : false;
471 $this->order_id = $order_id;
472 }
473
474 if ( ! $this->order_id || ! $this->template ) {
475 return false;
476 }
477
478 if ( 'sampleOrder' !== $order_id ) {
479 $this->order = new \WC_Order( $this->order_id );
480 }
481
482 if ( 'sampleOrder' !== $order_id && ( is_null( $this->order ) || empty( $this->order ) || ! isset( $this->order ) ) ) {
483 return false;
484 }
485
486 if ( 'sampleOrder' !== $order_id ) {
487 $this->collectOrderData();
488 } else {
489 $this->defaultSampleOrderData();
490 }
491
492 $result = (object) array();
493 $result->order_id = $this->order_id;
494 $result->order_data = $this->order_data;
495
496 $shortcode_order_meta = array();
497 $shortcode_order_custom_meta = array();
498 if ( 'sampleOrder' !== $order_id ) {
499 $result->order = $this->order;
500 $result->order_items = $result->order->get_items();
501 $result->user_details = $result->order->get_user();
502
503 /*
504 @@@@ Get name field in custom field of order woocommerce.
505 */
506 $order_metaArr = get_post_meta( $order_id );
507 if ( is_array( $order_metaArr ) && count( $order_metaArr ) > 0 ) {
508 $pattern = '/^_.*/i';
509 $n = 0;
510 foreach ( $order_metaArr as $k => $v ) {
511 // @@@ starts with the "_" character of the woo field.
512 if ( ! preg_match( $pattern, $k ) ) {
513 $nameField = str_replace( ' ', '_', trim( $k ) );
514 $nameShorcode = '[yaymail_post_meta:' . $nameField . ']';
515 $key_order_meta = 'post_meta:' . $nameField . '_' . $n;
516 $shortcode_order_meta[] = array(
517 'key' => $key_order_meta,
518 $nameShorcode => 'Loads value of order meta key - ' . $nameField,
519 );
520 $n++;
521 }
522 }
523 }
524 if ( ! empty( $result->order ) ) {
525 foreach ( $result->order->get_meta_data() as $meta ) {
526 $nameField = str_replace( ' ', '_', trim( $meta->get_data()['key'] ) );
527 $nameShorcode = '[yaymail_order_meta:' . $nameField . ']';
528 $key_order_custom_meta = 'order_meta:' . $nameField;
529 $shortcode_order_custom_meta[] = array(
530 'key' => $key_order_custom_meta,
531 $nameShorcode => 'Loads value of order custom meta key - ' . $nameField,
532 );
533 }
534 }
535 } else {
536 $result->order = '';
537 $result->order_items = '';
538 $result->user_details = '';
539 }
540 $real_postID = '';
541 if ( isset( $request['template'] ) ) {
542 if ( CustomPostType::postIDByTemplate( $this->template ) ) {
543 $postID = CustomPostType::postIDByTemplate( $this->template );
544 $real_postID = $postID;
545 $emailTemplate = get_post( $postID );
546 $updateElement = new UpdateElement();
547 $yaymail_elements = get_post_meta( $postID, '_yaymail_elements', true );
548 $result->elements = Helper::unsanitize_array( $updateElement->merge_new_props_to_elements( $yaymail_elements ) );
549 $result->emailBackgroundColor = get_post_meta( $postID, '_email_backgroundColor_settings', true ) ? get_post_meta( $postID, '_email_backgroundColor_settings', true ) : 'rgb(236, 236, 236)';
550 $result->emailTextLinkColor = get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) ? get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) : '#96588A';
551 $result->titleShipping = get_post_meta( $postID, '_email_title_shipping', true ) ? get_post_meta( $postID, '_email_title_shipping', true ) : 'Shipping Address';
552 $result->titleBilling = get_post_meta( $postID, '_email_title_billing', true ) ? get_post_meta( $postID, '_email_title_billing', true ) : 'Billing Address';
553 $result->orderTitle = get_post_meta( $postID, '_yaymail_email_order_item_title', true );
554 $result->customCSS = $this->applyCSSFormat();
555 $result->shortcode_order_meta = $shortcode_order_meta;
556 $result->shortcode_order_custom_meta = $shortcode_order_custom_meta;
557 $result->follow_up_shortcodes = array();
558 }
559 }
560 // ob_start();
561 // do_action( 'YaymailAddonWooSubscriptionInformationVue', $result->order_id, $real_postID );
562 // $vueHtml = ob_get_contents();
563 // ob_end_clean();
564 // $result->wooAddonOrderSubscriptionTemp = $vueHtml;
565 if ( class_exists( 'Follow_Up_Emails' ) ) {
566 $result->follow_up_shortcodes = apply_filters( 'yaymail_follow_up_shortcode', array() );
567 }
568 $result->yaymailAddonTemps = apply_filters( 'yaymail_addon_templates', array(), $result->order, $real_postID );
569
570 echo json_encode( $result );
571 die();
572 }
573 }
574
575 public function collectOrderData( $sent_to_admin = '', $args = array() ) {
576 $order = $this->order;
577 if ( empty( $this->order_id ) || empty( $order ) ) {
578 return false;
579 }
580
581 // Getting Fee & Refunds:
582 $fee = 0;
583 $refund = 0;
584 $totals = $order->get_order_item_totals();
585 foreach ( $totals as $index => $value ) {
586 if ( strpos( $index, 'fee' ) !== false ) {
587 $fees = $order->get_fees();
588 foreach ( $fees as $feeVal ) {
589 if ( method_exists( $feeVal, 'get_amount' ) ) {
590 $fee += $feeVal->get_amount();
591 }
592 }
593 }
594 if ( strpos( $index, 'refund' ) !== false ) {
595 $refund = $order->get_total_refunded();
596 }
597 }
598 // User Info
599 $user_data = $order->get_user();
600 $created_date = $order->get_date_created();
601 $items = $order->get_items();
602 $yaymail_settings = get_option( 'yaymail_settings' );
603 $order_url = $order->get_edit_order_url();
604 if ( class_exists( 'Flexible_Checkout_Fields_Disaplay_Options' ) ) {
605 add_action(
606 'woocommerce_email_customer_details',
607 function( $order ) {
608 if ( 'Shortcodes.php' === basename( __FILE__ ) ) {
609 $this->shipping_address = $order->get_formatted_shipping_address();
610 $this->billing_address = $order->get_formatted_billing_address();
611 }
612 },
613 100,
614 1
615 );
616 ob_start();
617 do_action( 'woocommerce_email_customer_details', $order );
618 $delete_write = ob_get_contents();
619 ob_end_clean();
620 }
621 $shipping_address = class_exists( 'Flexible_Checkout_Fields_Disaplay_Options' ) ? $this->shipping_address : $order->get_formatted_shipping_address();
622 $billing_address = class_exists( 'Flexible_Checkout_Fields_Disaplay_Options' ) ? $this->billing_address : $order->get_formatted_billing_address();
623 $postID = CustomPostType::postIDByTemplate( $this->template );
624 $yaymail_informations = array(
625 'post_id' => $postID,
626 'template' => $this->template,
627 'order' => $order,
628 'yaymail_elements' => get_post_meta( $postID, '_yaymail_elements', true ),
629 'general_settings' => array(
630 'tableWidth' => $yaymail_settings['container_width'],
631 'emailBackgroundColor' => get_post_meta( $postID, '_email_backgroundColor_settings', true ) ? get_post_meta( $postID, '_email_backgroundColor_settings', true ) : '#ECECEC',
632 'textLinkColor' => get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) ? get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) : '#96588A',
633 ),
634 );
635 $text_link_color = get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) ? get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) : '#96588A';
636 if ( $order->get_billing_phone() ) {
637 $billing_address .= "<br/> <a href='tel:" . esc_html( $order->get_billing_phone() ) . "' style='color:" . $text_link_color . "; font-weight: normal; text-decoration: underline;'>" . esc_html( $order->get_billing_phone() ) . '</a>';
638 }
639 if ( $order->get_billing_email() ) {
640 $billing_address .= "<br/><a href='mailto:" . esc_html( $order->get_billing_email() ) . "' style='color:" . $text_link_color . ";font-weight: normal; text-decoration: underline;'>" . esc_html( $order->get_billing_email() ) . '</a>';
641 }
642 $customerNotes = $order->get_customer_order_notes();
643 $customerNoteHtmlList = '';
644 $customerNoteHtml = $customerNoteHtmlList;
645 if ( ! empty( $customerNotes ) && count( $customerNotes ) ) {
646 $customerNoteHtmlList = $this->getOrderCustomerNotes( $customerNotes );
647 $customerNote_single[] = $customerNotes[0];
648 $customerNoteHtml = $this->getOrderCustomerNotes( $customerNote_single );
649 }
650
651 $resetURL = '';
652 if ( isset( $args['email']->reset_key ) && ! empty( $args['email']->reset_key )
653 && isset( $args['email']->user_login ) && ! empty( $args['email']->user_login )
654 ) {
655 $user = new \WP_User( intval( $args['email']->user_id ) );
656 $reset_key = get_password_reset_key( $user );
657 $resetURL = esc_url(
658 add_query_arg(
659 array(
660 'key' => $reset_key,
661 'login' => rawurlencode( $args['email']->user_login ),
662 ),
663 wc_get_endpoint_url( 'lost-password', '', wc_get_page_permalink( 'myaccount' ) )
664 )
665 );
666 }
667
668 // Link Downloadable Product
669 $shortcode['[yaymail_items_downloadable_title]'] = $this->itemsDownloadableTitle( '', $this->order, $sent_to_admin, '' ); // done
670 $shortcode['[yaymail_items_downloadable_product]'] = $this->itemsDownloadableProduct( '', $this->order, $sent_to_admin, '' ); // done
671
672 // ORDER DETAILS
673 $shortcode['[yaymail_items_border]'] = $this->itemsBorder( '', $this->order, $sent_to_admin ); // done
674 $shortcode['[yaymail_items_border_before]'] = $this->itemsBorderBefore( '', $this->order, $sent_to_admin ); // done
675 $shortcode['[yaymail_items_border_after]'] = $this->itemsBorderAfter( '', $this->order, $sent_to_admin ); // done
676 $shortcode['[yaymail_items_border_title]'] = $this->itemsBorderTitle( '', $this->order, $sent_to_admin ); // done
677 $shortcode['[yaymail_items_border_content]'] = $this->itemsBorderContent( '', $this->order, $sent_to_admin ); // done
678 $shortcode['[yaymail_get_heading]'] = $this->getEmailHeading( $args, $this->order, $sent_to_admin );
679
680 // WC HOOK
681 $shortcode['[woocommerce_email_before_order_table]'] = $this->orderWoocommerceBeforeHook( $args, $sent_to_admin ); // not Changed
682 $shortcode['[woocommerce_email_after_order_table]'] = $this->orderWoocommerceAfterHook( $args, $sent_to_admin ); // not Changed
683
684 // Define shortcode from plugin addon
685 $shortcode = apply_filters( 'yaymail_do_shortcode', $shortcode, $yaymail_informations, $this->args_email );
686
687 $shortcode['[yaymail_items]'] = $this->orderItems( $items, $sent_to_admin );
688 if ( null != $created_date ) {
689 $shortcode['[yaymail_order_date]'] = $order->get_date_created()->date_i18n( wc_date_format() );
690 } else {
691 $shortcode['[yaymail_order_date]'] = '';
692 }
693 $shortcode['[yaymail_order_fee]'] = $fee;
694 if ( ! empty( $order->get_id() ) ) {
695 $shortcode['[yaymail_order_id]'] = $order->get_id();
696 } else {
697 $shortcode['[yaymail_order_id]'] = '';
698 }
699 $shortcode['[yaymail_order_link]'] = '<a href="' . $order_url . '" style="color:' . $text_link_color . ';">' . esc_html__( 'Order', 'yaymail' ) . '</a>';
700 $shortcode['[yaymail_order_link]'] = str_replace( '[yaymail_order_id]', $order->get_id(), $shortcode['[yaymail_order_link]'] );
701 if ( ! empty( $order->get_order_number() ) ) {
702 $shortcode['[yaymail_order_number]'] = $order->get_order_number();
703 } else {
704 $shortcode['[yaymail_order_number]'] = '';
705 }
706 $shortcode['[yaymail_order_refund]'] = $refund;
707 if ( isset( $totals['cart_subtotal']['value'] ) ) {
708 $shortcode['[yaymail_order_sub_total]'] = $totals['cart_subtotal']['value'];
709 } else {
710 $shortcode['[yaymail_order_sub_total]'] = '';
711 }
712 $shortcode['[yaymail_order_total]'] = wc_price( $order->get_total() );
713
714 // PAYMENTS
715 if ( isset( $totals['payment_method']['value'] ) ) {
716 $shortcode['[yaymail_order_payment_method]'] = $totals['payment_method']['value'];
717 } else {
718 $shortcode['[yaymail_order_payment_method]'] = '';
719 }
720 $shortcode['[yaymail_order_payment_url]'] = '<a href="' . esc_url( $order->get_checkout_payment_url() ) . '">' . esc_html__( 'Payment page', 'yaymail' ) . '</a>';
721 $shortcode['[yaymail_order_payment_url_string]'] = esc_url( $order->get_checkout_payment_url() );
722 if ( ! empty( $order->get_payment_method_title() ) ) {
723 $shortcode['[yaymail_payment_method]'] = $order->get_payment_method_title();
724 } else {
725 $shortcode['[yaymail_payment_method]'] = '';
726 }
727 if ( ! empty( $order->get_transaction_id() ) ) {
728 $shortcode['[yaymail_transaction_id]'] = $order->get_transaction_id();
729 } else {
730 $shortcode['[yaymail_transaction_id]'] = '';
731 }
732
733 // SHIPPINGS
734 if ( ! empty( $order->calculate_shipping() ) ) {
735 $shortcode['[yaymail_order_shipping]'] = $order->calculate_shipping();
736 } else {
737 $shortcode['[yaymail_order_shipping]'] = 0;
738 }
739 $shortcode['[yaymail_shipping_address]'] = $shipping_address;
740 if ( ! empty( $order->get_shipping_address_1() ) ) {
741 $shortcode['[yaymail_shipping_address_1]'] = $order->get_shipping_address_1();
742 } else {
743 $shortcode['[yaymail_shipping_address_1]'] = '';
744 }
745 if ( ! empty( $order->get_shipping_address_2() ) ) {
746 $shortcode['[yaymail_shipping_address_2]'] = $order->get_shipping_address_2();
747 } else {
748 $shortcode['[yaymail_shipping_address_2]'] = '';
749 }
750 if ( ! empty( $order->get_shipping_city() ) ) {
751 $shortcode['[yaymail_shipping_city]'] = $order->get_shipping_city();
752 } else {
753 $shortcode['[yaymail_shipping_city]'] = '';
754 }
755 if ( ! empty( $order->get_shipping_company() ) ) {
756 $shortcode['[yaymail_shipping_company]'] = $order->get_shipping_company();
757 } else {
758 $shortcode['[yaymail_shipping_company]'] = '';
759 }
760 if ( ! empty( $order->get_shipping_country() ) ) {
761 $shortcode['[yaymail_shipping_country]'] = $order->get_shipping_country();
762 } else {
763 $shortcode['[yaymail_shipping_country]'] = '';
764 }
765 if ( ! empty( $order->get_shipping_first_name() ) ) {
766 $shortcode['[yaymail_shipping_first_name]'] = $order->get_shipping_first_name();
767 } else {
768 $shortcode['[yaymail_shipping_first_name]'] = '';
769
770 }
771 if ( ! empty( $order->get_shipping_last_name() ) ) {
772 $shortcode['[yaymail_shipping_last_name]'] = $order->get_shipping_last_name();
773 } else {
774 $shortcode['[yaymail_shipping_last_name]'] = '';
775
776 }
777 if ( ! empty( $order->get_shipping_method() ) ) {
778 $shortcode['[yaymail_shipping_method]'] = $order->get_shipping_method();
779 } else {
780 $shortcode['[yaymail_shipping_method]'] = '';
781 }
782 if ( ! empty( $order->get_shipping_postcode() ) ) {
783 $shortcode['[yaymail_shipping_postcode]'] = $order->get_shipping_postcode();
784 } else {
785 $shortcode['[yaymail_shipping_postcode]'] = '';
786 }
787 if ( ! empty( $order->get_shipping_state() ) ) {
788 $shortcode['[yaymail_shipping_state]'] = $order->get_shipping_state();
789 } else {
790 $shortcode['[yaymail_shipping_state]'] = '';
791 }
792
793 // BILLINGS
794 $shortcode['[yaymail_billing_address]'] = $billing_address;
795 if ( ! empty( $order->get_billing_address_1() ) ) {
796 $shortcode['[yaymail_billing_address_1]'] = $order->get_billing_address_1();
797 } else {
798 $shortcode['[yaymail_billing_address_1]'] = '';
799 }
800 if ( ! empty( $order->get_billing_address_2() ) ) {
801 $shortcode['[yaymail_billing_address_2]'] = $order->get_billing_address_2();
802 } else {
803 $shortcode['[yaymail_billing_address_2]'] = '';
804 }
805 if ( ! empty( $order->get_billing_city() ) ) {
806 $shortcode['[yaymail_billing_city]'] = $order->get_billing_city();
807 } else {
808 $shortcode['[yaymail_billing_city]'] = $order->get_billing_city();
809 }
810 if ( ! empty( $order->get_billing_company() ) ) {
811 $shortcode['[yaymail_billing_company]'] = $order->get_billing_company();
812 } else {
813 $shortcode['[yaymail_billing_company]'] = '';
814 }
815 if ( ! empty( $order->get_billing_country() ) ) {
816 $shortcode['[yaymail_billing_country]'] = $order->get_billing_country();
817 } else {
818 $shortcode['[yaymail_billing_country]'] = '';
819 }
820 if ( ! empty( $order->get_billing_email() ) ) {
821 $shortcode['[yaymail_billing_email]'] = '<a style="color: inherit" href="mailto:' . $order->get_billing_email() . '">' . $order->get_billing_email() . '</a>';
822 } else {
823 $shortcode['[yaymail_billing_email]'] = '';
824 }
825 if ( ! empty( $order->get_billing_first_name() ) ) {
826 $shortcode['[yaymail_billing_first_name]'] = $order->get_billing_first_name();
827 } else {
828 $shortcode['[yaymail_billing_first_name]'] = '';
829 }
830 if ( ! empty( $order->get_billing_last_name() ) ) {
831 $shortcode['[yaymail_billing_last_name]'] = $order->get_billing_last_name();
832 } else {
833 $shortcode['[yaymail_billing_last_name]'] = '';
834 }
835 if ( ! empty( $order->get_billing_phone() ) ) {
836 $shortcode['[yaymail_billing_phone]'] = $order->get_billing_phone();
837 } else {
838 $shortcode['[yaymail_billing_phone]'] = '';
839 }
840 if ( ! empty( $order->get_billing_postcode() ) ) {
841 $shortcode['[yaymail_billing_postcode]'] = $order->get_billing_postcode();
842 } else {
843 $shortcode['[yaymail_billing_postcode]'] = '';
844 }
845 if ( ! empty( $order->get_billing_state() ) ) {
846 $shortcode['[yaymail_billing_state]'] = $order->get_billing_state();
847 } else {
848 $shortcode['[yaymail_billing_state]'] = '';
849 }
850
851 // Reset Passwords
852 $shortcode['[yaymail_password_reset_url]'] = '<a style="color: ' . $text_link_color . ';" href="' . esc_url( $resetURL ) . '">' . esc_html__( 'Click here to reset your password', 'woocommerce' ) . '</a>';
853 $shortcode['[yaymail_password_reset_url_string]'] = esc_url( $resetURL );
854
855 // New Users
856 if ( isset( $args['email']->user_pass ) && ! empty( $args['email']->user_pass ) ) {
857 $shortcode['[yaymail_user_new_password]'] = $args['email']->user_pass;
858 } else {
859 if ( isset( $_REQUEST['pass1-text'] ) && '' != $_REQUEST['pass1-text'] ) {
860 $shortcode['[yaymail_user_new_password]'] = sanitize_text_field( $_REQUEST['pass1-text'] );
861 } elseif ( isset( $_REQUEST['pass1'] ) && '' != $_REQUEST['pass1'] ) {
862 $shortcode['[yaymail_user_new_password]'] = sanitize_text_field( $_REQUEST['pass1-text'] );
863 } else {
864 $shortcode['[yaymail_user_new_password]'] = '';
865 }
866 }
867 // Review this code ??
868 if ( isset( $args['email']->user_activation_url ) && ! empty( $args['email']->user_activation_url ) ) {
869 $shortcode['[yaymail_user_activation_link]'] = $args['email']->user_activation_url;
870 } else {
871 $shortcode['[yaymail_user_activation_link]'] = '';
872 }
873
874 // GENERALS
875 $shortcode['[yaymail_customer_note]'] = $customerNoteHtml;
876 $shortcode['[yaymail_customer_notes]'] = $customerNoteHtmlList;
877 if ( ! empty( $order->get_customer_note() ) ) {
878 $shortcode['[yaymail_customer_provided_note]'] = $order->get_customer_note();
879 } else {
880 $shortcode['[yaymail_customer_provided_note]'] = '';
881 }
882 $shortcode['[yaymail_site_name]'] = get_bloginfo( 'name' );
883 $shortcode['[yaymail_site_url]'] = '<a href="' . get_site_url() . '"> ' . get_site_url() . ' </a>';
884 $shortcode['[yaymail_site_url_string]'] = get_site_url();
885 if ( isset( $user_data->user_email ) ) {
886 $shortcode['[yaymail_user_email]'] = $user_data->user_email;
887 } else {
888 $shortcode['[yaymail_user_email]'] = $order->get_billing_email();
889 }
890 if ( isset( $shortcode['[yaymail_user_email]'] ) && '' != $shortcode['[yaymail_user_email]'] ) {
891 $user = get_user_by( 'email', $shortcode['[yaymail_user_email]'] );
892 $shortcode['[yaymail_user_id]'] = ( isset( $user->ID ) ) ? $user->ID : '';
893 }
894 if ( isset( $user_data->user_login ) && ! empty( $user_data->user_login ) ) {
895 $shortcode['[yaymail_customer_username]'] = $user_data->user_login;
896 } elseif ( isset( $user_data->user_nicename ) ) {
897 $shortcode['[yaymail_customer_username]'] = $user_data->user_nicename;
898 } else {
899 $shortcode['[yaymail_customer_username]'] = $order->get_billing_first_name();
900 }
901 if ( isset( $user->ID ) && ! empty( $user->ID ) ) {
902 $shortcode['[yaymail_customer_name]'] = get_user_meta( $user->ID, 'first_name', true ) . ' ' . get_user_meta( $user->ID, 'last_name', true );
903 } elseif ( isset( $user_data->user_nicename ) ) {
904 $shortcode['[yaymail_customer_name]'] = $user_data->user_nicename;
905 } else {
906 $shortcode['[yaymail_customer_name]'] = $order->get_billing_first_name() . ' ' . $order->get_billing_last_name();
907 }
908 if ( ! empty( $order->get_view_order_url() ) ) {
909 $text_your_order = esc_html__( 'Your Order', 'yaymail' );
910 $shortcode['[yaymail_view_order_url]'] = '<a href="' . $order->get_view_order_url() . '" style="color:' . $text_link_color . ';">' . $text_your_order . '</a>';
911 $shortcode['[yaymail_view_order_url_string]'] = $order->get_view_order_url();
912 } else {
913 $shortcode['[yaymail_view_order_url]'] = '';
914 }
915 $shortcode['[yaymail_billing_shipping_address]'] = $this->billingShippingAddress( '', $this->order ); // done
916
917 $shortcode['[yaymail_billing_shipping_address_title]'] = $this->billingShippingAddressTitle( '', $this->order ); // done
918 $shortcode['[yaymail_billing_shipping_address_content]'] = $this->billingShippingAddressContent( '', $this->order ); // done
919 $shortcode['[yaymail_check_billing_shipping_address]'] = $this->checkBillingShippingAddress( '', $this->order );
920
921 if ( ! empty( parse_url( get_site_url() )['host'] ) ) {
922 $shortcode['[yaymail_domain]'] = parse_url( get_site_url() )['host'];
923 } else {
924 $shortcode['[yaymail_domain]'] = '';
925 }
926
927 $shortcode['[yaymail_user_account_url]'] = '<a style="color:' . $text_link_color . '; font-weight: normal; text-decoration: underline;" href="' . wc_get_page_permalink( 'myaccount' ) . '">' . esc_url( wc_get_page_permalink( 'myaccount' ) ) . '</a>';
928 $shortcode['[yaymail_user_account_url_string]'] = wc_get_page_permalink( 'myaccount' );
929
930 // ADDITIONAL ORDER META:
931 $order_metaArr = get_post_meta( $this->order_id );
932 if ( is_array( $order_metaArr ) && count( $order_metaArr ) > 0 ) {
933 foreach ( $order_metaArr as $k => $v ) {
934 $nameField = str_replace( ' ', '_', trim( $k ) );
935 $nameShorcode = '[yaymail_post_meta:' . $nameField . ']';
936
937 // when array $v has tow value ???
938 if ( is_array( $v ) && count( $v ) > 0 ) {
939 $shortcode[ $nameShorcode ] = trim( $v[0] );
940 } else {
941 $shortcode[ $nameShorcode ] = trim( $v );
942 }
943 }
944 }
945
946 /*
947 To get custom fields support Checkout Field Editor for WooCommerce */
948 // funtion wc_get_custom_checkout_fields of Plugin Checkout Field Editor ????
949 if ( ! empty( $order ) ) {
950 if ( function_exists( 'wc_get_custom_checkout_fields' ) ) {
951 $custom_fields = wc_get_custom_checkout_fields( $order );
952 if ( ! empty( $custom_fields ) ) {
953 foreach ( $custom_fields as $key => $custom_field ) {
954 $shortcode[ '[yaymail_' . $key . ']' ] = get_post_meta( $order->get_id(), $key, true );
955 }
956 }
957 }
958 }
959 if ( ! empty( $order ) ) {
960 foreach ( $order->get_meta_data() as $meta ) {
961 $nameField = str_replace( ' ', '_', trim( $meta->get_data()['key'] ) );
962 $nameShorcode = '[yaymail_order_meta:' . $nameField . ']';
963 if ( is_array( $meta->get_data()['value'] ) ) {
964 $checkNestedArray = false;
965 foreach ( $meta->get_data()['value'] as $value ) {
966 if ( is_object( $value ) || is_array( $value ) ) {
967 $checkNestedArray = true;
968 break;
969 }
970 }
971 if ( false == $checkNestedArray ) {
972 $shortcode[ $nameShorcode ] = implode( ', ', $meta->get_data()['value'] );
973 } else {
974 $shortcode[ $nameShorcode ] = '';
975 }
976 } else {
977 $shortcode[ $nameShorcode ] = $meta->get_data()['value'];
978 }
979 }
980 }
981
982 $this->order_data = $shortcode;
983 }
984
985 public function defaultSampleOrderData( $sent_to_admin = '' ) {
986 $current_user = wp_get_current_user();
987 $postID = CustomPostType::postIDByTemplate( $this->template );
988 $text_link_color = get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) ? get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) : '#96588A';
989 $billing_address = "John Doe<br/>YayCommerce<br/>7400 Edwards Rd<br/>Edwards Rd<br/><a href='tel:+18587433828' style='color: " . $text_link_color . "; font-weight: normal; text-decoration: underline;'>(910) 529-1147</a><br/>";
990 $shipping_address = "John Doe<br/>YayCommerce<br/>755 E North Grove Rd<br/>Mayville, Michigan<br/><a href='tel:+18587433828' style='color: " . $text_link_color . "; font-weight: normal; text-decoration: underline;'>(910) 529-1147</a><br/>";
991 $user_id = get_current_user_id();
992 $yaymail_settings = get_option( 'yaymail_settings' );
993 $yaymail_informations = array(
994 'post_id' => $postID,
995 'yaymail_elements' => get_post_meta( $postID, '_yaymail_elements', true ),
996 'template' => $this->template,
997 'general_settings' => array(
998 'tableWidth' => $yaymail_settings['container_width'],
999 'emailBackgroundColor' => get_post_meta( $postID, '_email_backgroundColor_settings', true ) ? get_post_meta( $postID, '_email_backgroundColor_settings', true ) : '#ECECEC',
1000 'textLinkColor' => get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) ? get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) : '#96588A',
1001 ),
1002 );
1003
1004 // Link Downloadable Product
1005 $shortcode['[yaymail_items_downloadable_title]'] = $this->itemsDownloadableTitle( '', $this->order, $sent_to_admin, '' ); // done
1006 $shortcode['[yaymail_items_downloadable_product]'] = $this->itemsDownloadableProduct( '', $this->order, $sent_to_admin, '' ); // done
1007
1008 // ORDER DETAILS
1009 $shortcode['[yaymail_items_border]'] = $this->itemsBorder( '', $this->order, $sent_to_admin ); // done
1010
1011 $shortcode['[yaymail_items_border_before]'] = $this->itemsBorderBefore( '', $this->order, $sent_to_admin ); // done
1012 $shortcode['[yaymail_items_border_after]'] = $this->itemsBorderAfter( '', $this->order, $sent_to_admin ); // done
1013 $shortcode['[yaymail_items_border_title]'] = $this->itemsBorderTitle( '', $this->order, $sent_to_admin ); // done
1014 $shortcode['[yaymail_items_border_content]'] = $this->itemsBorderContent( '', $this->order, $sent_to_admin ); // done
1015 $shortcode['[yaymail_get_heading]'] = $this->getEmailHeading( '', $this->order, $sent_to_admin );
1016
1017 // WC HOOK
1018 $shortcode['[woocommerce_email_before_order_table]'] = $this->orderWoocommerceBeforeHook( array(), $sent_to_admin, 'sampleOrder' ); // not changed
1019 $shortcode['[woocommerce_email_after_order_table]'] = $this->orderWoocommerceAfterHook( array(), $sent_to_admin, 'sampleOrder' ); // not changed
1020
1021 // Yith-woocommerce-wishlist-premium
1022 // if ( function_exists( 'yith_wishlist_constructor' ) ) {
1023 // $shortcode['[yaymail_yith_wishlist_email_admin]'] = $this->yithWishlistEmailAdmin( '', $this->order, $sent_to_admin );
1024 // $shortcode['[yaymail_yith_wishlist_item_title]'] = $this->yithWishlistItemTitle( '', $this->order, $sent_to_admin );
1025 // $shortcode['[yaymail_yith_wishlist_item]'] = $this->yithWishlistItem( '', $this->order, $sent_to_admin );
1026 // $shortcode['[yaymail_yith_wishlist_additional_info]'] = $this->yithWishlistAdditionalInfo( '', $this->order, $sent_to_admin );
1027 // $shortcode['[yaymail_yith_wishlist_additional_data]'] = $this->yithWishlistAdditionalData( '', $this->order, $sent_to_admin );
1028 // $shortcode['[yaymail_yith_wishlist_customer_details]'] = $this->yithWishlistCustomerDetails( '', $this->order, $sent_to_admin );
1029 // }
1030
1031 // Define shortcode from plugin addon
1032 $shortcode = apply_filters( 'yaymail_do_shortcode', $shortcode, $yaymail_informations, '' );
1033
1034 $shortcode['[yaymail_items]'] = $this->orderItems( array(), $sent_to_admin, 'sampleOrder' );
1035 $shortcode['[yaymail_order_date]'] = gmdate( 'd-m-Y' );
1036 $shortcode['[yaymail_order_fee]'] = 0;
1037 $shortcode['[yaymail_order_id]'] = 1;
1038 $shortcode['[yaymail_order_link]'] = '<a href="" style="color:' . $text_link_color . ';">' . esc_html__( 'Order', 'yaymail' ) . '</a>';
1039 $shortcode['[yaymail_order_number]'] = '1';
1040 $shortcode['[yaymail_order_refund]'] = 0;
1041 $shortcode['[yaymail_order_sub_total]'] = '£18.00';
1042 $shortcode['[yaymail_order_total]'] = '£18.00';
1043
1044 // PAYMENTS
1045 $shortcode['[yaymail_order_payment_method]'] = 'Direct bank transfer';
1046 $shortcode['[yaymail_order_payment_url]'] = '<a href="">' . esc_html__( 'Payment page', 'yaymail' ) . '</a>';
1047 $shortcode['[yaymail_order_payment_url_string]'] = '';
1048 $shortcode['[yaymail_payment_method]'] = 'Check payments';
1049 $shortcode['[yaymail_transaction_id]'] = 1;
1050
1051 // SHIPPINGS
1052 $shortcode['[yaymail_order_shipping]'] = '333';
1053 $shortcode['[yaymail_shipping_address]'] = $shipping_address;
1054 $shortcode['[yaymail_shipping_address_1]'] = '755 E North Grove Rd';
1055 $shortcode['[yaymail_shipping_address_2]'] = '755 E North Grove Rd';
1056 $shortcode['[yaymail_shipping_city]'] = 'Mayville, Michigan';
1057 $shortcode['[yaymail_shipping_company]'] = 'YayCommerce';
1058 $shortcode['[yaymail_shipping_country]'] = '';
1059 $shortcode['[yaymail_shipping_first_name]'] = 'John';
1060 $shortcode['[yaymail_shipping_last_name]'] = 'Doe';
1061 $shortcode['[yaymail_shipping_method]'] = '';
1062 $shortcode['[yaymail_shipping_postcode]'] = '48744';
1063 $shortcode['[yaymail_shipping_state]'] = 'Random';
1064
1065 // BILLING
1066 $shortcode['[yaymail_billing_address]'] = $billing_address;
1067 $shortcode['[yaymail_billing_address_1]'] = '7400 Edwards Rd';
1068 $shortcode['[yaymail_billing_address_2]'] = '7400 Edwards Rd';
1069 $shortcode['[yaymail_billing_city]'] = 'Edwards Rd';
1070 $shortcode['[yaymail_billing_company]'] = 'YayCommerce';
1071 $shortcode['[yaymail_billing_country]'] = '';
1072 $shortcode['[yaymail_billing_email]'] = '[email protected]';
1073 $shortcode['[yaymail_billing_first_name]'] = 'John';
1074 $shortcode['[yaymail_billing_last_name]'] = 'Doe';
1075 $shortcode['[yaymail_billing_phone]'] = '(910) 529-1147';
1076 $shortcode['[yaymail_billing_postcode]'] = '48744';
1077 $shortcode['[yaymail_billing_state]'] = 'Random';
1078
1079 // RESET PASSWORD:
1080 $shortcode['[yaymail_password_reset_url]'] = '<a style="color:' . $text_link_color . ';" href="">' . esc_html__( 'Click here to reset your password', 'woocommerce' ) . '</a>';
1081 $shortcode['[yaymail_password_reset_url_string]'] = get_site_url() . '/my-account/lost-password/?login';
1082
1083 // NEW USERS:
1084 $shortcode['[yaymail_user_new_password]'] = 'G(UAM1(eIX#G';
1085 $shortcode['[yaymail_user_activation_link]'] = '';
1086
1087 // GENERALS
1088 $shortcode['[yaymail_customer_note]'] = 'note';
1089 $shortcode['[yaymail_customer_notes]'] = 'notes';
1090 $shortcode['[yaymail_customer_provided_note]'] = 'provided note';
1091 $shortcode['[yaymail_site_name]'] = get_bloginfo( 'name' );
1092 $shortcode['[yaymail_site_url]'] = '<a href="' . get_site_url() . '"> ' . get_site_url() . ' </a>';
1093 $shortcode['[yaymail_site_url_string]'] = get_site_url();
1094 $shortcode['[yaymail_user_email]'] = $current_user->data->user_email;
1095 $shortcode['[yaymail_user_id]'] = $user_id;
1096 $shortcode['[yaymail_customer_username]'] = $current_user->data->user_login;
1097 $shortcode['[yaymail_customer_name]'] = get_user_meta( $current_user->data->ID, 'first_name', true ) . ' ' . get_user_meta( $current_user->data->ID, 'last_name', true );
1098 $shortcode['[yaymail_view_order_url]'] = '';
1099 $shortcode['[yaymail_view_order_url_string]'] = '';
1100 $shortcode['[yaymail_billing_shipping_address]'] = $this->billingShippingAddress( '', $this->order ); // done
1101
1102 $shortcode['[yaymail_billing_shipping_address_title]'] = $this->billingShippingAddressTitle( '', $this->order ); // done
1103 $shortcode['[yaymail_billing_shipping_address_content]'] = $this->billingShippingAddressContent( '', $this->order ); // done
1104 $shortcode['[yaymail_check_billing_shipping_address]'] = $this->checkBillingShippingAddress( '', $this->order ); // done
1105
1106 $shortcode['[yaymail_domain]'] = parse_url( get_site_url() )['host'];
1107 $shortcode['[yaymail_user_account_url]'] = '<a style="color:' . $text_link_color . '; font-weight: normal; text-decoration: underline;" href="' . wc_get_page_permalink( 'myaccount' ) . '">' . esc_url( wc_get_page_permalink( 'myaccount' ) ) . '</a>';
1108 $shortcode['[yaymail_user_account_url_string]'] = wc_get_page_permalink( 'myaccount' );
1109
1110 // ADDITIONAL ORDER META:
1111 $order = CustomPostType::getListOrders();
1112 $order_metaArr = get_post_meta( isset( $order[0]['id'] ) ? $order[0]['id'] : '' );
1113 if ( is_array( $order_metaArr ) && count( $order_metaArr ) > 0 ) {
1114 foreach ( $order_metaArr as $k => $v ) {
1115 $nameField = str_replace( ' ', '_', trim( $k ) );
1116 $nameShorcode = '[yaymail_post_meta:' . $nameField . ']';
1117
1118 // when array $v has tow value ???
1119 if ( is_array( $v ) && count( $v ) > 0 ) {
1120 $shortcode[ $nameShorcode ] = trim( $v[0] );
1121 } else {
1122 $shortcode[ $nameShorcode ] = trim( $v );
1123 }
1124 }
1125 }
1126
1127 $this->order_data = $shortcode;
1128 }
1129
1130 public function ordetItemTables( $order, $default_args ) {
1131 $items = $order->get_items();
1132 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-order-items.php';
1133 $yaymail_settings = get_option( 'yaymail_settings' );
1134
1135 $show_product_image = isset( $yaymail_settings['product_image'] ) ? $yaymail_settings['product_image'] : 0;
1136 $show_product_sku = isset( $yaymail_settings['product_sku'] ) ? $yaymail_settings['product_sku'] : 0;
1137 $default_args['image_size'][0] = isset( $yaymail_settings['image_width'] ) ? $yaymail_settings['image_width'] : 32;
1138 $default_args['image_size'][1] = isset( $yaymail_settings['image_height'] ) ? $yaymail_settings['image_height'] : 32;
1139 $default_args['image_size'][2] = isset( $yaymail_settings['image_size'] ) ? $yaymail_settings['image_size'] : 'thumbnail';
1140
1141 $args = array(
1142 'order' => $order,
1143 'items' => $order->get_items(),
1144 'show_download_links' => $order->is_download_permitted() && ! $default_args['sent_to_admin'],
1145 'show_sku' => $show_product_sku,
1146 'show_purchase_note' => $order->is_paid() && ! $default_args['sent_to_admin'],
1147 'show_image' => $show_product_image,
1148 'image_size' => $default_args['image_size'],
1149 'plain_text' => $default_args['plain_text'],
1150 'sent_to_admin' => $default_args['sent_to_admin'],
1151 'order_item_table_border_color' => isset( $yaymail_settings['background_color_table_items'] ) ? $yaymail_settings['background_color_table_items'] : '#dddddd',
1152 );
1153 include $path;
1154 }
1155 public function itemsBorder( $atts, $order, $sent_to_admin = '' ) {
1156 if ( null === $order ) {
1157 ob_start();
1158 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/sampleOrder/email-order-details-border.php';
1159 include $path;
1160 $html = ob_get_contents();
1161 ob_end_clean();
1162 return $html;
1163 } else {
1164 ob_start();
1165 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-order-details-border.php';
1166 include $path;
1167 $html = ob_get_contents();
1168 ob_end_clean();
1169 return $html;
1170 }
1171
1172 }
1173
1174 /* Link Downloadable Product - start */
1175 public function itemsDownloadableTitle( $atts, $order, $sent_to_admin = '', $items = array() ) {
1176 if ( null !== $order ) {
1177 $items = $order->get_items();
1178 $downloads = $order->get_downloadable_items();
1179 }
1180 ob_start();
1181 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-order-item-download-title.php';
1182 include $path;
1183 $html = ob_get_contents();
1184 ob_end_clean();
1185 return $html;
1186 }
1187 public function itemsDownloadableProduct( $atts, $order, $sent_to_admin = '', $items = array() ) {
1188 if ( null === $order ) {
1189 ob_start();
1190 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/sampleOrder/email-order-item-download.php';
1191 include $path;
1192 $html = ob_get_contents();
1193 ob_end_clean();
1194 return $html;
1195 } else {
1196 $items = $order->get_items();
1197 ob_start();
1198 $downloads = $order->get_downloadable_items();
1199 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-order-item-download.php';
1200 include $path;
1201 $html = ob_get_contents();
1202 ob_end_clean();
1203 return $html;
1204 }
1205 }
1206
1207 /* Order items border - start */
1208 public function itemsBorderBefore( $atts, $order, $sent_to_admin = '' ) {
1209 if ( null === $order ) {
1210 return '';
1211 } else {
1212 ob_start();
1213 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-order-details-border-before.php';
1214 include $path;
1215 $html = ob_get_contents();
1216 ob_end_clean();
1217 return $html;
1218 }
1219 }
1220
1221 public function itemsBorderAfter( $atts, $order, $sent_to_admin = '' ) {
1222 if ( null === $order ) {
1223 return '';
1224 } else {
1225 ob_start();
1226 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-order-details-border-after.php';
1227 include $path;
1228 $html = ob_get_contents();
1229 ob_end_clean();
1230 return $html;
1231 }
1232 }
1233
1234 public function itemsBorderTitle( $atts, $order, $sent_to_admin = '' ) {
1235 if ( null === $order ) {
1236 ob_start();
1237 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/sampleOrder/email-order-details-border-title.php';
1238 include $path;
1239 $html = ob_get_contents();
1240 ob_end_clean();
1241 return $html;
1242 } else {
1243 ob_start();
1244 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-order-details-border-title.php';
1245 include $path;
1246 $html = ob_get_contents();
1247 ob_end_clean();
1248 return $html;
1249 }
1250 }
1251
1252 public function itemsBorderContent( $atts, $order, $sent_to_admin = '' ) {
1253 if ( null === $order ) {
1254 ob_start();
1255 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/sampleOrder/email-order-details-border-content.php';
1256 include $path;
1257 $html = ob_get_contents();
1258 ob_end_clean();
1259 return $html;
1260 } else {
1261 ob_start();
1262 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-order-details-border-content.php';
1263 include $path;
1264 $html = ob_get_contents();
1265 ob_end_clean();
1266 return $html;
1267 }
1268 }
1269 /* Order items border - end */
1270
1271 public function billingShippingAddress( $atts, $order ) {
1272 $postID = CustomPostType::postIDByTemplate( $this->template );
1273 $text_link_color = get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) ? get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) : '#96588A';
1274 if ( null !== $order ) {
1275 $shipping_address = class_exists( 'Flexible_Checkout_Fields_Disaplay_Options' ) ? $this->shipping_address : $order->get_formatted_shipping_address();
1276 $billing_address = class_exists( 'Flexible_Checkout_Fields_Disaplay_Options' ) ? $this->billing_address : $order->get_formatted_billing_address();
1277 if ( $order->get_billing_phone() ) {
1278 $billing_address .= "<br/> <a href='tel:" . esc_html( $order->get_billing_phone() ) . "' style='color:" . $text_link_color . "; font-weight: normal; text-decoration: underline;'>" . esc_html( $order->get_billing_phone() ) . '</a>';
1279 }
1280 if ( $order->get_billing_email() ) {
1281 $billing_address .= "<br/><a href='mailto:" . esc_html( $order->get_billing_email() ) . "' style='color:" . $text_link_color . ";font-weight: normal; text-decoration: underline;'>" . esc_html( $order->get_billing_email() ) . '</a>';
1282 }
1283 } else {
1284 $billing_address = "John Doe<br/>YayCommerce<br/>7400 Edwards Rd<br/>Edwards Rd<br/><a href='tel:+18587433828' style='color: " . $text_link_color . "; font-weight: normal; text-decoration: underline;'>(910) 529-1147</a><br/>";
1285 $shipping_address = "John Doe<br/>YayCommerce<br/>755 E North Grove Rd<br/>Mayville, Michigan<br/><a href='tel:+18587433828' style='color: " . $text_link_color . "; font-weight: normal; text-decoration: underline;'>(910) 529-1147</a><br/>";
1286 }
1287 ob_start();
1288 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-billing-shipping-address.php';
1289 $order = $this->order;
1290 include $path;
1291 $html = ob_get_contents();
1292 ob_end_clean();
1293 return $html;
1294
1295 }
1296
1297 /* Billing Shipping Address - start */
1298 public function billingShippingAddressTitle( $atts, $order ) {
1299 $postID = CustomPostType::postIDByTemplate( $this->template );
1300 $text_link_color = get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) ? get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) : '#96588A';
1301 if ( null !== $order ) {
1302 $shipping_address = class_exists( 'Flexible_Checkout_Fields_Disaplay_Options' ) ? $this->shipping_address : $order->get_formatted_shipping_address();
1303 $billing_address = class_exists( 'Flexible_Checkout_Fields_Disaplay_Options' ) ? $this->billing_address : $order->get_formatted_billing_address();
1304 } else {
1305 $billing_address = "John Doe<br/>YayCommerce<br/>7400 Edwards Rd<br/>Edwards Rd<br/><a href='tel:+18587433828' style='color: " . $text_link_color . "; font-weight: normal; text-decoration: underline;'>(910) 529-1147</a><br/>";
1306 $shipping_address = "John Doe<br/>YayCommerce<br/>755 E North Grove Rd<br/>Mayville, Michigan<br/><a href='tel:+18587433828' style='color: " . $text_link_color . "; font-weight: normal; text-decoration: underline;'>(910) 529-1147</a><br/>";
1307 }
1308 ob_start();
1309 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-billing-shipping-address-title.php';
1310 $order = $this->order;
1311 include $path;
1312 $html = ob_get_contents();
1313 ob_end_clean();
1314 return $html;
1315 }
1316
1317 public function checkBillingShippingAddress( $atts, $order_id ) {
1318 $isShippingAddress = false;
1319 $isBillingAddress = false;
1320
1321 if ( ! empty( $billing_address ) ) {
1322 $isBillingAddress = true;
1323 }
1324 if ( ! empty( $shipping_address ) ) {
1325 $isShippingAddress = true;
1326 }
1327
1328 $args = array(
1329 'isShippingAddress' => $isShippingAddress,
1330 'isBillingAddress' => $isBillingAddress,
1331 );
1332
1333 return 'Checking_here';
1334 }
1335
1336 public function billingShippingAddressContent( $atts, $order ) {
1337 $postID = CustomPostType::postIDByTemplate( $this->template );
1338 $text_link_color = get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) ? get_post_meta( $postID, '_yaymail_email_textLinkColor_settings', true ) : '#96588A';
1339 if ( null !== $order ) {
1340 $shipping_address = class_exists( 'Flexible_Checkout_Fields_Disaplay_Options' ) ? $this->shipping_address : $order->get_formatted_shipping_address();
1341 $billing_address = class_exists( 'Flexible_Checkout_Fields_Disaplay_Options' ) ? $this->billing_address : $order->get_formatted_billing_address();
1342 if ( $order->get_billing_phone() ) {
1343 $billing_address .= "<br/> <a href='tel:" . esc_html( $order->get_billing_phone() ) . "' style='color:" . $text_link_color . "; font-weight: normal; text-decoration: underline;'>" . esc_html( $order->get_billing_phone() ) . '</a>';
1344 }
1345 if ( $order->get_billing_email() ) {
1346 $billing_address .= "<br/><a href='mailto:" . esc_html( $order->get_billing_email() ) . "' style='color:" . $text_link_color . ";font-weight: normal; text-decoration: underline;'>" . esc_html( $order->get_billing_email() ) . '</a>';
1347 }
1348 } else {
1349 $billing_address = "John Doe<br/>YayCommerce<br/>7400 Edwards Rd<br/>Edwards Rd<br/><a href='tel:+18587433828' style='color: " . $text_link_color . "; font-weight: normal; text-decoration: underline;'>(910) 529-1147</a><br/>";
1350 $shipping_address = "John Doe<br/>YayCommerce<br/>755 E North Grove Rd<br/>Mayville, Michigan<br/><a href='tel:+18587433828' style='color: " . $text_link_color . "; font-weight: normal; text-decoration: underline;'>(910) 529-1147</a><br/>";
1351 }
1352 ob_start();
1353 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-billing-shipping-address-content.php';
1354 $order = $this->order;
1355 include $path;
1356 $html = ob_get_contents();
1357 ob_end_clean();
1358 return $html;
1359 }
1360 /* Billing Shipping Address - end */
1361
1362 public function orderItems( $items, $sent_to_admin = '', $checkOrder = '' ) {
1363 if ( 'sampleOrder' === $checkOrder ) {
1364 ob_start();
1365 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/sampleOrder/email-order-details.php';
1366 $order = $this->order;
1367 include $path;
1368 $html = ob_get_contents();
1369 ob_end_clean();
1370 return $html;
1371
1372 } else {
1373 ob_start();
1374 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/email-order-details.php';
1375 $order = $this->order;
1376 include $path;
1377 $html = ob_get_contents();
1378 ob_end_clean();
1379 return $html;
1380 }
1381
1382 }
1383 public function getOrderCustomerNotes( $customerNotes ) {
1384 ob_start();
1385 foreach ( $customerNotes as $customerNote ) {
1386 ?>
1387
1388 <?php echo wp_kses_post( $customerNote->comment_content ); ?>
1389
1390 <?php
1391 }
1392 $html = ob_get_contents();
1393 ob_end_clean();
1394 return $html;
1395 }
1396
1397 /* Woocommerce Hook - End */
1398 public function orderWoocommerceBeforeHook( $args, $sent_to_admin = '', $checkOrder = '' ) {
1399 if ( 'sampleOrder' === $checkOrder ) {
1400 return '[woocommerce_email_before_order_table]';
1401 } else {
1402 $order = $this->order;
1403 ob_start();
1404 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/wc-email-before.php';
1405 include $path;
1406 $html = ob_get_contents();
1407 ob_end_clean();
1408 return $html;
1409 }
1410 }
1411 public function orderWoocommerceAfterHook( $args, $sent_to_admin = '', $checkOrder = '' ) {
1412 if ( 'sampleOrder' === $checkOrder ) {
1413 return '[woocommerce_email_after_order_table]';
1414 } else {
1415 $order = $this->order;
1416 ob_start();
1417 $path = YAYMAIL_PLUGIN_PATH . 'views/templates/emails/wc-email-after.php';
1418 include $path;
1419 $html = ob_get_contents();
1420 ob_end_clean();
1421 return $html;
1422 }
1423 }
1424 public function getEmailHeading( $args, $order, $sent_to_admin ) {
1425 if ( isset($args['email_heading']) && !empty($args)) {
1426 $email_heading = $args['email_heading'];
1427 } else {
1428 if (isset($order)) {
1429 $orderID = $order->get_id();
1430 $email_heading = 'Order Refunded: ' . $order->get_id();
1431 } else {
1432 $email_heading = 'Order Refunded: 1';
1433 }
1434 }
1435 return $email_heading;
1436 }
1437 }
1438