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

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

434 lines 18.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YayMail\MailBuilder;
4
5 use YayMail\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 public static function getInstance() {
22 if ( null == self::$instance ) {
23 self::$instance = new self();
24 self::$instance->doHooks();
25 }
26
27 return self::$instance;
28 }
29
30 private function doHooks() {
31 $this->templateAccount = array( 'customer_new_account', 'customer_new_account_activation', 'customer_reset_password' );
32 $this->templateGermanizedForWC = array( 'sab_simple_invoice', 'sab_cancellation_invoice', 'sab_packing_slip', 'sab_document_admin', 'sab_document' );
33 add_filter( 'storeabill_get_template', array( $this, 'storeabill_get_template' ), 100, 5 );
34 add_filter( 'wc_get_template', array( $this, 'getTemplateMail' ), 100, 5 );
35 add_filter( 'fue_before_sending_email', array( $this, 'getFollowUpTemplates' ), 100, 3 );
36 if ( class_exists( 'WC_PIP_Loader' ) && class_exists( 'YayMailWooPrintInvoices\\templateDefault\\DefaultInvoice' ) && class_exists( 'YayMailWooPrintInvoices\\templateDefault\\DefaultPickList' ) ) {
37 PIPTemplate::handle_trigger();
38 }
39 add_filter( 'retrieve_password_message', array( $this, 'admin_reset_password' ), 100, 4 );
40 add_action( 'automatewoo_before_action_run', array( $this, 'automatewoo_before_action_run' ), 10 );
41 add_filter( 'automatewoo/referrals/invite_email/mailer', array( $this, 'automatewoo_invite_email' ), 100, 2 );
42
43 if ( class_exists( 'WCFM' ) ) {
44 $WCFMWooFM_Template = CustomPostType::postIDByTemplate( 'WCFMWooFM_Template' );
45 if ( get_post_meta( $WCFMWooFM_Template, '_yaymail_status', true ) ) {
46 global $WCFM;
47 remove_action( 'wcfm_email_content_wrapper', array( $WCFM, 'wcfm_email_content_wrapper' ), 10 );
48 add_filter( 'wcfm_email_content_wrapper', array( &$this, 'wcfm_email_content_wrapper' ), 1, 2 );
49 }
50 }
51
52 add_filter( 'wpml_translate_single_string', array( $this, 'yaymail_ywces_new_template' ), 1, 3 );
53 // change german market template dir
54 $this->yaymail_get_german_market_templates();
55 }
56
57 public function yaymail_ywces_new_template( $mail_body_content, $admin_mail_body_text, $mail_body_text ) {
58 if ( class_exists( 'YayMailYITHWooCouponEmailSystem\templateDefault\DefaultCouponEmailSystem' ) && class_exists( 'YITH_WC_Coupon_Email_System' ) && false !== strpos( $mail_body_text, 'ywces_mailbody_' ) ) {
59 $mail_body_text_explode = explode( 'ywces_mailbody_', $mail_body_text );
60 $email_template_type = $mail_body_text_explode[1];
61 $template = 'YWCES_' . $email_template_type;
62 $postID = CustomPostType::postIDByTemplate( $template );
63 if ( $postID ) {
64 if ( get_post_meta( $postID, '_yaymail_status', true ) && ! empty( get_post_meta( $postID, '_yaymail_elements', true ) ) ) {
65 $check_YWCES = true;
66 $templateActive = file_exists( YAYMAIL_PLUGIN_PATH . 'views/templates/single-mail-template.php' ) ? YAYMAIL_PLUGIN_PATH . 'views/templates/single-mail-template.php' : false;
67 ob_start();
68 include $templateActive;
69 $template_body = ob_get_contents();
70 // Replace newline (\n) in a string to YAYMAIL_YWCES_YAY
71 $template_body = str_replace( "\n", 'YAYMAIL_YWCES_YAY', $template_body );
72 ob_end_clean();
73 return $template_body;
74 }
75 }
76 }
77
78 return $mail_body_content;
79 }
80
81 public function yaymail_get_german_market_templates() {
82 if ( class_exists( 'Woocommerce_German_Market' ) ) {
83 add_filter(
84 'wgm_locate_template',
85 function( $template, $template_name, $template_path ) {
86 if ( 'emails/customer-confirm-order.php' === $template_name ) {
87 $postID = CustomPostType::postIDByTemplate( 'wgm_confirm_order_email' );
88 $template_status = get_post_meta( $postID, '_yaymail_status', true );
89 if ( $template_status ) {
90 return YAYMAIL_PLUGIN_PATH . 'views/templates/emails/customer-confirm-order.php';
91 }
92 } elseif ( 'double-opt-in-customer-registration.php' === $template_name ) {
93 $postID = CustomPostType::postIDByTemplate( 'wgm_double_opt_in_customer_registration' );
94 $template_status = get_post_meta( $postID, '_yaymail_status', true );
95 if ( $template_status ) {
96 return YAYMAIL_PLUGIN_PATH . 'views/templates/emails/double-opt-in-customer-registration.php';
97 }
98 } elseif ( 'emails/sepa-mandate.php' === $template_name ) {
99 $postID = CustomPostType::postIDByTemplate( 'wgm_sepa' );
100 $template_status = get_post_meta( $postID, '_yaymail_status', true );
101 if ( $template_status ) {
102 return YAYMAIL_PLUGIN_PATH . 'views/templates/emails/sepa.php';
103 }
104 }
105 return $template;
106 },
107 100,
108 3
109 );
110 }
111 }
112
113 public function wcfm_email_content_wrapper( $content_body, $email_heading ) {
114 $template = 'WCFMWooFM_Template';
115 $postID = CustomPostType::postIDByTemplate( 'WCFMWooFM_Template' );
116 $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;
117 $args = array(
118 'order' => null,
119 'content_body' => $content_body,
120 'email_heading' => $email_heading,
121 );
122 ob_start();
123 include $templateActive;
124 $template_body = ob_get_contents();
125 ob_end_clean();
126 return $template_body;
127 }
128
129 public function automatewoo_invite_email( $mailer, $invite_email ) {
130 if ( defined( 'YAYMAIL_ADDON_AUTOMATEWOO' ) && ! empty( YAYMAIL_ADDON_AUTOMATEWOO ) ) {
131 $template = 'AutomateWoo_Referrals_Email';
132 $postID = CustomPostType::postIDByTemplate( $template );
133 $template_status = get_post_meta( $postID, '_yaymail_status', true );
134 if ( $template_status ) {
135 $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;
136 ob_start();
137 include $templateActive;
138 $template_body = ob_get_contents();
139 ob_end_clean();
140 if ( '' !== $template_body ) {
141 $template_body = $invite_email->replace_variables( $template_body );
142 $this->automatewoo_referrals_email_content = $template_body;
143 }
144 add_filter(
145 'woocommerce_mail_content',
146 function( $email_content ) {
147 return $this->automatewoo_referrals_email_content;
148 },
149 100,
150 1
151 );
152 }
153 }
154 return $mailer;
155 }
156 public function automatewoo_before_action_run( $action ) {
157 if ( defined( 'YAYMAIL_ADDON_AUTOMATEWOO' ) && ! empty( YAYMAIL_ADDON_AUTOMATEWOO ) ) {
158 $this->automatewoo_info = $action;
159 $template = 'AutomateWoo_' . $action->workflow->get_id();
160 $postID = CustomPostType::postIDByTemplate( $template );
161 $template_status = get_post_meta( $postID, '_yaymail_status', true );
162 if ( $template_status ) {
163 add_filter(
164 'woocommerce_mail_content',
165 function( $html ) {
166 $workflow = $this->automatewoo_info->workflow;
167 $template = 'AutomateWoo_' . $workflow->get_id();
168 $postID = CustomPostType::postIDByTemplate( $template );
169 $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;
170 $raw_data = $workflow->data_layer()->get_raw_data();
171 $args = array(
172 'order' => isset( $raw_data['order'] ) ? $raw_data['order'] : null,
173 'subscription' => isset( $raw_data['subscription'] ) ? $raw_data['subscription'] : null,
174 'email' => '',
175 'workflow' => $workflow,
176 );
177
178 ob_start();
179 include $templateActive;
180 $template_body = ob_get_contents();
181 ob_end_clean();
182 if ( '' !== $template_body ) {
183 $template_body = $workflow->variable_processor()->process_field( $template_body, true );
184 $email = new \AutomateWoo\Workflow_Email( $workflow, '', '', $template_body );
185 $get_mailer = $email->get_mailer();
186 if ( $workflow->is_tracking_enabled() ) {
187 $template_body = $get_mailer->inject_tracking_pixel( $template_body );
188 $template_body = $get_mailer->replace_urls_in_content( $template_body );
189 }
190 $template_body = $get_mailer->style_inline( $template_body );
191 return $template_body;
192 }
193 return $html;
194 },
195 10
196 );
197 }
198 }
199 }
200
201 public function storeabill_get_template( $located, $template_name, $args, $template_path, $default_path ) {
202 $this_template = false;
203 $templateActive = file_exists( YAYMAIL_PLUGIN_PATH . 'views/templates/single-mail-template.php' ) ? YAYMAIL_PLUGIN_PATH . 'views/templates/single-mail-template.php' : false;
204 $template = isset( $args['email'] ) && isset( $args['email']->id ) && ! empty( $args['email']->id ) ? $args['email']->id : false;
205
206 if ( $template ) {
207 if ( CustomPostType::postIDByTemplate( $template ) ) {
208 $postID = CustomPostType::postIDByTemplate( $template );
209 if ( get_post_meta( $postID, '_yaymail_status', true ) && ! empty( get_post_meta( $postID, '_yaymail_elements', true ) ) ) {
210 if ( in_array( $template, $this->templateGermanizedForWC ) ) { // template mail with account
211 $this_template = $templateActive;
212 }
213 }
214 }
215 }
216 $this_template = $this_template ? $this_template : $located;
217 return $this_template;
218 }
219
220 private function __construct() {}
221 // define the woocommerce_new_order callback
222
223 public function admin_reset_password( $message, $key, $user_login, $user_data ) {
224 $this_template = false;
225 $templateActive = file_exists( YAYMAIL_PLUGIN_PATH . 'views/templates/single-mail-template.php' ) ? YAYMAIL_PLUGIN_PATH . 'views/templates/single-mail-template.php' : false;
226 $template = 'customer_reset_password';
227 $email = array(
228 'id' => 'customer_reset_password',
229 'user_login' => $user_login,
230 'user_id' => $user_data->ID,
231 'user_email' => $user_data->data->user_email,
232 'user_data' => $user_data,
233 'key' => $key,
234 );
235 $args = array(
236 'email' => (object) $email,
237 'sent_to_admin' => false,
238 'reset_key' => $key,
239 );
240 $holder_order = isset( $args['order'] ) ? $args['order'] : null;
241 if ( CustomPostType::postIDByTemplate( $template, $holder_order ) ) {
242 $postID = CustomPostType::postIDByTemplate( $template, $holder_order );
243 if ( get_post_meta( $postID, '_yaymail_status', true ) && ! empty( get_post_meta( $postID, '_yaymail_elements', true ) ) ) {
244 if ( isset( $args['order'] ) || in_array( $template, $this->templateAccount ) ) { // template mail with order
245 $this_template = $templateActive;
246 }
247 }
248 }
249 $template_path = '';
250 $template_name = 'emails/customer-reset-password.php';
251 if ( false !== $this_template ) {
252 ob_start();
253 include $this_template;
254 $message = ob_get_contents();
255 ob_end_clean();
256 $site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
257 // translators: none.
258 $title = sprintf( __( '[%s] Password Reset', 'yaymail' ), $site_name );
259 wc_mail( $email['user_email'], $title, $message );
260 $message = false;
261 }
262 return $message;
263 }
264
265 // support addon TrackShip for WooCommerce
266 public function woocommerce_mail_content( $html ) {
267 $trackshipArgs = $this->trackShipArgs;
268 $template = 'trackship_' . $trackshipArgs['new_status'];
269 $postID = CustomPostType::postIDByTemplate( $template );
270 $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;
271 $args = array(
272 'order_id' => isset( $trackshipArgs['order_id'] ) ? $trackshipArgs['order_id'] : '0',
273 'show_shipment_status' => isset( $trackshipArgs['show_shipment_status'] ) ? $trackshipArgs['show_shipment_status'] : false,
274 'new_status' => isset( $trackshipArgs['new_status'] ) ? $trackshipArgs['new_status'] : '',
275 'tracking_items' => isset( $trackshipArgs['tracking_items'] ) ? $trackshipArgs['tracking_items'] : array(),
276 'shipment_status' => isset( $trackshipArgs['shipment_status'] ) ? $trackshipArgs['shipment_status'] : array(),
277 );
278
279 ob_start();
280 include $templateActive;
281 $template_body = ob_get_contents();
282 ob_end_clean();
283 if ( '' !== $template_body ) {
284 return $template_body;
285 }
286 return $html;
287
288 }
289
290 public function getTemplateMail( $located, $template_name, $args, $template_path, $default_path ) {
291 // support addon TrackShip for WooCommerce
292 if ( 'emails/tracking-info.php' == $template_name ) {
293 $this->trackShipArgs = $args;
294 if ( isset( $args['new_status'] ) ) {
295 $template = 'trackship_' . $args['new_status'];
296 $postID = CustomPostType::postIDByTemplate( $template );
297 $template_status = get_post_meta( $postID, '_yaymail_status', true );
298 if ( $template_status ) {
299 add_filter( 'woocommerce_mail_content', array( $this, 'woocommerce_mail_content' ), 100 );
300 }
301 }
302 }
303 $this_template = false;
304 $templateActive = file_exists( YAYMAIL_PLUGIN_PATH . 'views/templates/single-mail-template.php' ) ? YAYMAIL_PLUGIN_PATH . 'views/templates/single-mail-template.php' : false;
305 if ( isset( $args['yith_wc_email'] ) && isset( $args['yith_wc_email']->id ) && ! empty( $args['yith_wc_email']->id ) ) {
306 // Get Email ID in yith-woocommerce-multi-vendor-premium
307 $template = $args['yith_wc_email']->id;
308 } else {
309 $template = isset( $args['email'] ) && isset( $args['email']->id ) && ! empty( $args['email']->id ) ? $args['email']->id : false;
310 if ( 'dokan-wholesale/' == $template_path ) {
311 $template = 'Dokan_Email_Wholesale_Register';
312 }
313 if ( 'new-user-registration.php' == $template_name ) {
314 $template = 'wp_crowdfunding_new_user';
315 }
316 if ( 'campaign-accepted.php' == $template_name ) {
317 $template = 'wp_crowdfunding_campaign_accept';
318 }
319 if ( 'submit-campaign.php' == $template_name ) {
320 $template = 'wp_crowdfunding_submit_campaign';
321 }
322 if ( 'campaign-updated.php' == $template_name ) {
323 $template = 'wp_crowdfunding_campaign_update_email';
324 }
325 if ( 'new-backed.php' == $template_name ) {
326 $template = 'wp_crowdfunding_new_backed';
327 }
328 if ( 'campaign-target-reached.php' == $template_name ) {
329 $template = 'wp_crowdfunding_target_reached_email';
330 }
331 if ( 'withdraw-request.php' == $template_name ) {
332 $template = 'wp_crowdfunding_withdraw_request';
333 }
334 if ( class_exists( 'WC_Smart_Coupons' ) ) {
335 if ( isset( $args['email'] ) && strpos( $located, plugin_dir_path( WC_SC_PLUGIN_FILE ) ) !== false ) {
336 $templateName = str_replace( plugin_dir_path( WC_SC_PLUGIN_FILE ) . 'templates/', '', $located );
337 if ( 'email.php' == $templateName ) {
338 $template = 'wc_sc_email_coupon';
339 $args['id'] = 'wc_sc_email_coupon';
340 }
341 if ( 'combined-email.php' == $templateName ) {
342 $template = 'wc_sc_combined_email_coupon';
343 $args['id'] = 'wc_sc_combined_email_coupon';
344 }
345 if ( 'acknowledgement-email.php' == $templateName ) {
346 $template = 'wc_sc_acknowledgement_email';
347 $args['id'] = 'wc_sc_acknowledgement_email';
348 }
349 }
350 }
351 if ( 'emails/waitlist-mailout.php' == $template_name ) {
352 $template = 'woocommerce_waitlist_mailout';
353 }
354 if ( 'emails/waitlist-left.php' == $template_name ) {
355 $template = 'woocommerce_waitlist_left_email';
356 }
357 if ( 'emails/waitlist-joined.php' == $template_name ) {
358 $template = 'woocommerce_waitlist_joined_email';
359 }
360 if ( 'emails/waitlist-new-signup.php' == $template_name ) {
361 $template = 'woocommerce_waitlist_signup_email';
362 }
363
364 if ( 'emails/dokan-admin-new-booking.php' == $template_name ) {
365 $template = 'Dokan_Email_Booking_New';
366 }
367 if ( 'emails/dokan-customer-booking-cancelled.php' == $template_name ) {
368 $template = 'Dokan_Email_Booking_Cancelled_NEW';
369 }
370 }
371
372 if ( isset( $args['email'] ) && isset( $args['email']->id ) && false !== strpos( get_class( $args['email'] ), 'ORDDD_Email_Delivery_Reminder' ) ) {
373 $template .= '_customer';
374 }
375
376 // can't load tempalte email-delivery-date.php because it will has error when check out, with plugin WooCommerce Order Delivery
377 if ( $template && 'emails/email-delivery-date.php' != $template_name && 'emails/email-order-details.php' != $template_name ) {
378
379 // Yith Stripe
380
381 if ( 'emails/expiring-card-email.php' === $template_name ) {
382 $template = 'expiring_card';
383 }
384 if ( 'emails/renew-needs-action-email.php' === $template_name ) {
385 $template = 'renew_needs_action';
386 }
387
388 if ( 'emails/admin-notify-approved.php' === $template_name ) {
389 $template = 'admin_notify_approved';
390 }
391 if ( 'customer_partially_refunded_order' === $template ) {
392 $template = 'customer_refunded_order';
393 }
394 if ( CustomPostType::postIDByTemplate( $template ) ) {
395 $postID = CustomPostType::postIDByTemplate( $template );
396 if ( get_post_meta( $postID, '_yaymail_status', true ) && ! empty( get_post_meta( $postID, '_yaymail_elements', true ) ) ) {
397 if ( isset( $args['order'] ) || in_array( $template, $this->templateAccount ) ) { // template mail with order
398 $this_template = $templateActive;
399 } else {
400 $checkHasTempalte = apply_filters( 'yaymail_addon_defined_template', false, $template );
401 if ( $checkHasTempalte ) { // template mail with account
402 $this_template = $templateActive;
403 }
404 }
405 }
406 }
407 }
408 $this_template = $this_template ? $this_template : $located;
409 return $this_template;
410 }
411
412 public function getFollowUpTemplates( $email_data, $email, $queue_item ) {
413 if ( has_filter( 'yaymail_follow_up_shortcode' ) ) {
414 $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;
415 $template = 'follow_up_email_' . $email->id;
416 $postID = CustomPostType::postIDByTemplate( $template );
417 $template_status = get_post_meta( $postID, '_yaymail_status', true );
418 $args = array(
419 'email_data' => $email_data,
420 'email' => $email,
421 'queue_item' => $queue_item,
422 );
423 if ( $template_status ) {
424 ob_start();
425 include $templateActive;
426 $template_body = ob_get_contents();
427 ob_end_clean();
428 $email_data['message'] = $template_body;
429 }
430 }
431 return $email_data;
432 }
433 }
434