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2.0-rc.1 3.0.9 6.2.0-rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Internal / StockNotifications / Emails / EmailManager.php
woocommerce / src / Internal / StockNotifications / Emails Last commit date
CustomerStockNotificationEmail.php 1 month ago CustomerStockNotificationVerifiedEmail.php 1 month ago CustomerStockNotificationVerifyEmail.php 1 month ago EmailActionController.php 1 month ago EmailManager.php 4 days ago EmailTemplatesController.php 10 months ago
EmailManager.php
321 lines
1 <?php
2
3 declare( strict_types = 1 );
4
5 namespace Automattic\WooCommerce\Internal\StockNotifications\Emails;
6
7 use Automattic\WooCommerce\Enums\TaxDisplayMode;
8 use Automattic\WooCommerce\Internal\StockNotifications\Notification;
9 use Automattic\WooCommerce\Internal\StockNotifications\Factory;
10 use Automattic\WooCommerce\Internal\StockNotifications\Emails\CustomerStockNotificationEmail;
11 use Automattic\WooCommerce\Internal\StockNotifications\Emails\CustomerStockNotificationVerifyEmail;
12 use Automattic\WooCommerce\Internal\StockNotifications\Emails\CustomerStockNotificationVerifiedEmail;
13 use Automattic\WooCommerce\Internal\StockNotifications\Emails\EmailTemplatesController;
14 /**
15 * Emails manager.
16 */
17 class EmailManager {
18
19 /**
20 * List of all core email IDs.
21 *
22 * @var array
23 */
24 public static $email_ids = array(
25 'customer_stock_notification',
26 'customer_stock_notification_verify',
27 'customer_stock_notification_verified',
28 );
29
30 /**
31 * Initialize the emails.
32 *
33 * @internal
34 *
35 * @return void
36 */
37 final public function init() {
38
39 // Setup email hooks & handlers.
40 add_filter( 'woocommerce_email_classes', array( $this, 'email_classes' ) );
41
42 // Add "transactional" emails.
43 add_action( 'woocommerce_email_actions', array( $this, 'add_transactional_emails' ) );
44
45 // Setup styles.
46 add_filter( 'woocommerce_email_styles', array( $this, 'add_stylesheets' ), 10, 2 );
47
48 // Preview.
49 add_filter( 'woocommerce_prepare_email_for_preview', array( $this, 'prepare_email_for_preview' ) );
50 add_filter( 'woocommerce_email_preview_email_content_setting_ids', array( $this, 'add_intro_content_to_preview_settings' ), 10, 2 );
51
52 // Restore customer's context while rendering the emails.
53 add_action( 'woocommerce_email_stock_notification_product', array( $this, 'maybe_restore_customer_tax_location_data' ), 9 );
54
55 // Register email templates.
56 $container = wc_get_container();
57 $container->get( EmailTemplatesController::class );
58 }
59
60 /**
61 * Registers custom emails classes.
62 *
63 * @param array $emails Array of email classes.
64 * @return array
65 */
66 public function email_classes( $emails ) {
67 $emails['WC_Email_Customer_Stock_Notification'] = new CustomerStockNotificationEmail();
68 $emails['WC_Email_Customer_Stock_Notification_Verify'] = new CustomerStockNotificationVerifyEmail();
69 $emails['WC_Email_Customer_Stock_Notification_Verified'] = new CustomerStockNotificationVerifiedEmail();
70
71 return $emails;
72 }
73
74 /**
75 * Adds transactional emails.
76 *
77 * Stock notifications are sent via a custom AS job.
78 * Additionally, two transactional emails are dispatched during the signup and verification processes,
79 * which need to be included in the actions array to support deferred email functionality.
80 *
81 * @hook woocommerce_defer_transactional_emails
82 *
83 * @param array $actions The list of actions.
84 * @return array
85 */
86 public function add_transactional_emails( $actions ) {
87 if ( ! is_array( $actions ) ) {
88 return $actions;
89 }
90
91 $actions[] = 'woocommerce_customer_stock_notification_verify';
92 $actions[] = 'woocommerce_customer_stock_notification_verified';
93
94 return $actions;
95 }
96
97 /**
98 * Restore customer tax location data from notification's metadata
99 * to display product prices in emails using the customer's tax location, if applicable.
100 *
101 * @param Notification $notification The notification object.
102 * @return void
103 */
104 public function maybe_restore_customer_tax_location_data( $notification ) {
105
106 // No need if stores displaying price excluding tax.
107 if ( TaxDisplayMode::INCLUSIVE !== get_option( 'woocommerce_tax_display_shop' ) ) {
108 return;
109 }
110
111 // Check if for some reason (e.g., 3PD), a WC_Customer is already assigned into the BG process's context.
112 if ( ! empty( WC()->customer ) ) {
113 return;
114 }
115
116 // Get the recorded customer data, if any.
117 $location = $notification->get_meta( '_customer_location_data' );
118 if ( empty( $location ) || ! is_array( $location ) || 4 !== count( $location ) ) {
119 return;
120 }
121
122 // Restore the tax location.
123 add_filter(
124 'woocommerce_get_tax_location',
125 function () use ( $location ) {
126 return $location;
127 }
128 );
129 }
130
131 /**
132 * Prints CSS in the emails.
133 *
134 * @param string $css The CSS to print.
135 * @param WC_Email $email (Optional) The email object.
136 * @return string
137 */
138 public function add_stylesheets( $css, $email = null ) {
139
140 /**
141 * `woocommerce_email_stock_notification_emails_to_style` filter.
142 *
143 * @since 10.2.0
144 *
145 * @return array
146 */
147 if ( ( is_null( $email ) || ! in_array( $email->id, (array) apply_filters( 'woocommerce_email_stock_notification_emails_to_style', self::$email_ids ), true ) ) ) {
148 return $css;
149 }
150
151 // General text.
152 $text = get_option( 'woocommerce_email_text_color' );
153
154 // Primary color.
155 $base = get_option( 'woocommerce_email_base_color' );
156
157 /**
158 * `woocommerce_email_stock_notification_base_text_color` filter.
159 *
160 * @since 10.2.0
161 *
162 * @return string
163 */
164 $base_text = (string) apply_filters( 'woocommerce_email_stock_notification_base_text_color', wc_light_or_dark( $base, '#202020', '#ffffff' ), $email );
165
166 ob_start();
167 ?>
168 #header_wrapper h1 {
169 line-height: 1em !important;
170 }
171 #notification__container {
172 color: <?php echo esc_attr( $text ); ?> !important;
173 padding: 20px 20px;
174 text-align: center;
175 font-family: "Helvetica Neue", Helvetica, Roboto, Arial, sans-serif;
176 width: 100%;
177 }
178 #notification__into_content {
179 margin-bottom: 48px;
180 color: <?php echo esc_attr( $text ); ?> !important;
181 }
182 #notification__product__image {
183 text-align: center;
184 margin-bottom: 20px;
185 width: 100%;
186 }
187 #notification__product__image img {
188 margin-right: 0;
189 width: 220px;
190 }
191 #notification__product__title {
192 font-size: 16px;
193 font-weight: bold;
194 line-height: 130%;
195 margin-bottom: 5px;
196 color: <?php echo esc_attr( $text ); ?> !important;
197 }
198 #notification__product__attributes table {
199 width: 100%;
200 padding: 0;
201 margin: 0;
202 color: <?php echo esc_attr( $text ); ?> !important;
203 }
204 #notification__product__attributes th,
205 #notification__product__attributes td {
206 color: <?php echo esc_attr( $text ); ?> !important;
207 padding: 4px !important;
208 text-align: center;
209 }
210 #notification__product__price {
211 margin-bottom: 20px;
212 color: <?php echo esc_attr( $text ); ?> !important;
213 }
214 #notification__action_button {
215 text-decoration: none;
216 display: inline-block;
217 background: <?php echo esc_attr( $base ); ?>;
218 color: <?php echo esc_attr( $base_text ); ?> !important;
219 border: 10px solid <?php echo esc_attr( $base ); ?>;
220 }
221 #notification__verification_expiration {
222 font-size: 0.8em;
223 margin-top: 20px;
224 color: <?php echo esc_attr( $text ); ?>;
225 }
226 #notification__footer {
227 text-align: center;
228 margin-top: 20px;
229 color: <?php echo esc_attr( $text ); ?>;
230 }
231 #notification__unsubscribe_link {
232 color: <?php echo esc_attr( $text ); ?>;
233 }
234 #notification__product__price .screen-reader-text {
235 display: none;
236 }
237 <?php
238 $css .= ob_get_clean();
239
240 return $css;
241 }
242
243 /**
244 * Register intro_content email fields to be watched by WooCommerce's live email preview.
245 *
246 * @param array $setting_ids The email content setting IDs.
247 * @param string $email_id The email ID.
248 * @return array
249 */
250 public function add_intro_content_to_preview_settings( $setting_ids, $email_id ) {
251
252 if ( in_array( $email_id, self::$email_ids, true ) ) {
253 $setting_ids[] = "woocommerce_{$email_id}_intro_content";
254 }
255
256 return $setting_ids;
257 }
258
259 /**
260 * Prepares the email for preview.
261 *
262 * @param \WC_Email $email The email object being previewed.
263 * @return \WC_Email
264 */
265 public function prepare_email_for_preview( $email ) {
266 if ( ! in_array( $email->id, self::$email_ids, true ) ) {
267 return $email;
268 }
269
270 $notification = Factory::create_dummy_notification();
271 $email->prepare_email( $notification );
272
273 return $email;
274 }
275
276 /**
277 * Send a stock notification email.
278 *
279 * @param Notification $notification The notification object.
280 * @return void
281 */
282 public function send_stock_notification_email( Notification $notification ) {
283 $emails = WC()->mailer()->get_emails();
284 $email = $emails['WC_Email_Customer_Stock_Notification'] ?? null;
285
286 if ( $email instanceof CustomerStockNotificationEmail ) {
287 $email->trigger( $notification );
288 }
289 }
290
291 /**
292 * Send the double opt-in verification email for a stock notification.
293 *
294 * @param Notification $notification The notification object.
295 * @return void
296 */
297 public function send_verify_email( Notification $notification ) {
298 $emails = WC()->mailer()->get_emails();
299 $email = $emails['WC_Email_Customer_Stock_Notification_Verify'] ?? null;
300
301 if ( $email instanceof CustomerStockNotificationVerifyEmail ) {
302 $email->trigger( $notification );
303 }
304 }
305
306 /**
307 * Send the sign-up confirmation email for a stock notification.
308 *
309 * @param Notification $notification The notification object.
310 * @return void
311 */
312 public function send_verified_email( Notification $notification ) {
313 $emails = WC()->mailer()->get_emails();
314 $email = $emails['WC_Email_Customer_Stock_Notification_Verified'] ?? null;
315
316 if ( $email instanceof CustomerStockNotificationVerifiedEmail ) {
317 $email->trigger( $notification );
318 }
319 }
320 }
321