WCEmailTemplateAutoApplier.php
2 months ago
WCEmailTemplateChangeSummary.php
2 months ago
WCEmailTemplateDivergenceDetector.php
2 months ago
WCEmailTemplateSelectiveApplier.php
2 months ago
WCEmailTemplateSyncBackfill.php
2 months ago
WCEmailTemplateSyncRegistry.php
4 months ago
WCEmailTemplateSyncTracker.php
2 months ago
WCTransactionalEmailPostsGenerator.php
2 months ago
WCTransactionalEmailPostsManager.php
4 months ago
WCTransactionalEmails.php
1 month ago
WCTransactionalEmails.php
133 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_pos_completed_order', |
| 33 | 'customer_pos_refunded_order', |
| 34 | 'customer_processing_order', |
| 35 | 'customer_refunded_order', |
| 36 | 'customer_partially_refunded_order', |
| 37 | 'customer_reset_password', |
| 38 | 'customer_review_request', |
| 39 | 'customer_verify_email', |
| 40 | 'failed_order', |
| 41 | 'new_order', |
| 42 | ); |
| 43 | |
| 44 | /** |
| 45 | * Email template generator instance. |
| 46 | * |
| 47 | * @var WCTransactionalEmailPostsGenerator |
| 48 | */ |
| 49 | private $email_template_generator; |
| 50 | |
| 51 | /** |
| 52 | * Constructor. |
| 53 | * |
| 54 | * Initializes the WCTransactionalEmailPostsGenerator by setting up the template generator. |
| 55 | */ |
| 56 | public function __construct() { |
| 57 | $this->email_template_generator = new WCTransactionalEmailPostsGenerator(); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Initialize the class. |
| 62 | * |
| 63 | * @internal |
| 64 | */ |
| 65 | final public function init() { |
| 66 | add_action( 'current_screen', array( $this, 'init_email_templates' ), 50 ); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Get the core transactional emails. |
| 71 | * |
| 72 | * @return array |
| 73 | */ |
| 74 | public static function get_core_transactional_emails() { |
| 75 | $emails = self::$core_transactional_emails; |
| 76 | |
| 77 | if ( FeaturesUtil::feature_is_enabled( 'fulfillments' ) ) { |
| 78 | $fulfillment_emails = array( |
| 79 | 'customer_fulfillment_created', |
| 80 | 'customer_fulfillment_updated', |
| 81 | 'customer_fulfillment_deleted', |
| 82 | ); |
| 83 | $emails = array_merge( $emails, $fulfillment_emails ); |
| 84 | } |
| 85 | |
| 86 | return $emails; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Get the Core WooCommerce transactional emails for the block editor. |
| 91 | * |
| 92 | * @return array |
| 93 | */ |
| 94 | public static function get_transactional_emails() { |
| 95 | $emails = self::get_core_transactional_emails(); |
| 96 | |
| 97 | /** |
| 98 | * Filter the transactional emails for the block editor. |
| 99 | * |
| 100 | * @param array $transactional_emails The transactional emails. |
| 101 | * @return array |
| 102 | * @since 9.9.0 |
| 103 | */ |
| 104 | return apply_filters( 'woocommerce_transactional_emails_for_block_editor', $emails ); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Initialize email templates on WooCommerce admin pages. |
| 109 | */ |
| 110 | public function init_email_templates() { |
| 111 | if ( ! function_exists( 'wc_get_screen_ids' ) ) { |
| 112 | return; |
| 113 | } |
| 114 | |
| 115 | $screen = get_current_screen(); |
| 116 | |
| 117 | $wc_screen_ids = array_merge( |
| 118 | wc_get_screen_ids(), |
| 119 | array( |
| 120 | 'woocommerce_page_wc-admin', |
| 121 | 'edit-woo_email', |
| 122 | ) |
| 123 | ); |
| 124 | |
| 125 | if ( ! $screen || ! in_array( $screen->id, $wc_screen_ids, true ) ) { |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | // run only on WooCommerce admin pages. |
| 130 | $this->email_template_generator->initialize(); |
| 131 | } |
| 132 | } |
| 133 |