PluginProbe
YayMail – WooCommerce Email Customizer / 2.1.4
YayMail – WooCommerce Email Customizer v2.1.4
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 2.1.4, at includes/MailBuilder/WooTemplate.php

142 lines 5.7 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
7 defined( 'ABSPATH' ) || exit;
8 /**
9 * Settings Page
10 */
11 class WooTemplate {
12
13
14 protected static $instance = null;
15 private $templateAccount;
16 private $templateSubscription;
17 public static function getInstance() {
18 if ( null == self::$instance ) {
19 self::$instance = new self();
20 self::$instance->doHooks();
21 }
22
23 return self::$instance;
24 }
25
26 private function doHooks() {
27 $this->templateAccount = array( 'customer_new_account', 'customer_new_account_activation', 'customer_reset_password' );
28 $this->templateGermanizedForWC = array( 'sab_simple_invoice', 'sab_cancellation_invoice' );
29 add_filter( 'storeabill_get_template', array( $this, 'storeabill_get_template' ), 100, 5 );
30 add_filter( 'wc_get_template', array( $this, 'getTemplateMail' ), 100, 5 );
31 add_filter( 'fue_before_sending_email', array( $this, 'getFollowUpTemplates' ), 100, 3 );
32 }
33
34 public function storeabill_get_template( $located, $template_name, $args, $template_path, $default_path ) {
35 $this_template = false;
36 $templateActive = file_exists( YAYMAIL_PLUGIN_PATH . 'views/templates/single-mail-template.php' ) ? YAYMAIL_PLUGIN_PATH . 'views/templates/single-mail-template.php' : false;
37 $template = isset( $args['email'] ) && isset( $args['email']->id ) && ! empty( $args['email']->id ) ? $args['email']->id : false;
38
39 if ( $template ) {
40 if ( CustomPostType::postIDByTemplate( $template ) ) {
41 $postID = CustomPostType::postIDByTemplate( $template );
42 if ( get_post_meta( $postID, '_yaymail_status', true ) && ! empty( get_post_meta( $postID, '_yaymail_elements', true ) ) ) {
43 if ( in_array( $template, $this->templateGermanizedForWC ) ) { // template mail with account
44 $this_template = $templateActive;
45 }
46 }
47 }
48 }
49 $this_template = $this_template ? $this_template : $located;
50 return $this_template;
51 }
52
53 private function __construct() {}
54 // define the woocommerce_new_order callback
55 public function getTemplateMail( $located, $template_name, $args, $template_path, $default_path ) {
56 $this_template = false;
57 $templateActive = file_exists( YAYMAIL_PLUGIN_PATH . 'views/templates/single-mail-template.php' ) ? YAYMAIL_PLUGIN_PATH . 'views/templates/single-mail-template.php' : false;
58 if ( isset( $args['yith_wc_email'] ) && isset( $args['yith_wc_email']->id ) && ! empty( $args['yith_wc_email']->id ) ) {
59 // Get Email ID in yith-woocommerce-multi-vendor-premium
60 $template = $args['yith_wc_email']->id;
61 } else {
62 $template = isset( $args['email'] ) && isset( $args['email']->id ) && ! empty( $args['email']->id ) ? $args['email']->id : false;
63 if ( 'dokan-wholesale/' == $template_path ) {
64 $template = 'Dokan_Email_Wholesale_Register';
65 }
66 if ( class_exists( 'WC_Smart_Coupons' ) ) {
67 if ( isset( $args['email'] ) && strpos( $located, plugin_dir_path( WC_SC_PLUGIN_FILE ) ) !== false ) {
68 $templateName = str_replace( plugin_dir_path( WC_SC_PLUGIN_FILE ) . 'templates/', '', $located );
69 if ( 'email.php' == $templateName ) {
70 $template = 'wc_sc_email_coupon';
71 $args['id'] = 'wc_sc_email_coupon';
72 }
73 if ( 'combined-email.php' == $templateName ) {
74 $template = 'wc_sc_combined_email_coupon';
75 $args['id'] = 'wc_sc_combined_email_coupon';
76 }
77 if ( 'acknowledgement-email.php' == $templateName ) {
78 $template = 'wc_sc_acknowledgement_email';
79 $args['id'] = 'wc_sc_acknowledgement_email';
80 }
81 }
82 }
83 if ( 'emails/waitlist-mailout.php' == $template_name ) {
84 $template = 'woocommerce_waitlist_mailout';
85 }
86 if ( 'emails/waitlist-left.php' == $template_name ) {
87 $template = 'woocommerce_waitlist_left_email';
88 }
89 if ( 'emails/waitlist-joined.php' == $template_name ) {
90 $template = 'woocommerce_waitlist_joined_email';
91 }
92 if ( 'emails/waitlist-new-signup.php' == $template_name ) {
93 $template = 'woocommerce_waitlist_signup_email';
94 }
95 }
96
97 if ( isset( $args['email'] ) && isset( $args['email']->id ) && false !== strpos( get_class( $args['email'] ), 'ORDDD_Email_Delivery_Reminder' ) ) {
98 $template .= '_customer';
99 }
100
101 if ( $template ) {
102 if ( CustomPostType::postIDByTemplate( $template ) ) {
103 $postID = CustomPostType::postIDByTemplate( $template );
104 if ( get_post_meta( $postID, '_yaymail_status', true ) && ! empty( get_post_meta( $postID, '_yaymail_elements', true ) ) ) {
105 if ( isset( $args['order'] ) || in_array( $template, $this->templateAccount ) ) { // template mail with order
106 $this_template = $templateActive;
107 } else {
108 $checkHasTempalte = apply_filters( 'yaymail_addon_defined_template', false, $template );
109 if ( $checkHasTempalte ) { // template mail with account
110 $this_template = $templateActive;
111 }
112 }
113 }
114 }
115 }
116 $this_template = $this_template ? $this_template : $located;
117 return $this_template;
118 }
119
120 public function getFollowUpTemplates( $email_data, $email, $queue_item ) {
121 if ( has_filter( 'yaymail_follow_up_shortcode' ) ) {
122 $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;
123 $template = 'follow_up_email_' . $email->id;
124 $postID = CustomPostType::postIDByTemplate( $template );
125 $template_status = get_post_meta( $postID, '_yaymail_status', true );
126 $args = array(
127 'email_data' => $email_data,
128 'email' => $email,
129 'queue_item' => $queue_item,
130 );
131 if ( $template_status ) {
132 ob_start();
133 include $templateActive;
134 $template_body = ob_get_contents();
135 ob_end_clean();
136 $email_data['message'] = $template_body;
137 }
138 }
139 return $email_data;
140 }
141 }
142