PluginProbe
YayMail – WooCommerce Email Customizer / 3.3.7
YayMail – WooCommerce Email Customizer v3.3.7
4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 All 57 releases
yaymail / includes / MailBuilder / WooTemplate.php

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

555 lines 22.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\Page\Source\CustomPostType;
6 use YayMail\MailBuilder\PIPTemplate;
7
8 defined( 'ABSPATH' ) || exit;
9 /**
10 * Settings Page
11 */
12 class WooTemplate {
13
14
15 protected static $instance = null;
16 private $templateAccount;
17 private $templateSubscription;
18 private $automatewoo_info = null;
19 private $automatewoo_referrals_email_content = null;
20 private $trackShipArgs = null;
21 private $FUE_Sending_Email_Variables = null;
22 public static function getInstance() {
23 if ( null == self::$instance ) {
24 self::$instance = new self();
25 self::$instance->doHooks();
26 }
27
28 return self::$instance;
29 }
30
31 private function doHooks() {
32 $this->templateAccount = array( 'customer_new_account', 'customer_new_account_activation', 'customer_reset_password' );
33 $this->templateGermanizedForWC = array( 'sab_simple_invoice', 'sab_cancellation_invoice', 'sab_packing_slip', 'sab_document_admin', 'sab_document' );
34 add_filter( 'storeabill_get_template', array( $this, 'storeabill_get_template' ), 100, 5 );
35 add_filter( 'wc_get_template', array( $this, 'getTemplateMail' ), 100, 5 );
36
37 if ( has_filter( 'YaymailCreateFollowUpTemplates' ) ) {
38 add_action( 'fue_before_variable_replacements', array( $this, 'register_variable_replacements' ), 100, 4 );
39 add_filter( 'fue_before_sending_email', array( $this, 'getFollowUpTemplates' ), 100, 3 );
40 }
41
42 if ( class_exists( 'WC_PIP_Loader' ) && class_exists( 'YayMailWooPrintInvoices\\templateDefault\\DefaultInvoice' ) && class_exists( 'YayMailWooPrintInvoices\\templateDefault\\DefaultPickList' ) ) {
43 PIPTemplate::handle_trigger();
44 }
45 add_filter( 'retrieve_password_message', array( $this, 'admin_reset_password' ), 100, 4 );
46 add_action( 'automatewoo_before_action_run', array( $this, 'automatewoo_before_action_run' ), 10 );
47 add_filter( 'automatewoo/referrals/invite_email/mailer', array( $this, 'automatewoo_invite_email' ), 100, 2 );
48
49 if ( class_exists( 'WCFM' ) ) {
50 $WCFMWooFM_Template = CustomPostType::postIDByTemplate( 'WCFMWooFM_Template' );
51 if ( get_post_meta( $WCFMWooFM_Template, '_yaymail_status', true ) ) {
52 global $WCFM;
53 remove_action( 'wcfm_email_content_wrapper', array( $WCFM, 'wcfm_email_content_wrapper' ), 10 );
54 add_filter( 'wcfm_email_content_wrapper', array( &$this, 'wcfm_email_content_wrapper' ), 1, 2 );
55 }
56 }
57
58 add_filter( 'wpml_translate_single_string', array( $this, 'yaymail_ywces_new_template' ), 1, 3 );
59 // change german market template dir
60 $this->yaymail_get_german_market_templates();
61
62 if ( class_exists( 'CARTFLOWS_CA_Loader' ) && function_exists( 'YayMailAddonWcCartAbandonmentRecovery\\init' ) ) {
63 add_filter( 'woo_ca_recovery_email_data', array( $this, 'yaymail_addon_ca_recovery_send_mail' ), 10, 1 );
64 }
65
66 if ( class_exists( 'WPDesk\\ShopMagic\\Plugin' ) && function_exists( 'YaymailAddonShopMagicForWoocommerce\\init' ) ) {
67 add_filter( 'shopmagic/core/action/send_mail/sending', array( $this, 'yaymail_addon_shopmagic_send_mail' ) );
68 //add_action( 'shopmagic/core/initialized/v2', array( $this, 'shopmagic_do_action_external_plugins_access' ), 10, 1 );
69 add_action( 'shopmagic/core/action/before_execution', array( $this, 'shopmagic_before_send_mail' ), 10, 3 );
70 }
71 }
72
73 public function shopmagic_before_send_mail( $action, $automation, $event ) {
74 $automation_id = $automation->get_id();
75
76 if ( empty( $automation_id ) ) {
77 return;
78 }
79
80 $shopmagic_data = array(
81 'automation' => $automation,
82 'action' => $action,
83 );
84
85 session_start();
86
87 $_SESSION['shopmagic_data'] = $shopmagic_data;
88
89 }
90
91 public function shopmagic_do_action_external_plugins_access( $external_plugins_access ) {
92 $external_plugins_access->add_template_resolver( new \ShopMagicVendor\WPDesk\View\Resolver\DirResolver( YAYMAIL_ADDON_SHOP_MAGIC_FOR_WC_PLUGIN_PATH . '/views/Template' ) );
93 }
94
95 public function yaymail_addon_shopmagic_send_mail( $sending_email ) {
96 if ( ! $sending_email->get_email()->is_html() ) {
97 return $sending_email;
98 }
99
100 $shopmagic_automation = $sending_email->get_automation();
101 if ( method_exists( $shopmagic_automation, 'get_id' ) ) {
102 $shopmagic_template_id = $shopmagic_automation->get_id();
103 }
104
105 if ( isset( $shopmagic_template_id ) ) {
106 $shopmagic_template_name = 'ShopMagic_' . $shopmagic_template_id;
107 }
108
109 if ( ! empty( $shopmagic_template_name ) ) {
110 $postID = null;
111 $postID = CustomPostType::postIDByTemplate( $shopmagic_template_name );
112 $template_status = get_post_meta( $postID, '_yaymail_status', true );
113 }
114
115 if ( $template_status && ! empty( $postID ) ) {
116 $active_template = file_exists( YAYMAIL_PLUGIN_PATH . 'views/templates/single-follow-up-mail-template.php' ) ? YAYMAIL_PLUGIN_PATH . 'views/templates/single-follow-up-mail-template.php' : false;
117
118 $args['email'] = $sending_email->get_email();
119 $args['automation'] = $sending_email->get_automation();
120 $template = $shopmagic_template_name;
121 ob_start();
122 include $active_template;
123 $template_body = ob_get_contents();
124 ob_end_clean();
125 }
126
127 if ( ! empty( $template_body ) ) {
128 $sending_email->email->message = $template_body;
129 }
130
131 return $sending_email;
132 }
133
134 public function yaymail_addon_ca_recovery_send_mail( $email_data ) {
135 $ca_recovery_template_id = $email_data->email_template_id;
136
137 if ( empty( $ca_recovery_template_id ) ) {
138 return $email_data;
139 }
140 $yaymail_template_id = 'YaymailWcCaRecovery_' . $ca_recovery_template_id;
141
142 if ( ! empty( $yaymail_template_id ) ) {
143 $postID = null;
144 $postID = CustomPostType::postIDByTemplate( $yaymail_template_id );
145 $template_status = get_post_meta( $postID, '_yaymail_status', true );
146 }
147
148 if ( $template_status && ! empty( $postID ) ) {
149 $active_template = file_exists( YAYMAIL_PLUGIN_PATH . 'views/templates/single-follow-up-mail-template.php' ) ? YAYMAIL_PLUGIN_PATH . 'views/templates/single-follow-up-mail-template.php' : false;
150
151 $args['email'] = $email_data;
152 $template = $yaymail_template_id;
153 if ( $active_template ) {
154 ob_start();
155 include $active_template;
156 $template_body = ob_get_contents();
157 ob_end_clean();
158 }
159 }
160
161 if ( ! empty( $template_body ) ) {
162 $email_data->email_body = $template_body;
163 }
164
165 return $email_data;
166 }
167
168 public function yaymail_ywces_new_template( $mail_body_content, $admin_mail_body_text, $mail_body_text ) {
169 if ( class_exists( 'YayMailYITHWooCouponEmailSystem\templateDefault\DefaultCouponEmailSystem' ) && class_exists( 'YITH_WC_Coupon_Email_System' ) && false !== strpos( $mail_body_text, 'ywces_mailbody_' ) ) {
170 $mail_body_text_explode = explode( 'ywces_mailbody_', $mail_body_text );
171 $email_template_type = $mail_body_text_explode[1];
172 $template = 'YWCES_' . $email_template_type;
173 $postID = CustomPostType::postIDByTemplate( $template );
174 if ( $postID ) {
175 if ( get_post_meta( $postID, '_yaymail_status', true ) && ! empty( get_post_meta( $postID, '_yaymail_elements', true ) ) ) {
176 $check_YWCES = true;
177 $templateActive = file_exists( YAYMAIL_PLUGIN_PATH . 'views/templates/single-mail-template.php' ) ? YAYMAIL_PLUGIN_PATH . 'views/templates/single-mail-template.php' : false;
178 ob_start();
179 include $templateActive;
180 $template_body = ob_get_contents();
181 // Replace newline (\n) in a string to YAYMAIL_YWCES_YAY
182 $template_body = str_replace( "\n", 'YAYMAIL_YWCES_YAY', $template_body );
183 ob_end_clean();
184 return $template_body;
185 }
186 }
187 }
188
189 return $mail_body_content;
190 }
191
192 public function yaymail_get_german_market_templates() {
193 if ( class_exists( 'Woocommerce_German_Market' ) ) {
194 add_filter(
195 'wgm_locate_template',
196 function( $template, $template_name, $template_path ) {
197 if ( 'emails/customer-confirm-order.php' === $template_name ) {
198 $postID = CustomPostType::postIDByTemplate( 'wgm_confirm_order_email' );
199 $template_status = get_post_meta( $postID, '_yaymail_status', true );
200 if ( $template_status ) {
201 return YAYMAIL_PLUGIN_PATH . 'views/templates/emails/customer-confirm-order.php';
202 }
203 } elseif ( 'emails/double-opt-in-customer-registration.php' === $template_name ) {
204 $postID = CustomPostType::postIDByTemplate( 'wgm_double_opt_in_customer_registration' );
205 $template_status = get_post_meta( $postID, '_yaymail_status', true );
206 if ( $template_status ) {
207 return YAYMAIL_PLUGIN_PATH . 'views/templates/emails/double-opt-in-customer-registration.php';
208 }
209 } elseif ( 'emails/sepa-mandate.php' === $template_name ) {
210 $postID = CustomPostType::postIDByTemplate( 'wgm_sepa' );
211 $template_status = get_post_meta( $postID, '_yaymail_status', true );
212 if ( $template_status ) {
213 return YAYMAIL_PLUGIN_PATH . 'views/templates/emails/sepa.php';
214 }
215 }
216 return $template;
217 },
218 100,
219 3
220 );
221 }
222 }
223
224 public function wcfm_email_content_wrapper( $content_body, $email_heading ) {
225 $template = 'WCFMWooFM_Template';
226 $postID = CustomPostType::postIDByTemplate( 'WCFMWooFM_Template' );
227 $templateActive = file_exists( YAYMAIL_PLUGIN_PATH . 'views/templates/single-follow-up-mail-template.php' ) ? YAYMAIL_PLUGIN_PATH . 'views/templates/single-follow-up-mail-template.php' : false;
228 $args = array(
229 'order' => null,
230 'content_body' => $content_body,
231 'email_heading' => $email_heading,
232 );
233 ob_start();
234 include $templateActive;
235 $template_body = ob_get_contents();
236 ob_end_clean();
237 return $template_body;
238 }
239
240 public function automatewoo_invite_email( $mailer, $invite_email ) {
241 if ( defined( 'YAYMAIL_ADDON_AUTOMATEWOO' ) || ! empty( YAYMAIL_ADDON_AUTOMATEWOO ) ) {
242 $template = 'AutomateWoo_Referrals_Email';
243 $postID = CustomPostType::postIDByTemplate( $template );
244 $template_status = get_post_meta( $postID, '_yaymail_status', true );
245 if ( $template_status ) {
246 $templateActive = file_exists( YAYMAIL_PLUGIN_PATH . 'views/templates/single-follow-up-mail-template.php' ) ? YAYMAIL_PLUGIN_PATH . 'views/templates/single-follow-up-mail-template.php' : false;
247 ob_start();
248 include $templateActive;
249 $template_body = ob_get_contents();
250 ob_end_clean();
251 if ( '' !== $template_body ) {
252 $template_body = $invite_email->replace_variables( $template_body );
253 $this->automatewoo_referrals_email_content = $template_body;
254 }
255 add_filter(
256 'woocommerce_mail_content',
257 function( $email_content ) {
258 return $this->automatewoo_referrals_email_content;
259 },
260 100,
261 1
262 );
263 }
264 }
265 return $mailer;
266 }
267 public function automatewoo_before_action_run( $action ) {
268 if ( defined( 'YAYMAIL_ADDON_AUTOMATEWOO' ) && ! empty( YAYMAIL_ADDON_AUTOMATEWOO ) ) {
269 $this->automatewoo_info = $action;
270 $template = 'AutomateWoo_' . $action->workflow->get_id();
271 $postID = CustomPostType::postIDByTemplate( $template );
272 $template_status = get_post_meta( $postID, '_yaymail_status', true );
273 if ( $template_status ) {
274 add_filter(
275 'woocommerce_mail_content',
276 function( $html ) {
277 $workflow = $this->automatewoo_info->workflow;
278 $template = 'AutomateWoo_' . $workflow->get_id();
279 $postID = CustomPostType::postIDByTemplate( $template );
280 $templateActive = file_exists( YAYMAIL_PLUGIN_PATH . 'views/templates/single-follow-up-mail-template.php' ) ? YAYMAIL_PLUGIN_PATH . 'views/templates/single-follow-up-mail-template.php' : false;
281 $raw_data = $workflow->data_layer()->get_raw_data();
282 $args = array(
283 'order' => isset( $raw_data['order'] ) ? $raw_data['order'] : null,
284 'subscription' => isset( $raw_data['subscription'] ) ? $raw_data['subscription'] : null,
285 'email' => '',
286 'workflow' => $workflow,
287 );
288
289 ob_start();
290 include $templateActive;
291 $template_body = ob_get_contents();
292 ob_end_clean();
293 if ( '' !== $template_body ) {
294 $template_body = $workflow->variable_processor()->process_field( $template_body, true );
295 $email = new \AutomateWoo\Workflow_Email( $workflow, '', '', $template_body );
296 $get_mailer = $email->get_mailer();
297 if ( $workflow->is_tracking_enabled() ) {
298 $template_body = $get_mailer->inject_tracking_pixel( $template_body );
299 $template_body = $get_mailer->replace_urls_in_content( $template_body );
300 }
301 $template_body = $get_mailer->style_inline( $template_body );
302 return $template_body;
303 }
304 return $html;
305 },
306 10
307 );
308 }
309 }
310 }
311
312 public function storeabill_get_template( $located, $template_name, $args, $template_path, $default_path ) {
313 $this_template = false;
314 $templateActive = file_exists( YAYMAIL_PLUGIN_PATH . 'views/templates/single-mail-template.php' ) ? YAYMAIL_PLUGIN_PATH . 'views/templates/single-mail-template.php' : false;
315 $template = isset( $args['email'] ) && isset( $args['email']->id ) && ! empty( $args['email']->id ) ? $args['email']->id : false;
316
317 if ( $template ) {
318 if ( CustomPostType::postIDByTemplate( $template ) ) {
319 $postID = CustomPostType::postIDByTemplate( $template );
320 if ( get_post_meta( $postID, '_yaymail_status', true ) && ! empty( get_post_meta( $postID, '_yaymail_elements', true ) ) ) {
321 if ( in_array( $template, $this->templateGermanizedForWC ) ) { // template mail with account
322 $this_template = $templateActive;
323 }
324 }
325 }
326 }
327 $this_template = $this_template ? $this_template : $located;
328 return $this_template;
329 }
330
331 private function __construct() {}
332 // define the woocommerce_new_order callback
333
334 public function admin_reset_password( $message, $key, $user_login, $user_data ) {
335 $this_template = false;
336 $templateActive = file_exists( YAYMAIL_PLUGIN_PATH . 'views/templates/single-mail-template.php' ) ? YAYMAIL_PLUGIN_PATH . 'views/templates/single-mail-template.php' : false;
337 $template = 'customer_reset_password';
338 $email = array(
339 'id' => 'customer_reset_password',
340 'user_login' => $user_login,
341 'user_id' => $user_data->ID,
342 'user_email' => $user_data->data->user_email,
343 'user_data' => $user_data,
344 'key' => $key,
345 );
346 $args = array(
347 'email' => (object) $email,
348 'sent_to_admin' => false,
349 'reset_key' => $key,
350 );
351 $holder_order = isset( $args['order'] ) ? $args['order'] : null;
352 if ( CustomPostType::postIDByTemplate( $template, $holder_order ) ) {
353 $postID = CustomPostType::postIDByTemplate( $template, $holder_order );
354 if ( get_post_meta( $postID, '_yaymail_status', true ) && ! empty( get_post_meta( $postID, '_yaymail_elements', true ) ) ) {
355 if ( isset( $args['order'] ) || in_array( $template, $this->templateAccount ) ) { // template mail with order
356 $this_template = $templateActive;
357 }
358 }
359 }
360 $template_path = '';
361 $template_name = 'emails/customer-reset-password.php';
362 if ( false !== $this_template ) {
363 ob_start();
364 include $this_template;
365 $message = ob_get_contents();
366 ob_end_clean();
367 $site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
368 // translators: none.
369 $title = sprintf( __( '[%s] Password Reset', 'yaymail' ), $site_name );
370 wc_mail( $email['user_email'], $title, $message );
371 $message = false;
372 }
373 return $message;
374 }
375
376 // support addon TrackShip for WooCommerce
377 public function woocommerce_mail_content( $html ) {
378 $trackshipArgs = $this->trackShipArgs;
379 $template = 'trackship_' . $trackshipArgs['new_status'];
380 $postID = CustomPostType::postIDByTemplate( $template );
381 $templateActive = file_exists( YAYMAIL_PLUGIN_PATH . 'views/templates/single-follow-up-mail-template.php' ) ? YAYMAIL_PLUGIN_PATH . 'views/templates/single-follow-up-mail-template.php' : false;
382 $args = array(
383 'order_id' => isset( $trackshipArgs['order_id'] ) ? $trackshipArgs['order_id'] : '0',
384 'show_shipment_status' => isset( $trackshipArgs['show_shipment_status'] ) ? $trackshipArgs['show_shipment_status'] : false,
385 'new_status' => isset( $trackshipArgs['new_status'] ) ? $trackshipArgs['new_status'] : '',
386 'tracking_items' => isset( $trackshipArgs['tracking_items'] ) ? $trackshipArgs['tracking_items'] : array(),
387 'shipment_status' => isset( $trackshipArgs['shipment_status'] ) ? $trackshipArgs['shipment_status'] : array(),
388 );
389
390 ob_start();
391 include $templateActive;
392 $template_body = ob_get_contents();
393 ob_end_clean();
394 if ( '' !== $template_body ) {
395 return $template_body;
396 }
397 return $html;
398
399 }
400
401 public function getTemplateMail( $located, $template_name, $args, $template_path, $default_path ) {
402 // support addon TrackShip for WooCommerce
403 if ( 'emails/tracking-info.php' == $template_name ) {
404 $this->trackShipArgs = $args;
405 if ( isset( $args['new_status'] ) ) {
406 $template = 'trackship_' . $args['new_status'];
407 $postID = CustomPostType::postIDByTemplate( $template );
408 $template_status = get_post_meta( $postID, '_yaymail_status', true );
409 if ( $template_status ) {
410 add_filter( 'woocommerce_mail_content', array( $this, 'woocommerce_mail_content' ), 100 );
411 }
412 }
413 }
414 $this_template = false;
415 $templateActive = file_exists( YAYMAIL_PLUGIN_PATH . 'views/templates/single-mail-template.php' ) ? YAYMAIL_PLUGIN_PATH . 'views/templates/single-mail-template.php' : false;
416 if ( isset( $args['yith_wc_email'] ) && isset( $args['yith_wc_email']->id ) && ! empty( $args['yith_wc_email']->id ) ) {
417 // Get Email ID in yith-woocommerce-multi-vendor-premium
418 $template = $args['yith_wc_email']->id;
419 } else {
420 $template = isset( $args['email'] ) && isset( $args['email']->id ) && ! empty( $args['email']->id ) ? $args['email']->id : false;
421 if ( 'dokan-wholesale/' == $template_path ) {
422 $template = 'Dokan_Email_Wholesale_Register';
423 }
424 if ( 'new-user-registration.php' == $template_name ) {
425 $template = 'wp_crowdfunding_new_user';
426 }
427 if ( 'campaign-accepted.php' == $template_name ) {
428 $template = 'wp_crowdfunding_campaign_accept';
429 }
430 if ( 'submit-campaign.php' == $template_name ) {
431 $template = 'wp_crowdfunding_submit_campaign';
432 }
433 if ( 'campaign-updated.php' == $template_name ) {
434 $template = 'wp_crowdfunding_campaign_update_email';
435 }
436 if ( 'new-backed.php' == $template_name ) {
437 $template = 'wp_crowdfunding_new_backed';
438 }
439 if ( 'campaign-target-reached.php' == $template_name ) {
440 $template = 'wp_crowdfunding_target_reached_email';
441 }
442 if ( 'withdraw-request.php' == $template_name ) {
443 $template = 'wp_crowdfunding_withdraw_request';
444 }
445 if ( class_exists( 'WC_Smart_Coupons' ) ) {
446 if ( isset( $args['email'] ) && strpos( $located, plugin_dir_path( WC_SC_PLUGIN_FILE ) ) !== false ) {
447 $templateName = str_replace( plugin_dir_path( WC_SC_PLUGIN_FILE ) . 'templates/', '', $located );
448 if ( 'email.php' == $templateName ) {
449 $template = 'wc_sc_email_coupon';
450 $args['id'] = 'wc_sc_email_coupon';
451 }
452 if ( 'combined-email.php' == $templateName ) {
453 $template = 'wc_sc_combined_email_coupon';
454 $args['id'] = 'wc_sc_combined_email_coupon';
455 }
456 if ( 'acknowledgement-email.php' == $templateName ) {
457 $template = 'wc_sc_acknowledgement_email';
458 $args['id'] = 'wc_sc_acknowledgement_email';
459 }
460 }
461 }
462 if ( 'emails/waitlist-mailout.php' == $template_name ) {
463 $template = 'woocommerce_waitlist_mailout';
464 }
465 if ( 'emails/waitlist-left.php' == $template_name ) {
466 $template = 'woocommerce_waitlist_left_email';
467 }
468 if ( 'emails/waitlist-joined.php' == $template_name ) {
469 $template = 'woocommerce_waitlist_joined_email';
470 }
471 if ( 'emails/waitlist-new-signup.php' == $template_name ) {
472 $template = 'woocommerce_waitlist_signup_email';
473 }
474
475 if ( 'emails/dokan-admin-new-booking.php' == $template_name ) {
476 $template = 'Dokan_Email_Booking_New';
477 }
478 if ( 'emails/dokan-customer-booking-cancelled.php' == $template_name ) {
479 $template = 'Dokan_Email_Booking_Cancelled_NEW';
480 }
481 }
482
483 if ( isset( $args['email'] ) && isset( $args['email']->id ) && false !== strpos( get_class( $args['email'] ), 'ORDDD_Email_Delivery_Reminder' ) ) {
484 $template .= '_customer';
485 }
486
487 if ( isset( $args['email'] ) && is_object( $args['email'] ) && 'WC_GZD_Email_Customer_Cancelled_Order' === get_class( $args['email'] ) && 'customer_failed_order' === $template ) {
488 $template = 'customer_cancelled_order';
489 }
490
491 // can't load tempalte email-delivery-date.php because it will has error when check out, with plugin WooCommerce Order Delivery
492 if ( $template && 'emails/email-delivery-date.php' != $template_name && 'emails/email-order-details.php' != $template_name ) {
493
494 // Yith Stripe
495
496 if ( 'emails/expiring-card-email.php' === $template_name ) {
497 $template = 'expiring_card';
498 }
499 if ( 'emails/renew-needs-action-email.php' === $template_name ) {
500 $template = 'renew_needs_action';
501 }
502
503 if ( 'emails/admin-notify-approved.php' === $template_name ) {
504 $template = 'admin_notify_approved';
505 }
506 if ( 'customer_partially_refunded_order' === $template ) {
507 $template = 'customer_refunded_order';
508 }
509 if ( CustomPostType::postIDByTemplate( $template ) ) {
510 $postID = CustomPostType::postIDByTemplate( $template );
511 if ( get_post_meta( $postID, '_yaymail_status', true ) && ! empty( get_post_meta( $postID, '_yaymail_elements', true ) ) ) {
512 if ( isset( $args['order'] ) || in_array( $template, $this->templateAccount ) ) { // template mail with order
513 $this_template = $templateActive;
514 } else {
515 $checkHasTempalte = apply_filters( 'yaymail_addon_defined_template', false, $template );
516 if ( $checkHasTempalte ) { // template mail with account
517 $this_template = $templateActive;
518 }
519 }
520 }
521 }
522 }
523 $this_template = $this_template ? $this_template : $located;
524 return $this_template;
525 }
526
527 public function register_variable_replacements( $var, $email_data, $email, $queue_item ) {
528 $this->FUE_Sending_Email_Variables = $var;
529 }
530
531 public function getFollowUpTemplates( $email_data, $email, $queue_item ) {
532 if ( has_filter( 'yaymail_follow_up_shortcode' ) ) {
533 $templateActive = file_exists( YAYMAIL_PLUGIN_PATH . 'views/templates/single-follow-up-mail-template.php' ) ? YAYMAIL_PLUGIN_PATH . 'views/templates/single-follow-up-mail-template.php' : false;
534 $template = 'follow_up_email_' . $email->id;
535 $postID = CustomPostType::postIDByTemplate( $template );
536 $template_status = get_post_meta( $postID, '_yaymail_status', true );
537 $args = array(
538 'email_data' => $email_data,
539 'email' => $email,
540 'queue_item' => $queue_item,
541 );
542 if ( $template_status ) {
543 ob_start();
544 include $templateActive;
545 $template_body = ob_get_contents();
546 $FUE_Sending_Email_Variables = $this->FUE_Sending_Email_Variables;
547 $template_body = $FUE_Sending_Email_Variables->apply_replacements( $template_body );
548 ob_end_clean();
549 $email_data['message'] = $template_body;
550 }
551 }
552 return $email_data;
553 }
554 }
555