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 / WooTemplate.php

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

58 lines 2.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->templateSubscription = array( 'cancelled_subscription', 'expired_subscription', 'suspended_subscription' );
29 $this->templateYITHSubscription = array( 'ywsbs_subscription_admin_mail', 'ywsbs_customer_subscription_cancelled', 'ywsbs_customer_subscription_suspended', 'ywsbs_customer_subscription_expired', 'ywsbs_customer_subscription_before_expired', 'ywsbs_customer_subscription_paused', 'ywsbs_customer_subscription_resumed', 'ywsbs_customer_subscription_request_payment', 'ywsbs_customer_subscription_renew_reminder', 'ywsbs_customer_subscription_payment_done', 'ywsbs_customer_subscription_payment_failed' );
30 add_filter( 'wc_get_template', array( $this, 'getTemplateMail' ), 10, 5 );
31 }
32
33 private function __construct() {}
34 // define the woocommerce_new_order callback
35 public function getTemplateMail( $located, $template_name, $args, $template_path, $default_path ) {
36 $this_template = false;
37 $templateActive = file_exists( YAYMAIL_PLUGIN_PATH . 'views/templates/single-mail-template.php' ) ? YAYMAIL_PLUGIN_PATH . 'views/templates/single-mail-template.php' : false;
38 $template = isset( $args['email'] ) && isset( $args['email']->id ) && ! empty( $args['email']->id ) ? $args['email']->id : false;
39
40 if ( $template ) {
41 if ( CustomPostType::postIDByTemplate( $template ) ) {
42 $postID = CustomPostType::postIDByTemplate( $template );
43 if ( get_post_meta( $postID, '_yaymail_status', true ) && ! empty( get_post_meta( $postID, '_yaymail_html', true ) ) ) {
44 if ( isset( $args['order'] ) ) { // template mail with order
45 $this_template = $templateActive;
46 } else {
47 if ( in_array( $template, $this->templateAccount ) || in_array( $template, $this->templateSubscription ) || in_array( $template, $this->templateYITHSubscription ) ) { // template mail with account
48 $this_template = $templateActive;
49 }
50 }
51 }
52 }
53 }
54 $this_template = $this_template ? $this_template : $located;
55 return $this_template;
56 }
57 }
58