"Arial, 'Helvetica Neue', Helvetica, sans-serif",
'Comic Sans MS' => "'Comic Sans MS', 'Marker Felt-Thin', Arial, sans-serif",
'Courier New' => "'Courier New', Courier, 'Lucida Sans Typewriter', 'Lucida Typewriter', monospace",
'Georgia' => "Georgia, Times, 'Times New Roman', serif",
'Lucida' => "'Lucida Sans Unicode', 'Lucida Grande', sans-serif",
'Tahoma' => 'Tahoma, Verdana, Segoe, sans-serif',
'Times New Roman' => "'Times New Roman', Times, Baskerville, Georgia, serif",
'Trebuchet MS' => "'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Tahoma, sans-serif",
'Verdana' => 'Verdana, Geneva, sans-serif',
);
/**
* Constructor.
*/
public function __construct() {
$this->id = 'email';
$this->label = __( 'Emails', 'woocommerce' );
add_action( 'woocommerce_admin_field_email_notification', array( $this, 'email_notification_setting' ) );
add_action( 'woocommerce_admin_field_email_preview', array( $this, 'email_preview' ) );
add_action( 'woocommerce_admin_field_email_image_url', array( $this, 'email_image_url' ) );
add_action( 'woocommerce_admin_field_email_font_family', array( $this, 'email_font_family' ) );
add_action( 'woocommerce_admin_field_email_color_palette', array( $this, 'email_color_palette' ) );
if ( FeaturesUtil::feature_is_enabled( 'email_improvements' ) ) {
add_action( 'woocommerce_email_settings_after', array( $this, 'email_preview_single' ) );
}
parent::__construct();
}
/**
* Setting page icon.
*
* @var string
*/
public $icon = 'atSymbol';
/**
* Get own sections.
*
* @return array
*/
protected function get_own_sections() {
return array(
'' => __( 'Email options', 'woocommerce' ),
);
}
/**
* Get settings array.
*
* @return array
*/
protected function get_settings_for_default_section() {
$desc_help_text = sprintf(
/* translators: %1$s: Link to WP Mail Logging plugin, %2$s: Link to Email FAQ support page. */
__( 'To ensure your store’s notifications arrive in your and your customers’ inboxes, we recommend connecting your email address to your domain and setting up a dedicated SMTP server. If something doesn’t seem to be sending correctly, install the WP Mail Logging Plugin or check the Email FAQ page.', 'woocommerce' ),
'https://wordpress.org/plugins/wp-mail-logging/',
'https://woocommerce.com/document/email-faq'
);
/* translators: %s: Nonced email preview link */
$email_template_description = sprintf( __( 'This section lets you customize the WooCommerce emails. Click here to preview your email template.', 'woocommerce' ), wp_nonce_url( admin_url( '?preview_woocommerce_mail=true' ), 'preview-mail' ) );
$logo_image = array(
'title' => __( 'Header image', 'woocommerce' ),
'desc' => __( 'Paste the URL of an image you want to show in the email header. Upload images using the media uploader (Media > Add New).', 'woocommerce' ),
'id' => 'woocommerce_email_header_image',
'type' => 'text',
'css' => 'min-width:400px;',
'placeholder' => __( 'N/A', 'woocommerce' ),
'default' => '',
'autoload' => false,
'desc_tip' => true,
);
$header_alignment = null;
$font_family = null;
/* translators: %s: Available placeholders for use */
$footer_text_description = __( 'The text to appear in the footer of all WooCommerce emails.', 'woocommerce' ) . ' ' . sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '{site_title} {site_url}' );
$footer_text_default = '{site_title} — Built with {WooCommerce}';
// These defaults should be chosen by the same logic as the other color option properties.
list(
'base_color_default' => $base_color_default,
'bg_color_default' => $bg_color_default,
'body_bg_color_default' => $body_bg_color_default,
'body_text_color_default' => $body_text_color_default,
'footer_text_color_default' => $footer_text_color_default,
) = $this->get_email_default_colors();
$base_color_title = __( 'Base color', 'woocommerce' );
/* translators: %s: default color */
$base_color_desc = sprintf( __( 'The base color for WooCommerce email templates. Default %s.', 'woocommerce' ), '' . $base_color_default . '
' );
$bg_color_title = __( 'Background color', 'woocommerce' );
/* translators: %s: default color */
$bg_color_desc = sprintf( __( 'The background color for WooCommerce email templates. Default %s.', 'woocommerce' ), '' . $bg_color_default . '
' );
$body_bg_color_title = __( 'Body background color', 'woocommerce' );
/* translators: %s: default color */
$body_bg_color_desc = sprintf( __( 'The main body background color. Default %s.', 'woocommerce' ), '' . $body_bg_color_default . '
' );
$body_text_color_title = __( 'Body text color', 'woocommerce' );
/* translators: %s: default color */
$body_text_color_desc = sprintf( __( 'The main body text color. Default %s.', 'woocommerce' ), '' . $body_text_color_default . '
' );
$footer_text_color_title = __( 'Footer text color', 'woocommerce' );
/* translators: %s: footer default color */
$footer_text_color_desc = sprintf( __( 'The footer text color. Default %s.', 'woocommerce' ), '' . $footer_text_color_default . '
' );
$color_palette_section_header = null;
$color_palette_section_end = null;
if ( FeaturesUtil::feature_is_enabled( 'email_improvements' ) ) {
$email_template_description = __( 'Customize your WooCommerce email template and preview it below.', 'woocommerce' );
$logo_image = array(
'title' => __( 'Logo', 'woocommerce' ),
'desc' => __( 'Add your logo to each of your WooCommerce emails. If no logo is uploaded, your site title will be used instead.', 'woocommerce' ),
'id' => 'woocommerce_email_header_image',
'type' => 'email_image_url',
'css' => 'min-width:400px;',
'placeholder' => __( 'N/A', 'woocommerce' ),
'default' => '',
'autoload' => false,
'desc_tip' => true,
);
$header_alignment = array(
'title' => __( 'Header alignment', 'woocommerce' ),
'id' => 'woocommerce_email_header_alignment',
'desc_tip' => '',
'default' => 'left',
'type' => 'select',
'class' => 'wc-enhanced-select',
'options' => array(
'left' => __( 'Left', 'woocommerce' ),
'center' => __( 'Center', 'woocommerce' ),
'right' => __( 'Right', 'woocommerce' ),
),
);
$font_family = array(
'title' => __( 'Font family', 'woocommerce' ),
'id' => 'woocommerce_email_font_family',
'default' => 'Arial',
'type' => 'email_font_family',
);
/* translators: %s: Available placeholders for use */
$footer_text_description = __( '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}' );
$footer_text_default = '{site_title}
{store_address}';
$base_color_title = __( 'Accent', 'woocommerce' );
/* translators: %s: default color */
$base_color_desc = sprintf( __( 'Customize the color of your buttons and links. Default %s.', 'woocommerce' ), '' . $base_color_default . '
' );
$bg_color_title = __( 'Email background', 'woocommerce' );
/* translators: %s: default color */
$bg_color_desc = sprintf( __( 'Select a color for the background of your emails. Default %s.', 'woocommerce' ), '' . $bg_color_default . '
' );
$body_bg_color_title = __( 'Content background', 'woocommerce' );
/* translators: %s: default color */
$body_bg_color_desc = sprintf( __( 'Choose a background color for the content area of your emails. Default %s.', 'woocommerce' ), '' . $body_bg_color_default . '
' );
$body_text_color_title = __( 'Heading & text', 'woocommerce' );
/* translators: %s: default color */
$body_text_color_desc = sprintf( __( 'Set the color of your headings and text. Default %s.', 'woocommerce' ), '' . $body_text_color_default . '
' );
$footer_text_color_title = __( 'Secondary text', 'woocommerce' );
/* translators: %s: footer default color */
$footer_text_color_desc = sprintf( __( 'Choose a color for your secondary text, such as your footer content. Default %s.', 'woocommerce' ), '' . $footer_text_color_default . '
' );
$color_palette_section_header = array(
'title' => __( 'Color palette', 'woocommerce' ),
'type' => 'email_color_palette',
'id' => 'email_color_palette',
);
$color_palette_section_end = array(
'type' => 'sectionend',
'id' => 'email_template_options',
);
}
// Reorder email color settings based on the email_improvements feature flag.
$base_color_setting = array(
'title' => $base_color_title,
'desc' => $base_color_desc,
'id' => 'woocommerce_email_base_color',
'type' => 'color',
'css' => 'width:6em;',
'default' => $base_color_default,
'autoload' => false,
'desc_tip' => true,
);
$bg_color_setting = array(
'title' => $bg_color_title,
'desc' => $bg_color_desc,
'id' => 'woocommerce_email_background_color',
'type' => 'color',
'css' => 'width:6em;',
'default' => $bg_color_default,
'autoload' => false,
'desc_tip' => true,
);
$body_bg_color_setting = array(
'title' => $body_bg_color_title,
'desc' => $body_bg_color_desc,
'id' => 'woocommerce_email_body_background_color',
'type' => 'color',
'css' => 'width:6em;',
'default' => $body_bg_color_default,
'autoload' => false,
'desc_tip' => true,
);
$body_text_color_setting = array(
'title' => $body_text_color_title,
'desc' => $body_text_color_desc,
'id' => 'woocommerce_email_text_color',
'type' => 'color',
'css' => 'width:6em;',
'default' => $body_text_color_default,
'autoload' => false,
'desc_tip' => true,
);
$footer_text_color_setting = array(
'title' => $footer_text_color_title,
'desc' => $footer_text_color_desc,
'id' => 'woocommerce_email_footer_text_color',
'type' => 'color',
'css' => 'width:6em;',
'default' => $footer_text_color_default,
'autoload' => false,
'desc_tip' => true,
);
$reorder_colors = FeaturesUtil::feature_is_enabled( 'email_improvements' );
$base_color_setting_in_template_opts = $reorder_colors ? null : $base_color_setting;
$bg_color_setting_in_template_opts = $reorder_colors ? null : $bg_color_setting;
$body_bg_color_setting_in_template_opts = $reorder_colors ? null : $body_bg_color_setting;
$body_text_color_setting_in_template_opts = $reorder_colors ? null : $body_text_color_setting;
$footer_text_color_setting_in_template_opts = $reorder_colors ? null : $footer_text_color_setting;
$base_color_setting_in_palette = $reorder_colors ? $base_color_setting : null;
$bg_color_setting_in_palette = $reorder_colors ? $bg_color_setting : null;
$body_bg_color_setting_in_palette = $reorder_colors ? $body_bg_color_setting : null;
$body_text_color_setting_in_palette = $reorder_colors ? $body_text_color_setting : null;
$footer_text_color_setting_in_palette = $reorder_colors ? $footer_text_color_setting : null;
$settings =
array(
array(
'title' => __( 'Email notifications', 'woocommerce' ),
/* translators: %s: help description with link to WP Mail logging and support page. */
'desc' => sprintf( __( 'Email notifications sent from WooCommerce are listed below. Click on an email to configure it.
%s', 'woocommerce' ), $desc_help_text ),
'type' => 'title',
'id' => 'email_notification_settings',
),
array( 'type' => 'email_notification' ),
array(
'type' => 'sectionend',
'id' => 'email_notification_settings',
),
array(
'type' => 'sectionend',
'id' => 'email_recipient_options',
),
array(
'title' => __( 'Email sender options', 'woocommerce' ),
'type' => 'title',
'desc' => __( "Set the name and email address you'd like your outgoing emails to use.", 'woocommerce' ),
'id' => 'email_options',
),
array(
'title' => __( '"From" name', 'woocommerce' ),
'desc' => '',
'id' => 'woocommerce_email_from_name',
'type' => 'text',
'css' => 'min-width:400px;',
'default' => esc_attr( get_bloginfo( 'name', 'display' ) ),
'autoload' => false,
'desc_tip' => true,
),
array(
'title' => __( '"From" address', 'woocommerce' ),
'desc' => '',
'id' => 'woocommerce_email_from_address',
'type' => 'email',
'custom_attributes' => array(
'multiple' => 'multiple',
),
'css' => 'min-width:400px;',
'default' => get_option( 'admin_email' ),
'autoload' => false,
'desc_tip' => true,
),
array(
'type' => 'sectionend',
'id' => 'email_options',
),
array(
'title' => __( 'Email template', 'woocommerce' ),
'type' => 'title',
'desc' => $email_template_description,
'id' => 'email_template_options',
),
$logo_image,
$header_alignment,
$font_family,
$base_color_setting_in_template_opts,
$bg_color_setting_in_template_opts,
$body_bg_color_setting_in_template_opts,
$body_text_color_setting_in_template_opts,
array(
'title' => __( 'Footer text', 'woocommerce' ),
'desc' => $footer_text_description,
'id' => 'woocommerce_email_footer_text',
'css' => 'width:400px; height: 75px;',
'placeholder' => __( 'N/A', 'woocommerce' ),
'type' => 'textarea',
'default' => $footer_text_default,
'autoload' => false,
'desc_tip' => true,
),
$footer_text_color_setting_in_template_opts,
array(
'type' => 'sectionend',
'id' => 'email_template_options',
),
$color_palette_section_header,
$base_color_setting_in_palette,
$bg_color_setting_in_palette,
$body_bg_color_setting_in_palette,
$body_text_color_setting_in_palette,
$footer_text_color_setting_in_palette,
$color_palette_section_end,
array( 'type' => 'email_preview' ),
array(
'title' => __( 'Store management insights', 'woocommerce' ),
'type' => 'title',
'id' => 'email_merchant_notes',
),
array(
'title' => __( 'Enable email insights', 'woocommerce' ),
'desc' => __( 'Receive email notifications with additional guidance to complete the basic store setup and helpful insights', 'woocommerce' ),
'id' => 'woocommerce_merchant_email_notifications',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'default' => 'no',
'autoload' => false,
),
array(
'type' => 'sectionend',
'id' => 'email_merchant_notes',
),
);
// Remove empty elements that depend on the email_improvements feature flag.
$settings = array_filter( $settings );
return apply_filters( 'woocommerce_email_settings', $settings );
}
/**
* Get default colors for emails.
*/
private function get_email_default_colors() {
$base_color_default = '#720eec';
$bg_color_default = '#f7f7f7';
$body_bg_color_default = '#ffffff';
$body_text_color_default = '#3c3c3c';
$footer_text_color_default = '#3c3c3c';
if ( FeaturesUtil::feature_is_enabled( 'email_improvements' ) ) {
$base_color_default = '#8526ff';
$bg_color_default = '#ffffff';
$body_bg_color_default = '#ffffff';
$body_text_color_default = '#1e1e1e';
$footer_text_color_default = '#787c82';
if ( wc_current_theme_is_fse_theme() && function_exists( 'wp_get_global_styles' ) ) {
$global_styles = wp_get_global_styles( array(), array( 'transforms' => array( 'resolve-variables' ) ) );
$base_color_default = $global_styles['elements']['button']['color']['text'] ?? $base_color_default;
$bg_color_default = $global_styles['color']['background'] ?? $bg_color_default;
$body_bg_color_default = $global_styles['color']['background'] ?? $body_bg_color_default;
$body_text_color_default = $global_styles['color']['text'] ?? $body_text_color_default;
$footer_text_color_default = $global_styles['elements']['caption']['color']['text'] ?? $footer_text_color_default;
}
}
return compact(
'base_color_default',
'bg_color_default',
'body_bg_color_default',
'body_text_color_default',
'footer_text_color_default',
);
}
/**
* Get custom fonts for emails.
*/
public function get_custom_fonts() {
$custom_fonts = array();
if ( wc_current_theme_is_fse_theme() && class_exists( 'WP_Font_Face_Resolver' ) ) {
$theme_fonts = WP_Font_Face_Resolver::get_fonts_from_theme_json();
if ( count( $theme_fonts ) > 0 ) {
foreach ( $theme_fonts as $font ) {
if ( ! empty( $font[0]['font-family'] ) ) {
$custom_fonts[ $font[0]['font-family'] ] = $font[0]['font-family'];
}
}
}
}
ksort( $custom_fonts );
return $custom_fonts;
}
/**
* Output the settings.
*/
public function output() {
global $current_section;
// Define emails that can be customised here.
$mailer = WC()->mailer();
$email_templates = $mailer->get_emails();
if ( $current_section ) {
foreach ( $email_templates as $email_key => $email ) {
if ( strtolower( $email_key ) === $current_section ) {
$this->run_email_admin_options( $email );
break;
}
}
}
parent::output();
}
/**
* Run the 'admin_options' method on a given email.
* This method exists to easy unit testing.
*
* @param object $email The email object to run the method on.
*/
protected function run_email_admin_options( $email ) {
$email->admin_options();
}
/**
* Save settings.
*/
public function save() {
global $current_section;
if ( ! $current_section ) {
$this->save_settings_for_current_section();
$this->do_update_options_action();
} else {
$wc_emails = WC_Emails::instance();
if ( in_array( $current_section, array_map( 'sanitize_title', array_keys( $wc_emails->get_emails() ) ), true ) ) {
foreach ( $wc_emails->get_emails() as $email_id => $email ) {
if ( sanitize_title( $email_id ) === $current_section ) {
$this->do_update_options_action( $email->id );
}
}
} else {
$this->save_settings_for_current_section();
$this->do_update_options_action();
}
}
}
/**
* Output email notification settings.
*/
public function email_notification_setting() {
// Define emails that can be customised here.
$mailer = WC()->mailer();
$email_templates = $mailer->get_emails();
?>
' . esc_html( $column ) . ' | '; } ?>||||
---|---|---|---|---|
' . esc_html( $email->get_title() ) . ' ' . wc_help_tip( $email->get_description() ) . ' | '; break; case 'recipient': echo '' . esc_html( $email->is_customer_email() ? __( 'Customer', 'woocommerce' ) : $email->get_recipient() ) . ' | '; break; case 'status': echo ''; if ( $email->is_manual() ) { echo '' . esc_html__( 'Manual', 'woocommerce' ) . ''; } elseif ( $email->is_enabled() ) { echo '' . esc_html__( 'Yes', 'woocommerce' ) . ''; } else { echo '-'; } echo ' | '; break; case 'email_type': echo '' . esc_html( $email->get_content_type() ) . ' | '; break; case 'actions': echo '' . esc_html__( 'Manage', 'woocommerce' ) . ' | '; break; default: do_action( 'woocommerce_email_setting_column_' . $key, $email ); break; } } echo '