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