WCEmailTemplateAutoApplier.php
1 month ago
WCEmailTemplateChangeSummary.php
1 month ago
WCEmailTemplateDivergenceDetector.php
1 month ago
WCEmailTemplateSelectiveApplier.php
1 month ago
WCEmailTemplateSyncBackfill.php
1 month ago
WCEmailTemplateSyncRegistry.php
2 months ago
WCEmailTemplateSyncTracker.php
1 month ago
WCTransactionalEmailPostsGenerator.php
1 month ago
WCTransactionalEmailPostsManager.php
2 months ago
WCTransactionalEmails.php
1 month ago
WCTransactionalEmails.php
135 lines
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | |
| 4 | namespace Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails; |
| 5 | |
| 6 | use Automattic\WooCommerce\Utilities\FeaturesUtil; |
| 7 | |
| 8 | /** |
| 9 | * Class WCTransactionalEmails |
| 10 | * |
| 11 | * Handles the initialization and management of WooCommerce transactional emails. |
| 12 | * |
| 13 | * @package Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails |
| 14 | */ |
| 15 | class WCTransactionalEmails { |
| 16 | |
| 17 | /** |
| 18 | * Array of core transactional email types. |
| 19 | * |
| 20 | * @var array |
| 21 | */ |
| 22 | public static $core_transactional_emails = array( |
| 23 | 'admin_payment_gateway_enabled', |
| 24 | 'cancelled_order', |
| 25 | 'customer_cancelled_order', |
| 26 | 'customer_completed_order', |
| 27 | 'customer_failed_order', |
| 28 | 'customer_invoice', |
| 29 | 'customer_new_account', |
| 30 | 'customer_note', |
| 31 | 'customer_on_hold_order', |
| 32 | 'customer_processing_order', |
| 33 | 'customer_refunded_order', |
| 34 | 'customer_partially_refunded_order', |
| 35 | 'customer_reset_password', |
| 36 | 'customer_review_request', |
| 37 | 'failed_order', |
| 38 | 'new_order', |
| 39 | ); |
| 40 | |
| 41 | /** |
| 42 | * Email template generator instance. |
| 43 | * |
| 44 | * @var WCTransactionalEmailPostsGenerator |
| 45 | */ |
| 46 | private $email_template_generator; |
| 47 | |
| 48 | /** |
| 49 | * Constructor. |
| 50 | * |
| 51 | * Initializes the WCTransactionalEmailPostsGenerator by setting up the template generator. |
| 52 | */ |
| 53 | public function __construct() { |
| 54 | $this->email_template_generator = new WCTransactionalEmailPostsGenerator(); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Initialize the class. |
| 59 | * |
| 60 | * @internal |
| 61 | */ |
| 62 | final public function init() { |
| 63 | add_action( 'current_screen', array( $this, 'init_email_templates' ), 50 ); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Get the core transactional emails. |
| 68 | * |
| 69 | * @return array |
| 70 | */ |
| 71 | public static function get_core_transactional_emails() { |
| 72 | $emails = self::$core_transactional_emails; |
| 73 | |
| 74 | if ( FeaturesUtil::feature_is_enabled( 'point_of_sale' ) ) { |
| 75 | $emails[] = 'customer_pos_completed_order'; |
| 76 | $emails[] = 'customer_pos_refunded_order'; |
| 77 | } |
| 78 | |
| 79 | if ( FeaturesUtil::feature_is_enabled( 'fulfillments' ) ) { |
| 80 | $fulfillment_emails = array( |
| 81 | 'customer_fulfillment_created', |
| 82 | 'customer_fulfillment_updated', |
| 83 | 'customer_fulfillment_deleted', |
| 84 | ); |
| 85 | $emails = array_merge( $emails, $fulfillment_emails ); |
| 86 | } |
| 87 | |
| 88 | return $emails; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Get the Core WooCommerce transactional emails for the block editor. |
| 93 | * |
| 94 | * @return array |
| 95 | */ |
| 96 | public static function get_transactional_emails() { |
| 97 | $emails = self::get_core_transactional_emails(); |
| 98 | |
| 99 | /** |
| 100 | * Filter the transactional emails for the block editor. |
| 101 | * |
| 102 | * @param array $transactional_emails The transactional emails. |
| 103 | * @return array |
| 104 | * @since 9.9.0 |
| 105 | */ |
| 106 | return apply_filters( 'woocommerce_transactional_emails_for_block_editor', $emails ); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Initialize email templates on WooCommerce admin pages. |
| 111 | */ |
| 112 | public function init_email_templates() { |
| 113 | if ( ! function_exists( 'wc_get_screen_ids' ) ) { |
| 114 | return; |
| 115 | } |
| 116 | |
| 117 | $screen = get_current_screen(); |
| 118 | |
| 119 | $wc_screen_ids = array_merge( |
| 120 | wc_get_screen_ids(), |
| 121 | array( |
| 122 | 'woocommerce_page_wc-admin', |
| 123 | 'edit-woo_email', |
| 124 | ) |
| 125 | ); |
| 126 | |
| 127 | if ( ! $screen || ! in_array( $screen->id, $wc_screen_ids, true ) ) { |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | // run only on WooCommerce admin pages. |
| 132 | $this->email_template_generator->initialize(); |
| 133 | } |
| 134 | } |
| 135 |