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 5.2.0-beta.1 10.0.2 5.2.0-rc.1 10.0.3 5.2.0-rc.2 10.0.4 5.2.1 10.0.5 5.2.2 10.0.6 5.2.3 10.1.0 5.2.4 10.1.0-rc.1 5.2.5 10.1.0-rc.2 5.3.0 10.1.0-rc.3 5.3.0-beta.1 10.1.0-rc.4 5.3.0-rc.1 10.1.1 5.3.0-rc.2 10.1.2 5.3.1 10.1.3 5.3.2 10.1.4 5.3.3 10.2.0 5.4.0 10.2.0-beta.1 5.4.0-beta.1 10.2.0-beta.2 5.4.0-rc.1 10.2.0-rc.1 5.4.1 10.2.1 5.4.2 10.2.2 5.4.3 10.2.3 5.4.4 10.2.4 5.4.5 10.3.0 5.5.0 10.3.0-beta.1 5.5.0-beta.1 10.3.0-beta.2 5.5.0-rc.1 10.3.0-rc.1 5.5.0-rc.2 10.3.0-rc.2 5.5.1 10.3.1 5.5.2 10.3.2 5.5.3 10.3.3 5.5.4 10.3.4 5.5.5 10.3.5 5.6.0 10.3.6 5.6.0-beta.1 10.3.7 5.6.0-rc.1 10.3.8 5.6.0-rc.2 10.4.0 5.6.1 10.4.0-beta.1 5.6.2 10.4.0-beta.2 5.6.3 10.4.0-rc.1 5.7.0 10.4.1 5.7.0-beta.1 10.4.2 5.7.0-rc.1 10.4.3 5.7.1 10.4.4 5.7.2 10.5.0 5.7.3 10.5.0-beta.1 5.8.0 10.5.0-beta.2 5.8.0-beta.1 10.5.0-rc.1 5.8.0-beta.2 10.5.0-rc.2 5.8.0-rc.1 10.5.0-rc.3 5.8.1 10.5.1 5.8.2 10.5.2 5.9.0 10.5.3 5.9.0-beta.1 10.6.0 5.9.0-rc.1 10.6.0-beta.1 5.9.0-rc.2 10.6.0-beta.2 5.9.1 10.6.0-rc.1 5.9.2 10.6.1 6.0.0 10.6.2 6.0.0-beta.1 10.7.0 6.0.0-rc.1 10.7.0-beta.1 6.0.1 10.7.0-beta.2 6.0.2 10.7.0-rc.1 6.1.0 3.0.0 6.1.0-beta.1 3.0.1 6.1.0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7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / admin / settings / class-wc-settings-emails.php
woocommerce / includes / admin / settings Last commit date
views 1 month ago class-wc-settings-accounts.php 7 months ago class-wc-settings-advanced.php 2 months ago class-wc-settings-checkout.php 5 years ago class-wc-settings-emails.php 1 month ago class-wc-settings-general.php 3 months ago class-wc-settings-integrations.php 1 year ago class-wc-settings-page.php 1 month ago class-wc-settings-payment-gateways.php 2 months ago class-wc-settings-point-of-sale.php 1 month ago class-wc-settings-products.php 1 month ago class-wc-settings-shipping.php 5 months ago class-wc-settings-site-visibility.php 2 years ago class-wc-settings-tax.php 1 month ago
class-wc-settings-emails.php
1053 lines
1 <?php
2 /**
3 * WooCommerce Email Settings
4 *
5 * @package WooCommerce\Admin
6 * @version 2.1.0
7 */
8
9 use Automattic\WooCommerce\Internal\Admin\EmailPreview\EmailPreview;
10 use Automattic\WooCommerce\Internal\Email\EmailColors;
11 use Automattic\WooCommerce\Internal\Email\EmailFont;
12 use Automattic\WooCommerce\Internal\Email\EmailStyleSync;
13 use Automattic\WooCommerce\Internal\EmailEditor\EmailTemplates\WooEmailTemplate;
14 use Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails\WCTransactionalEmailPostsManager;
15 use Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails\WCEmailTemplateDivergenceDetector;
16 use Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails\WCEmailTemplateSyncRegistry;
17 use Automattic\WooCommerce\Internal\Features\FeaturesController;
18 use Automattic\WooCommerce\Utilities\FeaturesUtil;
19
20 defined( 'ABSPATH' ) || exit;
21
22 if ( class_exists( 'WC_Settings_Emails', false ) ) {
23 return new WC_Settings_Emails();
24 }
25
26 /**
27 * WC_Settings_Emails.
28 */
29 class WC_Settings_Emails extends WC_Settings_Page {
30
31 /**
32 * Constructor.
33 */
34 public function __construct() {
35 $this->id = 'email';
36 $this->label = __( 'Emails', 'woocommerce' );
37
38 add_action( 'woocommerce_admin_field_email_notification', array( $this, 'email_notification_setting' ) );
39 add_action( 'woocommerce_admin_field_email_notification_block_emails', array( $this, 'email_notification_setting_block_emails' ) );
40 add_action( 'woocommerce_admin_field_email_preview', array( $this, 'email_preview' ) );
41 add_action( 'woocommerce_admin_field_email_image_url', array( $this, 'email_image_url' ) );
42 add_action( 'woocommerce_admin_field_email_font_family', array( $this, 'email_font_family' ) );
43 add_action( 'woocommerce_admin_field_email_color_palette', array( $this, 'email_color_palette' ) );
44 add_action( 'woocommerce_admin_field_previewing_new_templates', array( $this, 'previewing_new_templates' ) );
45 add_action( 'woocommerce_admin_field_email_improvements_button', array( $this, 'email_improvements_button' ) );
46 add_action( 'woocommerce_email_settings_after', array( $this, 'email_preview_single' ) );
47 add_action( 'woocommerce_settings_saved', array( $this, 'enable_email_improvements_when_trying_new_templates' ), 999 );
48 add_filter( 'woocommerce_admin_settings_sanitize_option_woocommerce_email_header_image', array( $this, 'sanitize_email_header_image' ), 10, 3 );
49 add_filter( 'woocommerce_tracks_event_properties', array( $this, 'append_feature_email_improvements_to_tracks' ) );
50 add_action( FeaturesController::FEATURE_ENABLED_CHANGED_ACTION, array( $this, 'track_email_improvements_feature_change' ), 10, 2 );
51 parent::__construct();
52 }
53
54 /**
55 * Setting page icon.
56 *
57 * @var string
58 */
59 public $icon = 'atSymbol';
60
61 /**
62 * Get own sections.
63 *
64 * @return array
65 */
66 protected function get_own_sections() {
67 return array(
68 '' => __( 'Email options', 'woocommerce' ),
69 );
70 }
71
72 /**
73 * Get settings array.
74 *
75 * @return array
76 */
77 protected function get_settings_for_default_section() {
78 $desc_help_text = sprintf(
79 /* translators: %1$s: Link to WP Mail Logging plugin, %2$s: Link to Email FAQ support page. */
80 __( 'To ensure your store&rsquo;s notifications arrive in your and your customers&rsquo; inboxes, we recommend connecting your email address to your domain and setting up a dedicated SMTP server. If something doesn&rsquo;t seem to be sending correctly, install the <a href="%1$s">WP Mail Logging Plugin</a> or check the <a href="%2$s">Email FAQ page</a>.', 'woocommerce' ),
81 'https://wordpress.org/plugins/wp-mail-logging/',
82 'https://woocommerce.com/document/email-faq'
83 );
84
85 $block_email_editor_enabled = FeaturesUtil::feature_is_enabled( 'block_email_editor' );
86 $email_improvements_enabled = $this->get_email_improvements_enabled();
87
88 // These defaults should be chosen by the same logic as the other color option properties.
89 $default_colors = EmailColors::get_default_colors( $email_improvements_enabled );
90
91 if ( $block_email_editor_enabled ) {
92 $email_notifications_field = 'email_notification_block_emails';
93 $email_notifications_desc = null;
94 } else {
95 $email_notifications_field = 'email_notification';
96 /* translators: %s: help description with link to WP Mail logging and support page. */
97 $email_notifications_desc = sprintf( __( 'Email notifications sent from WooCommerce are listed below. Click on an email to configure it.<br>%s', 'woocommerce' ), $desc_help_text );
98 }
99
100 $settings =
101 array(
102 array(
103 'title' => __( 'Email notifications', 'woocommerce' ),
104 'desc' => $email_notifications_desc,
105 'type' => 'title',
106 'id' => 'email_notification_settings',
107 ),
108
109 array( 'type' => $email_notifications_field ),
110
111 array(
112 'type' => 'sectionend',
113 'id' => 'email_notification_settings',
114 ),
115
116 array(
117 'type' => 'sectionend',
118 'id' => 'email_recipient_options',
119 ),
120 array(
121 'title' => __( 'Email sender options', 'woocommerce' ),
122 'type' => 'title',
123 'desc' => __( "Set the name and email address you'd like your outgoing emails to use.", 'woocommerce' ),
124 'id' => 'email_options',
125 ),
126
127 array(
128 'title' => __( '"From" name', 'woocommerce' ),
129 'desc' => '',
130 'id' => 'woocommerce_email_from_name',
131 'type' => 'text',
132 'css' => 'min-width:400px;',
133 'default' => esc_attr( get_bloginfo( 'name', 'display' ) ),
134 'autoload' => false,
135 'desc_tip' => true,
136 'skip_initial_save' => true,
137 ),
138
139 array(
140 'title' => __( '"From" address', 'woocommerce' ),
141 'desc' => '',
142 'id' => 'woocommerce_email_from_address',
143 'type' => 'email',
144 'custom_attributes' => array(
145 'multiple' => 'multiple',
146 ),
147 'css' => 'min-width:400px;',
148 'default' => get_option( 'admin_email' ),
149 'autoload' => false,
150 'desc_tip' => true,
151 ),
152 );
153
154 // Add reply-to fields.
155 $settings = array_merge(
156 $settings,
157 array(
158 array(
159 'title' => __( 'Add "Reply-to" email', 'woocommerce' ),
160 'desc' => __( 'Add a different email address to receive replies.', 'woocommerce' ),
161 'id' => 'woocommerce_email_reply_to_enabled',
162 'type' => 'checkbox',
163 'default' => 'no',
164 'autoload' => false,
165 ),
166
167 array(
168 'title' => __( '"Reply-to" name', 'woocommerce' ),
169 'desc' => '',
170 'id' => 'woocommerce_email_reply_to_name',
171 'type' => 'text',
172 'css' => 'min-width:400px;',
173 'default' => '',
174 'autoload' => false,
175 'desc_tip' => true,
176 ),
177
178 array(
179 'title' => __( '"Reply-to" address', 'woocommerce' ),
180 'desc' => '',
181 'id' => 'woocommerce_email_reply_to_address',
182 'type' => 'email',
183 'css' => 'min-width:400px;',
184 'default' => '',
185 'autoload' => false,
186 'desc_tip' => true,
187 ),
188 )
189 );
190
191 $settings = array_merge(
192 $settings,
193 array(
194 array(
195 'type' => 'sectionend',
196 'id' => 'email_options',
197 ),
198 )
199 );
200
201 // If the email editor is enabled the design is handled by the email editor.
202 if ( ! $block_email_editor_enabled ) {
203 $settings = array_merge(
204 $settings,
205 array(
206 array(
207 'title' => __( 'Email template', 'woocommerce' ),
208 'type' => 'title',
209 'desc' => __( 'Customize your WooCommerce email template and preview it below.', 'woocommerce' ),
210 'id' => 'email_template_options',
211 ),
212
213 array(
214 'title' => __( 'Try new templates', 'woocommerce' ),
215 'type' => 'previewing_new_templates',
216 'id' => 'previewing_new_templates',
217 ),
218
219 array(
220 'title' => __( 'Logo', 'woocommerce' ),
221 'desc' => __( 'Add your logo to each of your WooCommerce emails. If no logo is uploaded, your site title will be used instead.', 'woocommerce' ),
222 'id' => 'woocommerce_email_header_image',
223 'type' => 'email_image_url',
224 'css' => 'min-width:400px;',
225 'placeholder' => __( 'N/A', 'woocommerce' ),
226 'default' => '',
227 'autoload' => false,
228 'desc_tip' => true,
229 ),
230
231 array(
232 'title' => __( 'Logo width (px)', 'woocommerce' ),
233 'id' => 'woocommerce_email_header_image_width',
234 'desc_tip' => '',
235 'default' => '120',
236 'type' => 'number',
237 'row_class' => $email_improvements_enabled ? '' : 'disabled',
238 ),
239
240 array(
241 'title' => __( 'Header alignment', 'woocommerce' ),
242 'id' => 'woocommerce_email_header_alignment',
243 'desc_tip' => '',
244 'default' => 'left',
245 'type' => 'select',
246 'class' => 'wc-enhanced-select',
247 'options' => array(
248 'left' => __( 'Left', 'woocommerce' ),
249 'center' => __( 'Center', 'woocommerce' ),
250 'right' => __( 'Right', 'woocommerce' ),
251 ),
252 'row_class' => $email_improvements_enabled ? '' : 'disabled',
253 ),
254
255 array(
256 'title' => __( 'Font family', 'woocommerce' ),
257 'id' => 'woocommerce_email_font_family',
258 'default' => 'Helvetica',
259 'type' => 'email_font_family',
260 'row_class' => $email_improvements_enabled ? '' : 'disabled',
261 ),
262
263 array(
264 'title' => __( 'Footer text', 'woocommerce' ),
265 /* translators: %s: Available placeholders for use */
266 'desc' => __( 'This text will appear in the footer of all of your WooCommerce emails.', 'woocommerce' ) . ' ' . sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '{site_title} {site_url} {store_address} {store_email}' ),
267 'id' => 'woocommerce_email_footer_text',
268 'css' => 'width:400px; height: 75px;',
269 'placeholder' => __( 'N/A', 'woocommerce' ),
270 'type' => 'textarea',
271 'default' => '{site_title}<br />{store_address}',
272 'autoload' => false,
273 'desc_tip' => true,
274 ),
275
276 array(
277 'type' => 'sectionend',
278 'id' => 'email_template_options',
279 ),
280
281 array(
282 'title' => __( 'Color palette', 'woocommerce' ),
283 'type' => 'email_color_palette',
284 'id' => 'email_color_palette',
285 ),
286
287 array(
288 'title' => __( 'Accent', 'woocommerce' ),
289 /* translators: %s: default color */
290 'desc' => sprintf( __( 'Customize the color of your buttons and links. Default %s.', 'woocommerce' ), '<code>' . $default_colors['base'] . '</code>' ),
291 'id' => 'woocommerce_email_base_color',
292 'type' => 'color',
293 'css' => 'width:6em;',
294 'default' => $default_colors['base'],
295 'autoload' => false,
296 'desc_tip' => true,
297 ),
298
299 array(
300 'title' => __( 'Email background', 'woocommerce' ),
301 /* translators: %s: default color */
302 'desc' => sprintf( __( 'Select a color for the background of your emails. Default %s.', 'woocommerce' ), '<code>' . $default_colors['bg'] . '</code>' ),
303 'id' => 'woocommerce_email_background_color',
304 'type' => 'color',
305 'css' => 'width:6em;',
306 'default' => $default_colors['bg'],
307 'autoload' => false,
308 'desc_tip' => true,
309 ),
310
311 array(
312 'title' => __( 'Content background', 'woocommerce' ),
313 /* translators: %s: default color */
314 'desc' => sprintf( __( 'Choose a background color for the content area of your emails. Default %s.', 'woocommerce' ), '<code>' . $default_colors['body_bg'] . '</code>' ),
315 'id' => 'woocommerce_email_body_background_color',
316 'type' => 'color',
317 'css' => 'width:6em;',
318 'default' => $default_colors['body_bg'],
319 'autoload' => false,
320 'desc_tip' => true,
321 ),
322
323 array(
324 'title' => __( 'Heading & text', 'woocommerce' ),
325 /* translators: %s: default color */
326 'desc' => sprintf( __( 'Set the color of your headings and text. Default %s.', 'woocommerce' ), '<code>' . $default_colors['body_text'] . '</code>' ),
327 'id' => 'woocommerce_email_text_color',
328 'type' => 'color',
329 'css' => 'width:6em;',
330 'default' => $default_colors['body_text'],
331 'autoload' => false,
332 'desc_tip' => true,
333 ),
334
335 array(
336 'title' => __( 'Secondary text', 'woocommerce' ),
337 /* translators: %s: footer default color */
338 'desc' => sprintf( __( 'Choose a color for your secondary text, such as your footer content. Default %s.', 'woocommerce' ), '<code>' . $default_colors['footer_text'] . '</code>' ),
339 'id' => 'woocommerce_email_footer_text_color',
340 'type' => 'color',
341 'css' => 'width:6em;',
342 'default' => $default_colors['footer_text'],
343 'autoload' => false,
344 'desc_tip' => true,
345 ),
346
347 array(
348 'title' => __( 'Auto-sync with theme', 'woocommerce' ),
349 'desc' => __( 'Automatically update email styles when theme styles change', 'woocommerce' ),
350 'id' => 'woocommerce_email_auto_sync_with_theme',
351 'type' => 'hidden',
352 'default' => 'no',
353 'autoload' => false,
354 ),
355
356 array(
357 'type' => 'sectionend',
358 'id' => 'email_color_palette',
359 ),
360
361 array(
362 'title' => __( 'Email improvements button', 'woocommerce' ),
363 'type' => 'email_improvements_button',
364 'id' => 'email_improvements_button',
365 ),
366
367 array( 'type' => 'email_preview' ),
368 )
369 );
370 }
371
372 // Remove empty elements that depend on the email_improvements feature flag.
373 $settings = array_filter( $settings );
374
375 /**
376 * Filters the email settings array.
377 *
378 * @since 2.1.0
379 *
380 * @param array $settings Array of email settings.
381 */
382 return apply_filters( 'woocommerce_email_settings', $settings );
383 }
384
385 /**
386 * Get custom fonts for emails.
387 */
388 public function get_custom_fonts() {
389 $custom_fonts = array();
390 if ( wp_is_block_theme() && class_exists( 'WP_Font_Face_Resolver' ) ) {
391 $theme_fonts = WP_Font_Face_Resolver::get_fonts_from_theme_json();
392 if ( count( $theme_fonts ) > 0 ) {
393 foreach ( $theme_fonts as $font ) {
394 if ( ! empty( $font[0]['font-family'] ) ) {
395 $custom_fonts[ $font[0]['font-family'] ] = $font[0]['font-family'];
396 }
397 }
398 }
399 }
400 ksort( $custom_fonts );
401
402 return $custom_fonts;
403 }
404
405 /**
406 * Output the settings.
407 */
408 public function output() {
409 global $current_section;
410
411 // Define emails that can be customised here.
412 $mailer = WC()->mailer();
413 $email_templates = $mailer->get_emails();
414
415 if ( $current_section ) {
416 foreach ( $email_templates as $email_key => $email ) {
417 if ( strtolower( $email_key ) === $current_section ) {
418 $this->run_email_admin_options( $email );
419 break;
420 }
421 }
422 }
423
424 parent::output();
425 }
426
427 /**
428 * Run the 'admin_options' method on a given email.
429 * This method exists to easy unit testing.
430 *
431 * @param object $email The email object to run the method on.
432 */
433 protected function run_email_admin_options( $email ) {
434 $email->admin_options();
435 }
436
437 /**
438 * Save settings.
439 */
440 public function save() {
441 global $current_section;
442
443 if ( ! $current_section ) {
444 $this->save_settings_for_current_section();
445 $this->do_update_options_action();
446 } else {
447 $wc_emails = WC_Emails::instance();
448
449 if ( in_array( $current_section, array_map( 'sanitize_title', array_keys( $wc_emails->get_emails() ) ), true ) ) {
450 foreach ( $wc_emails->get_emails() as $email_id => $email ) {
451 if ( sanitize_title( $email_id ) === $current_section ) {
452 $this->do_update_options_action( $email->id );
453 }
454 }
455 } else {
456 $this->save_settings_for_current_section();
457 $this->do_update_options_action();
458 }
459 }
460 }
461
462 /**
463 * Output email notification settings.
464 */
465 public function email_notification_setting() {
466 // Define emails that can be customised here.
467 $mailer = WC()->mailer();
468 $email_templates = $mailer->get_emails();
469
470 ?>
471 <tr valign="top">
472 <td class="wc_emails_wrapper" colspan="2">
473 <table class="wc_emails widefat" cellspacing="0">
474 <thead>
475 <tr>
476 <?php
477 /**
478 * Filters the columns displayed in the email settings table.
479 *
480 * @since 2.1.0
481 *
482 * @param array $columns Array of column keys and labels.
483 */
484 $columns = apply_filters(
485 'woocommerce_email_setting_columns',
486 array(
487 'status' => '',
488 'name' => __( 'Email', 'woocommerce' ),
489 'email_type' => __( 'Content type', 'woocommerce' ),
490 'recipient' => __( 'Recipient(s)', 'woocommerce' ),
491 'actions' => '',
492 )
493 );
494 foreach ( $columns as $key => $column ) {
495 echo '<th class="wc-email-settings-table-' . esc_attr( $key ) . '">' . esc_html( $column ) . '</th>';
496 }
497 ?>
498 </tr>
499 </thead>
500 <tbody>
501 <?php
502 foreach ( $email_templates as $email_key => $email ) {
503 echo '<tr>';
504
505 foreach ( $columns as $key => $column ) {
506
507 switch ( $key ) {
508 case 'name':
509 echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '">
510 <a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=email&section=' . strtolower( $email_key ) ) ) . '">' . esc_html( $email->get_title() ) . '</a>
511 ' . wc_help_tip( $email->get_description() ) . '
512 </td>';
513 break;
514 case 'recipient':
515 $to = $email->is_customer_email() ? __( 'Customer', 'woocommerce' ) : $email->get_recipient();
516 $cc = false;
517 $bcc = false;
518 if ( FeaturesUtil::feature_is_enabled( 'email_improvements' ) ) {
519 $ccs = $email->get_cc_recipient();
520 $bccs = $email->get_bcc_recipient();
521 // Translators: %s: comma-separated email addresses to which the email is cc-ed.
522 $cc = $ccs ? sprintf( __( '<b>Cc</b>: %s', 'woocommerce' ), $ccs ) : false;
523 // Translators: %s: comma-separated email addresses to which the email is bcc-ed.
524 $bcc = $bccs ? sprintf( __( '<b>Bcc</b>: %s', 'woocommerce' ), $bccs ) : false;
525 if ( $cc || $bcc ) {
526 // Translators: %s: comma-separated email addresses to which the email is sent.
527 $to = sprintf( __( '<b>To</b>: %s', 'woocommerce' ), $to );
528 }
529 }
530 $allowed_tags = array( 'b' => array() );
531
532 echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '">';
533 echo wp_kses( $to, $allowed_tags );
534 if ( $cc ) {
535 echo '<br>' . wp_kses( $cc, $allowed_tags );
536 }
537 if ( $bcc ) {
538 echo '<br>' . wp_kses( $bcc, $allowed_tags );
539 }
540 echo '</td>';
541 break;
542 case 'status':
543 echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '">';
544
545 if ( $email->is_manual() ) {
546 echo '<span class="status-manual tips" data-tip="' . esc_attr__( 'Manually sent', 'woocommerce' ) . '">' . esc_html__( 'Manual', 'woocommerce' ) . '</span>';
547 } elseif ( $email->is_enabled() ) {
548 echo '<span class="status-enabled tips" data-tip="' . esc_attr__( 'Enabled', 'woocommerce' ) . '">' . esc_html__( 'Yes', 'woocommerce' ) . '</span>';
549 } else {
550 echo '<span class="status-disabled tips" data-tip="' . esc_attr__( 'Disabled', 'woocommerce' ) . '">-</span>';
551 }
552
553 echo '</td>';
554 break;
555 case 'email_type':
556 echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '">
557 ' . esc_html( $email->get_content_type() ) . '
558 </td>';
559 break;
560 case 'actions':
561 echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '">
562 <a class="button alignright" href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=email&section=' . strtolower( $email_key ) ) ) . '">' . esc_html__( 'Manage', 'woocommerce' ) . '</a>
563 </td>';
564 break;
565 default:
566 /**
567 * Fires when rendering a custom column in the email settings table.
568 *
569 * @since 2.1.0
570 *
571 * @param WC_Email $email The email object.
572 */
573 do_action( 'woocommerce_email_setting_column_' . $key, $email );
574 break;
575 }
576 }
577
578 echo '</tr>';
579 }
580 ?>
581 </tbody>
582 </table>
583 </td>
584 </tr>
585 <?php
586 }
587
588 /**
589 * Creates the React mount point for listing of block based emails.
590 */
591 public function email_notification_setting_block_emails() {
592 $desc_help_text = sprintf(
593 /* translators: %1$s: Link to WP Mail Logging plugin, %2$s: Link to Email FAQ support page. */
594 __( 'To ensure your store&rsquo;s notifications arrive in your and your customers&rsquo; inboxes, we recommend connecting your email address to your domain and setting up a dedicated SMTP server. If something doesn&rsquo;t seem to be sending correctly, install the <a href="%1$s">WP Mail Logging Plugin</a> or check the <a href="%2$s">Email FAQ page</a>.', 'woocommerce' ),
595 'https://wordpress.org/plugins/wp-mail-logging/',
596 'https://woocommerce.com/document/email-faq'
597 );
598 $email_post_manager = WCTransactionalEmailPostsManager::get_instance();
599 $emails = WC()->mailer()->get_emails();
600 $email_types = array();
601 $post_id_for_template = null;
602 foreach ( $emails as $email_key => $email ) {
603 $post_id = $email_post_manager->get_email_template_post_id( $email->id );
604 $sync_config = WCEmailTemplateSyncRegistry::get_email_sync_config( $email->id );
605 // `current_version` is the canonical version core ships right now;
606 // the list view's "Review update" cell and RSM-141's editor banner
607 // gate on `merchant_reviewed_version < current_version` so a row
608 // stays customized but stops showing the indicator once the
609 // merchant has reviewed this release.
610 $current_version = is_array( $sync_config ) ? (string) ( $sync_config['version'] ?? '' ) : '';
611
612 // Project the template-sync meta directly onto the slotfill payload
613 // so the RSM-145 `_list_viewed` aggregate event can compute
614 // `eligible_count` immediately on mount without waiting for the
615 // REST enrichment in `useTransactionalEmails` to resolve. REST
616 // enrichment still runs and overrides these values once it lands —
617 // both sources read from the same post meta, so they always agree.
618 $template_status = $post_id ? (string) get_post_meta( $post_id, WCEmailTemplateDivergenceDetector::STATUS_META_KEY, true ) : '';
619 $template_version = $post_id ? (string) get_post_meta( $post_id, WCEmailTemplateDivergenceDetector::VERSION_META_KEY, true ) : '';
620 $was_backfilled = $post_id ? (bool) get_post_meta( $post_id, WCEmailTemplateDivergenceDetector::BACKFILLED_META_KEY, true ) : false;
621
622 $email_types[] = array(
623 'title' => $email->get_title(),
624 'description' => $email->get_description(),
625 'id' => $email->id,
626 'email_key' => strtolower( $email_key ),
627 'post_id' => $post_id,
628 'enabled' => $email->is_enabled(),
629 'manual' => $email->is_manual(),
630 'current_version' => '' !== $current_version ? $current_version : null,
631 'template_status' => '' !== $template_status ? $template_status : null,
632 'template_version' => '' !== $template_version ? $template_version : null,
633 'was_backfilled' => $was_backfilled,
634 'recipients' => array(
635 'to' => $email->is_customer_email() ? __( 'Customers', 'woocommerce' ) : $email->get_recipient(),
636 'cc' => $email->get_cc_recipient(),
637 'bcc' => $email->get_bcc_recipient(),
638 ),
639 );
640
641 // Store the first valid post ID we find.
642 if ( ! $post_id_for_template && $post_id ) {
643 $post_id_for_template = $post_id;
644 }
645 }
646 // Create URL for email editor template mode.
647 $edit_template_url = null;
648 if ( $post_id_for_template ) {
649 $email_template_id = get_stylesheet() . '//' . WooEmailTemplate::TEMPLATE_SLUG;
650 $edit_template_url = admin_url( 'post.php?post=' . $post_id_for_template . '&action=edit&template=' . $email_template_id );
651 }
652
653 ?>
654 <div
655 id="wc_settings_email_listing_slotfill" class="wc-settings-prevent-change-event woocommerce-email-listing-listview"
656 data-email-types="<?php echo esc_attr( wp_json_encode( $email_types ) ); ?>"
657 data-edit-template-url="<?php echo esc_attr( $edit_template_url ); ?>"
658 >
659 <div style="
660 display: flex;
661 align-items: center;
662 justify-content: center;
663 padding: 12px;
664 height: 40px;
665 width: 100%;
666 ">
667 <h3> <?php esc_html_e( 'Loading&hellip;', 'woocommerce' ); ?> </h3>
668 </div>
669 </div>
670 <div>
671 <p><?php echo wp_kses_post( wpautop( wptexturize( $desc_help_text ) ) ); ?></p>
672 </div>
673 <?php
674 }
675
676 /**
677 * Creates the React mount point for the email preview.
678 */
679 public function email_preview() {
680 $this->delete_transient_email_settings();
681 $emails = WC()->mailer()->get_emails();
682 $email_types = array();
683 foreach ( $emails as $email ) {
684 $email_types[] = array(
685 'label' => $email->get_title(),
686 'value' => get_class( $email ),
687 );
688 }
689 ?>
690 <div
691 id="wc_settings_email_preview_slotfill"
692 data-preview-url="<?php echo esc_url( wp_nonce_url( admin_url( '?preview_woocommerce_mail=true' ), 'preview-mail' ) ); ?>"
693 data-email-types="<?php echo esc_attr( wp_json_encode( $email_types ) ); ?>"
694 data-email-setting-ids="<?php echo esc_attr( wp_json_encode( EmailPreview::get_email_style_setting_ids() ) ); ?>"
695 ></div>
696 <?php
697 }
698
699 /**
700 * Creates the React mount point for the single email preview.
701 *
702 * @param object $email The email object to run the method on.
703 */
704 public function email_preview_single( $email ) {
705 $this->delete_transient_email_settings();
706 // Email types array should have a single entry for current email.
707 $email_types = array(
708 array(
709 'label' => $email->get_title(),
710 'value' => get_class( $email ),
711 ),
712 );
713 ?>
714 <h2><?php echo esc_html( __( 'Email preview', 'woocommerce' ) ); ?></h2>
715
716 <p><?php echo esc_html( __( 'Preview your email template. You can also test on different devices and send yourself a test email.', 'woocommerce' ) ); ?></p>
717 <div>
718 <div
719 id="wc_settings_email_preview_slotfill"
720 data-preview-url="<?php echo esc_url( wp_nonce_url( admin_url( '?preview_woocommerce_mail=true' ), 'preview-mail' ) ); ?>"
721 data-email-types="<?php echo esc_attr( wp_json_encode( $email_types ) ); ?>"
722 data-email-setting-ids="<?php echo esc_attr( wp_json_encode( EmailPreview::get_email_content_setting_ids( $email->id ) ) ); ?>"
723 ></div>
724 <input type="hidden" id="woocommerce_email_from_name" value="<?php echo esc_attr( get_option( 'woocommerce_email_from_name' ) ); ?>" />
725 <input type="hidden" id="woocommerce_email_from_address" value="<?php echo esc_attr( get_option( 'woocommerce_email_from_address' ) ); ?>" />
726 </div>
727 <?php
728 }
729
730 /**
731 * Deletes transient with email settings used for live preview. This is to
732 * prevent conflicts where the preview would show values from previous session.
733 */
734 private function delete_transient_email_settings() {
735 $setting_ids = EmailPreview::get_all_email_setting_ids();
736 foreach ( $setting_ids as $id ) {
737 delete_transient( $id );
738 }
739 }
740
741 /**
742 * Creates the React mount point for the email image url.
743 *
744 * @param array $value Field value array.
745 */
746 public function email_image_url( $value ) {
747 $option_value = $value['value'];
748 if ( ! isset( $value['field_name'] ) ) {
749 $value['field_name'] = $value['id'];
750 }
751 ?>
752 <tr class="<?php echo esc_attr( $value['row_class'] ); ?>">
753 <th scope="row" class="titledesc">
754 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?> <?php echo wc_help_tip( $value['desc'] ); // WPCS: XSS ok. ?></label>
755 </th>
756 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
757 <input
758 name="<?php echo esc_attr( $value['field_name'] ); ?>"
759 id="<?php echo esc_attr( $value['id'] ); ?>"
760 type="hidden"
761 value="<?php echo esc_attr( $option_value ); ?>"
762 />
763 <div
764 id="wc_settings_email_image_url_slotfill"
765 data-id="<?php echo esc_attr( $value['id'] ); ?>"
766 data-image-url="<?php echo esc_attr( $option_value ); ?>"
767 ></div>
768 </td>
769 </tr>
770 <?php
771 }
772
773 /**
774 * Sanitize email image URL.
775 *
776 * @param string $value Option value.
777 * @param array $option Option name.
778 * @param string $raw_value Raw value.
779 * @return string
780 */
781 public function sanitize_email_header_image( $value, $option, $raw_value ) {
782 return sanitize_url( $raw_value );
783 }
784
785 /**
786 * Creates the email font family field with custom font family applied to each option.
787 *
788 * @param array $value Field value array.
789 */
790 public function email_font_family( $value ) {
791 $option_value = $value['value'];
792 // This is a temporary fix to prevent using custom fonts without fallback.
793 $custom_fonts = null;
794
795 ?>
796 <tr class="<?php echo esc_attr( $value['row_class'] ); ?>">
797 <th scope="row" class="titledesc">
798 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
799 </th>
800 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
801 <script type="text/javascript">
802 function renderWithFont( node ) {
803 if ( ! node.element || ! node.element.value ) return node.text;
804 var $wrapper = jQuery( '<span></span>' );
805 $wrapper.css( {'font-family': node.element.dataset['font-family'] || node.element.value} );
806 $wrapper.text( node.text );
807 return $wrapper;
808 }
809 function fontsSelect( selector ) {
810 jQuery( selector ).selectWoo( {
811 minimumResultsForSearch: Infinity,
812 templateResult: renderWithFont
813 } );
814 }
815 jQuery( document.body )
816 .on( 'wc-enhanced-select-init', function() {
817 fontsSelect( '#<?php echo esc_js( $value['id'] ); ?>' );
818 } );
819 </script>
820 <select
821 name="<?php echo esc_attr( $value['field_name'] ); ?>"
822 id="<?php echo esc_attr( $value['id'] ); ?>"
823 >
824 <optgroup label="<?php echo esc_attr__( 'Standard fonts', 'woocommerce' ); ?>">
825 <?php
826 foreach ( EmailFont::$font as $key => $font_family ) {
827 ?>
828 <option
829 value="<?php echo esc_attr( $key ); ?>"
830 data-font-family="<?php echo esc_attr( $font_family ); ?>"
831 <?php selected( $option_value, (string) $key ); ?>
832 ><?php echo esc_html( $key ); ?></option>
833 <?php
834 }
835 ?>
836 </optgroup>
837 <?php if ( $custom_fonts ) : ?>
838 <optgroup label="<?php echo esc_attr__( 'Custom fonts', 'woocommerce' ); ?>">
839 <?php
840 foreach ( $custom_fonts as $key => $val ) {
841 ?>
842 <option
843 value="<?php echo esc_attr( $key ); ?>"
844 <?php selected( $option_value, (string) $key ); ?>
845 ><?php echo esc_html( $val ); ?></option>
846 <?php
847 }
848 ?>
849 </optgroup>
850 <?php endif; ?>
851 </select>
852 </td>
853 </tr>
854 <?php
855 }
856
857 /**
858 * Creates the React mount point for the email color palette title.
859 *
860 * @param array $value Field value array.
861 */
862 public function email_color_palette( $value ) {
863 $email_improvements_enabled = $this->get_email_improvements_enabled();
864 $default_colors = EmailColors::get_default_colors( $email_improvements_enabled );
865 $auto_sync = get_option( EmailStyleSync::AUTO_SYNC_OPTION, 'no' );
866
867 ?>
868 <hr class="wc-settings-email-color-palette-separator" />
869 <div class="wc-settings-email-color-palette-header">
870 <h2 class="wc-settings-email-color-palette-title"><?php echo esc_html( $value['title'] ); ?></h2>
871 <?php if ( $email_improvements_enabled ) : ?>
872 <div
873 class="wc-settings-email-color-palette-buttons"
874 id="wc_settings_email_color_palette_slotfill"
875 data-default-colors="<?php echo esc_attr( wp_json_encode( $default_colors ) ); ?>"
876 <?php echo wp_theme_has_theme_json() ? 'data-has-theme-json' : ''; ?>
877 ></div>
878 <input
879 type="hidden"
880 name="woocommerce_email_auto_sync_with_theme"
881 id="woocommerce_email_auto_sync_with_theme"
882 value="<?php echo esc_attr( $auto_sync ); ?>"
883 />
884 <?php else : ?>
885 <div class="wc-settings-email-color-palette-buttons">
886 <button disabled type="button" class="components-button is-secondary"><?php esc_html_e( 'Sync with theme', 'woocommerce' ); ?></button>
887 </div>
888 <?php endif; ?>
889 </div>
890 <table class="form-table">
891 <?php
892 }
893
894 /**
895 * Show a notice to the user when they are trying out the new email templates.
896 */
897 public function previewing_new_templates(): void {
898 if ( ! $this->is_trying_new_templates() ) {
899 return;
900 }
901 if ( FeaturesUtil::feature_is_enabled( 'email_improvements' ) ) {
902 return;
903 }
904 update_option( 'woocommerce_admin_dismissed_try_email_improvements_modal', 'yes' );
905 ?>
906 <div class="wc-settings-email-color-palette-header submit">
907 <div class="notice notice-info inline">
908 <p><?php esc_html_e( 'Previewing new template designs. You can customize and test your emails and switch to the new template whenever you are ready.', 'woocommerce' ); ?></p>
909 <p>
910 <button name="save" type="submit" class="components-button is-secondary" value="<?php esc_attr_e( 'Save changes', 'woocommerce' ); ?>">
911 <?php esc_html_e( 'Switch to new template', 'woocommerce' ); ?>
912 </button>
913 <a href="?page=wc-settings&tab=email" class="components-button is-tertiary">
914 <?php esc_html_e( 'Keep legacy template', 'woocommerce' ); ?>
915 </a>
916 </p>
917 </div>
918 </div>
919 <?php
920 }
921
922 /**
923 * Show a button to revert or enable email improvements.
924 */
925 public function email_improvements_button(): void {
926 if ( 'yes' === get_transient( 'wc_settings_email_improvements_reverted' ) ) {
927 ?>
928 <div id="wc_settings_features_email_feedback_slotfill"></div>
929 <?php
930 }
931 $is_feature_enabled = FeaturesUtil::feature_is_enabled( 'email_improvements' );
932 $trying_new_templates = $this->is_trying_new_templates();
933 if ( ! $is_feature_enabled && ! $trying_new_templates ) {
934 ?>
935 <hr class="wc-settings-email-color-palette-separator" />
936 <a href="?page=wc-settings&tab=email&try-new-templates" class="components-button is-link">
937 <?php esc_html_e( 'Try our new email templates!', 'woocommerce' ); ?>
938 </a>
939 <?php
940 return;
941 }
942
943 $has_feature_enabled_since_installation = 'yes' === get_option( 'woocommerce_email_improvements_default_enabled', 'no' );
944 if ( $is_feature_enabled && ! $has_feature_enabled_since_installation ) {
945 $disable_feature_args = array(
946 'email_improvements' => '0',
947 '_feature_nonce' => wp_create_nonce( 'change_feature_enable' ),
948 );
949 ?>
950 <hr class="wc-settings-email-color-palette-separator" />
951 <a href="<?php echo esc_url( add_query_arg( $disable_feature_args ) ); ?>"
952 class="components-button is-link"
953 onclick="return confirm('<?php esc_attr_e( 'Are you sure want to revert to legacy? Doing so will erase any changes you’ve made to your new email templates, and will restore your previous email designs.', 'woocommerce' ); ?>');"
954 >
955 <?php esc_html_e( 'Revert to legacy template', 'woocommerce' ); ?>
956 </a>
957 <?php
958 return;
959 }
960 ?>
961 <?php
962 }
963
964 /**
965 * Append email improvements prop to Tracks globally.
966 *
967 * @param array $event_properties Event properties array.
968 *
969 * @return array
970 */
971 public function append_feature_email_improvements_to_tracks( $event_properties ) {
972 if ( is_array( $event_properties ) ) {
973 $is_email_improvements_enabled = FeaturesUtil::feature_is_enabled( 'email_improvements' );
974 $event_properties['feature_email_improvements'] = $is_email_improvements_enabled ? 'enabled' : 'disabled';
975 }
976 return $event_properties;
977 }
978
979 /**
980 * Track email improvements feature change.
981 *
982 * @param string $feature_id The feature ID.
983 * @param bool $enabled True if the feature is enabled, false if it is disabled.
984 */
985 public function track_email_improvements_feature_change( $feature_id, $enabled ) {
986 if ( 'email_improvements' === $feature_id ) {
987 $current_date = gmdate( 'Y-m-d H:i:s' );
988 if ( $enabled ) {
989 $enabled_count = get_option( 'woocommerce_email_improvements_enabled_count', 0 );
990 update_option( 'woocommerce_email_improvements_enabled_count', $enabled_count + 1 );
991 add_option( 'woocommerce_email_improvements_first_enabled_at', $current_date );
992 update_option( 'woocommerce_email_improvements_last_enabled_at', $current_date );
993 } else {
994 $disabled_count = get_option( 'woocommerce_email_improvements_disabled_count', 0 );
995 update_option( 'woocommerce_email_improvements_disabled_count', $disabled_count + 1 );
996 add_option( 'woocommerce_email_improvements_first_disabled_at', $current_date );
997 update_option( 'woocommerce_email_improvements_last_disabled_at', $current_date );
998 }
999 }
1000 }
1001
1002 /**
1003 * When the email settings are saved, if the user is trying out the new email templates, enable the email improvements feature.
1004 */
1005 public function enable_email_improvements_when_trying_new_templates() {
1006 if ( $this->is_trying_new_templates() ) {
1007 $feature_controller = wc_get_container()->get( FeaturesController::class );
1008 $feature_controller->change_feature_enable( 'email_improvements', true );
1009
1010 // Remove the try-new-templates parameter from the URL.
1011 wp_safe_redirect( remove_query_arg( 'try-new-templates' ) );
1012 exit;
1013 }
1014 }
1015
1016 /**
1017 * Get "email improvements" feature status or force it when enabled via URL parameter.
1018 * Transient is used to force the email improvements feature in email preview, which
1019 * is rendered in iframe.
1020 *
1021 * @return bool
1022 */
1023 private function get_email_improvements_enabled() {
1024 $email_improvements_enabled = FeaturesUtil::feature_is_enabled( 'email_improvements' );
1025 // Check for try-new-templates URL parameter, which is used to force the email improvements feature in preview mode.
1026 if ( $this->is_trying_new_templates() ) {
1027 $email_improvements_enabled = true;
1028 set_transient( EmailPreview::TRANSIENT_PREVIEW_EMAIL_IMPROVEMENTS, 'yes' );
1029 } else {
1030 delete_transient( EmailPreview::TRANSIENT_PREVIEW_EMAIL_IMPROVEMENTS );
1031 }
1032 return $email_improvements_enabled;
1033 }
1034
1035 /**
1036 * Check if the user is trying out the new email templates.
1037 *
1038 * @return bool
1039 */
1040 private function is_trying_new_templates() {
1041 global $current_tab;
1042 if ( 'email' !== $current_tab ) {
1043 return false;
1044 }
1045 if ( isset( $_GET['section'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1046 return false;
1047 }
1048 return isset( $_GET['try-new-templates'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1049 }
1050 }
1051
1052 return new WC_Settings_Emails();
1053