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

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

169 lines 6.6 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 ('new-user-registration.php' == $template_name) {
67 $template = 'wp_crowdfunding_new_user';
68 }
69 if ('campaign-accepted.php' == $template_name) {
70 $template = 'wp_crowdfunding_campaign_accept';
71 }
72 if ('submit-campaign.php' == $template_name) {
73 $template = 'wp_crowdfunding_submit_campaign';
74 }
75 if ('campaign-updated.php' == $template_name) {
76 $template = 'wp_crowdfunding_campaign_update_email';
77 }
78 if ('new-backed.php' == $template_name) {
79 $template = 'wp_crowdfunding_new_backed';
80 }
81 if ('campaign-target-reached.php' == $template_name) {
82 $template = 'wp_crowdfunding_target_reached_email';
83 }
84 if ('withdraw-request.php' == $template_name) {
85 $template = 'wp_crowdfunding_withdraw_request';
86 }
87 if ( class_exists( 'WC_Smart_Coupons' ) ) {
88 if ( isset( $args['email'] ) && strpos( $located, plugin_dir_path( WC_SC_PLUGIN_FILE ) ) !== false ) {
89 $templateName = str_replace( plugin_dir_path( WC_SC_PLUGIN_FILE ) . 'templates/', '', $located );
90 if ( 'email.php' == $templateName ) {
91 $template = 'wc_sc_email_coupon';
92 $args['id'] = 'wc_sc_email_coupon';
93 }
94 if ( 'combined-email.php' == $templateName ) {
95 $template = 'wc_sc_combined_email_coupon';
96 $args['id'] = 'wc_sc_combined_email_coupon';
97 }
98 if ( 'acknowledgement-email.php' == $templateName ) {
99 $template = 'wc_sc_acknowledgement_email';
100 $args['id'] = 'wc_sc_acknowledgement_email';
101 }
102 }
103 }
104 if ( 'emails/waitlist-mailout.php' == $template_name ) {
105 $template = 'woocommerce_waitlist_mailout';
106 }
107 if ( 'emails/waitlist-left.php' == $template_name ) {
108 $template = 'woocommerce_waitlist_left_email';
109 }
110 if ( 'emails/waitlist-joined.php' == $template_name ) {
111 $template = 'woocommerce_waitlist_joined_email';
112 }
113 if ( 'emails/waitlist-new-signup.php' == $template_name ) {
114 $template = 'woocommerce_waitlist_signup_email';
115 }
116 }
117
118 if ( isset( $args['email'] ) && isset( $args['email']->id ) && false !== strpos( get_class( $args['email'] ), 'ORDDD_Email_Delivery_Reminder' ) ) {
119 $template .= '_customer';
120 }
121
122 if ( $template ) {
123 if ( 'emails/admin-notify-approved.php' === $template_name ) {
124 $template = 'admin_notify_approved';
125 }
126 if( $template === 'customer_partially_refunded_order') {
127 $template = 'customer_refunded_order';
128 }
129 if ( CustomPostType::postIDByTemplate( $template ) ) {
130 $postID = CustomPostType::postIDByTemplate( $template );
131 if ( get_post_meta( $postID, '_yaymail_status', true ) && ! empty( get_post_meta( $postID, '_yaymail_elements', true ) ) ) {
132 if ( isset( $args['order'] ) || in_array( $template, $this->templateAccount ) ) { // template mail with order
133 $this_template = $templateActive;
134 } else {
135 $checkHasTempalte = apply_filters( 'yaymail_addon_defined_template', false, $template );
136 if ( $checkHasTempalte ) { // template mail with account
137 $this_template = $templateActive;
138 }
139 }
140 }
141 }
142 }
143 $this_template = $this_template ? $this_template : $located;
144 return $this_template;
145 }
146
147 public function getFollowUpTemplates( $email_data, $email, $queue_item ) {
148 if ( has_filter( 'yaymail_follow_up_shortcode' ) ) {
149 $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;
150 $template = 'follow_up_email_' . $email->id;
151 $postID = CustomPostType::postIDByTemplate( $template );
152 $template_status = get_post_meta( $postID, '_yaymail_status', true );
153 $args = array(
154 'email_data' => $email_data,
155 'email' => $email,
156 'queue_item' => $queue_item,
157 );
158 if ( $template_status ) {
159 ob_start();
160 include $templateActive;
161 $template_body = ob_get_contents();
162 ob_end_clean();
163 $email_data['message'] = $template_body;
164 }
165 }
166 return $email_data;
167 }
168 }
169