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