PluginProbe
YayMail – WooCommerce Email Customizer / 1.9.6
YayMail – WooCommerce Email Customizer v1.9.6
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 1.9.6, at includes/MailBuilder/Shortcodes.php

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