Emails
2 months ago
Integrations
2 months ago
MultichannelMarketing
2 years ago
TransactionalEmails
10 months ago
WooCommerceBookings
1 month ago
WooCommerceSubscriptions
2 months ago
CouponPreProcessor.php
2 months ago
Emails.php
8 months ago
Helper.php
1 month ago
MailPoetTask.php
2 years ago
NonPersistablePreviewData.php
1 month ago
OrderAttributionFields.php
1 month ago
OrderAttributionRevenueReader.php
2 weeks ago
OrderAttributionWriter.php
1 month ago
RandomCouponCodeGenerator.php
2 months ago
Settings.php
1 year ago
SubscriberEngagement.php
3 years ago
Subscription.php
2 months ago
Tracker.php
2 years ago
TransactionalEmailHooks.php
1 year ago
TransactionalEmails.php
1 year ago
WooSystemInfo.php
1 month ago
WooSystemInfoController.php
1 year ago
index.php
3 years ago
Emails.php
120 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\WooCommerce; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\WooCommerce\Emails\MarketingConfirmation; |
| 9 | use MailPoet\WP\Functions as WPFunctions; |
| 10 | use MailPoet\WPCOM\DotcomHelperFunctions; |
| 11 | |
| 12 | if (!defined('ABSPATH')) exit; |
| 13 | |
| 14 | /** |
| 15 | * WooCommerce Emails Manager |
| 16 | * |
| 17 | * Manages registration of MailPoet emails with WooCommerce. |
| 18 | * Only available in Garden environment. |
| 19 | */ |
| 20 | class Emails { |
| 21 | |
| 22 | /** @var DotcomHelperFunctions */ |
| 23 | private $dotcomHelperFunctions; |
| 24 | |
| 25 | /** @var WPFunctions */ |
| 26 | private $wp; |
| 27 | |
| 28 | public function __construct() { |
| 29 | $this->wp = new WPFunctions(); |
| 30 | $this->dotcomHelperFunctions = new DotcomHelperFunctions($this->wp); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Initialize the email registration. |
| 35 | */ |
| 36 | public function init() { |
| 37 | // Only register in Garden environment. |
| 38 | if (!$this->dotcomHelperFunctions->isGarden()) { |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | // Register the email classes with WooCommerce. |
| 43 | $this->wp->addFilter('woocommerce_email_classes', [$this, 'registerEmailClasses']); |
| 44 | // Register the emails for the block editor. |
| 45 | $this->wp->addFilter('woocommerce_transactional_emails_for_block_editor', [$this, 'registerTransactionalEmailsForBlockEditor']); |
| 46 | // Register the marketing email group title. |
| 47 | $this->wp->addFilter('woocommerce_email_groups', [$this, 'registerEmailGroups']); |
| 48 | // This filter is required because WCTransactionalEmailPostsGenerator does not provide the email's $template_base property when loading templates. |
| 49 | // As a result, WooCommerce attempts to load the template from its default template directory instead of MailPoet's. |
| 50 | // We need to apply this filter until this issue is addressed upstream to ensure MailPoet email templates are found. |
| 51 | $this->wp->addFilter('wc_get_template', [$this, 'locateBlockTemplate'], 10, 4); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Register MailPoet email classes with WooCommerce. |
| 56 | * |
| 57 | * @param array $email_classes Array of email classes. |
| 58 | * @return array Modified array of email classes. |
| 59 | */ |
| 60 | public function registerEmailClasses($email_classes) { |
| 61 | $email_classes['mailpoet_marketing_confirmation'] = new MarketingConfirmation(); |
| 62 | |
| 63 | return $email_classes; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Register MailPoet transactional emails for the block editor. |
| 68 | * |
| 69 | * @param array $emails Array of email IDs. |
| 70 | * @return array Modified array of email IDs. |
| 71 | */ |
| 72 | public function registerTransactionalEmailsForBlockEditor($emails) { |
| 73 | // Register marketing confirmation email for block editor |
| 74 | $emails[] = 'mailpoet_marketing_confirmation'; |
| 75 | |
| 76 | return $emails; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Register email group titles. |
| 81 | * |
| 82 | * @param array $email_groups Array of email groups. |
| 83 | * @return array Modified array of email groups. |
| 84 | */ |
| 85 | public function registerEmailGroups($email_groups) { |
| 86 | if (!isset($email_groups['marketing'])) { |
| 87 | $email_groups['marketing'] = __('Marketing', 'mailpoet'); |
| 88 | } |
| 89 | |
| 90 | return $email_groups; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Locate block templates for MailPoet emails. |
| 95 | * |
| 96 | * @param string $template The template path. |
| 97 | * @param string $template_name The template name. |
| 98 | * @param array $args The template arguments. |
| 99 | * @param string $template_path The template path. |
| 100 | * @return string The located template path. |
| 101 | */ |
| 102 | public function locateBlockTemplate($template, $template_name, $args, $template_path) { |
| 103 | // Only handle block templates for MailPoet emails |
| 104 | if (strpos($template_name, 'emails/block/marketing-confirmation.php') !== 0) { |
| 105 | return $template; |
| 106 | } |
| 107 | |
| 108 | if (file_exists($template_path)) { |
| 109 | return $template; |
| 110 | } |
| 111 | |
| 112 | $mailpoet_template = __DIR__ . '/Emails/Templates/' . $template_name; |
| 113 | if (file_exists($mailpoet_template)) { |
| 114 | return $mailpoet_template; |
| 115 | } |
| 116 | |
| 117 | return $template; |
| 118 | } |
| 119 | } |
| 120 |