id = 'email';
$this->label = __( 'Emails', 'woocommerce' );
add_action( 'woocommerce_admin_field_email_notification', array( $this, 'email_notification_setting' ) );
add_action( 'woocommerce_admin_field_email_notification_block_emails', array( $this, 'email_notification_setting_block_emails' ) );
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' ) );
add_action( 'woocommerce_admin_field_previewing_new_templates', array( $this, 'previewing_new_templates' ) );
add_action( 'woocommerce_admin_field_email_improvements_button', array( $this, 'email_improvements_button' ) );
add_action( 'woocommerce_email_settings_after', array( $this, 'email_preview_single' ) );
add_action( 'woocommerce_settings_saved', array( $this, 'enable_email_improvements_when_trying_new_templates' ), 999 );
add_filter( 'woocommerce_admin_settings_sanitize_option_woocommerce_email_header_image', array( $this, 'sanitize_email_header_image' ), 10, 3 );
add_filter( 'woocommerce_tracks_event_properties', array( $this, 'append_feature_email_improvements_to_tracks' ) );
add_action( FeaturesController::FEATURE_ENABLED_CHANGED_ACTION, array( $this, 'track_email_improvements_feature_change' ), 10, 2 );
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'
);
$block_email_editor_enabled = FeaturesUtil::feature_is_enabled( 'block_email_editor' );
$email_improvements_enabled = $this->get_email_improvements_enabled();
// These defaults should be chosen by the same logic as the other color option properties.
$default_colors = EmailColors::get_default_colors( $email_improvements_enabled );
if ( $block_email_editor_enabled ) {
$email_notifications_field = 'email_notification_block_emails';
$email_notifications_desc = null;
} else {
$email_notifications_field = 'email_notification';
/* translators: %s: help description with link to WP Mail logging and support page. */
$email_notifications_desc = sprintf( __( 'Email notifications sent from WooCommerce are listed below. Click on an email to configure it.
%s', 'woocommerce' ), $desc_help_text );
}
$settings =
array(
array(
'title' => __( 'Email notifications', 'woocommerce' ),
'desc' => $email_notifications_desc,
'type' => 'title',
'id' => 'email_notification_settings',
),
array( 'type' => $email_notifications_field ),
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,
'skip_initial_save' => 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,
),
);
// Add reply-to fields when block email editor is enabled.
if ( $block_email_editor_enabled ) {
$settings = array_merge(
$settings,
array(
array(
'title' => __( 'Add "Reply-to" email', 'woocommerce' ),
'desc' => __( 'Add a different email address to receive replies.', 'woocommerce' ),
'id' => 'woocommerce_email_reply_to_enabled',
'type' => 'checkbox',
'default' => 'no',
'autoload' => false,
),
array(
'title' => __( '"Reply-to" name', 'woocommerce' ),
'desc' => '',
'id' => 'woocommerce_email_reply_to_name',
'type' => 'text',
'css' => 'min-width:400px;',
'default' => '',
'autoload' => false,
'desc_tip' => true,
),
array(
'title' => __( '"Reply-to" address', 'woocommerce' ),
'desc' => '',
'id' => 'woocommerce_email_reply_to_address',
'type' => 'email',
'css' => 'min-width:400px;',
'default' => '',
'autoload' => false,
'desc_tip' => true,
),
)
);
}
$settings = array_merge(
$settings,
array(
array(
'type' => 'sectionend',
'id' => 'email_options',
),
)
);
// If the email editor is enabled the design is handled by the email editor.
if ( ! $block_email_editor_enabled ) {
$settings = array_merge(
$settings,
array(
array(
'title' => __( 'Email template', 'woocommerce' ),
'type' => 'title',
'desc' => __( 'Customize your WooCommerce email template and preview it below.', 'woocommerce' ),
'id' => 'email_template_options',
),
array(
'title' => __( 'Try new templates', 'woocommerce' ),
'type' => 'previewing_new_templates',
'id' => 'previewing_new_templates',
),
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,
),
array(
'title' => __( 'Logo width (px)', 'woocommerce' ),
'id' => 'woocommerce_email_header_image_width',
'desc_tip' => '',
'default' => '120',
'type' => 'number',
'row_class' => $email_improvements_enabled ? '' : 'disabled',
),
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' ),
),
'row_class' => $email_improvements_enabled ? '' : 'disabled',
),
array(
'title' => __( 'Font family', 'woocommerce' ),
'id' => 'woocommerce_email_font_family',
'default' => 'Helvetica',
'type' => 'email_font_family',
'row_class' => $email_improvements_enabled ? '' : 'disabled',
),
array(
'title' => __( 'Footer text', 'woocommerce' ),
/* translators: %s: Available placeholders for use */
'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}' ),
'id' => 'woocommerce_email_footer_text',
'css' => 'width:400px; height: 75px;',
'placeholder' => __( 'N/A', 'woocommerce' ),
'type' => 'textarea',
'default' => '{site_title}
{store_address}',
'autoload' => false,
'desc_tip' => true,
),
array(
'type' => 'sectionend',
'id' => 'email_template_options',
),
array(
'title' => __( 'Color palette', 'woocommerce' ),
'type' => 'email_color_palette',
'id' => 'email_color_palette',
),
array(
'title' => __( 'Accent', 'woocommerce' ),
/* translators: %s: default color */
'desc' => sprintf( __( 'Customize the color of your buttons and links. Default %s.', 'woocommerce' ), '' . $default_colors['base'] . '' ),
'id' => 'woocommerce_email_base_color',
'type' => 'color',
'css' => 'width:6em;',
'default' => $default_colors['base'],
'autoload' => false,
'desc_tip' => true,
),
array(
'title' => __( 'Email background', 'woocommerce' ),
/* translators: %s: default color */
'desc' => sprintf( __( 'Select a color for the background of your emails. Default %s.', 'woocommerce' ), '' . $default_colors['bg'] . '' ),
'id' => 'woocommerce_email_background_color',
'type' => 'color',
'css' => 'width:6em;',
'default' => $default_colors['bg'],
'autoload' => false,
'desc_tip' => true,
),
array(
'title' => __( 'Content background', 'woocommerce' ),
/* translators: %s: default color */
'desc' => sprintf( __( 'Choose a background color for the content area of your emails. Default %s.', 'woocommerce' ), '' . $default_colors['body_bg'] . '' ),
'id' => 'woocommerce_email_body_background_color',
'type' => 'color',
'css' => 'width:6em;',
'default' => $default_colors['body_bg'],
'autoload' => false,
'desc_tip' => true,
),
array(
'title' => __( 'Heading & text', 'woocommerce' ),
/* translators: %s: default color */
'desc' => sprintf( __( 'Set the color of your headings and text. Default %s.', 'woocommerce' ), '' . $default_colors['body_text'] . '' ),
'id' => 'woocommerce_email_text_color',
'type' => 'color',
'css' => 'width:6em;',
'default' => $default_colors['body_text'],
'autoload' => false,
'desc_tip' => true,
),
array(
'title' => __( 'Secondary text', 'woocommerce' ),
/* translators: %s: footer default color */
'desc' => sprintf( __( 'Choose a color for your secondary text, such as your footer content. Default %s.', 'woocommerce' ), '' . $default_colors['footer_text'] . '' ),
'id' => 'woocommerce_email_footer_text_color',
'type' => 'color',
'css' => 'width:6em;',
'default' => $default_colors['footer_text'],
'autoload' => false,
'desc_tip' => true,
),
array(
'title' => __( 'Auto-sync with theme', 'woocommerce' ),
'desc' => __( 'Automatically update email styles when theme styles change', 'woocommerce' ),
'id' => 'woocommerce_email_auto_sync_with_theme',
'type' => 'hidden',
'default' => 'no',
'autoload' => false,
),
array(
'type' => 'sectionend',
'id' => 'email_color_palette',
),
array(
'title' => __( 'Email improvements button', 'woocommerce' ),
'type' => 'email_improvements_button',
'id' => 'email_improvements_button',
),
array( 'type' => 'email_preview' ),
)
);
}
// Remove empty elements that depend on the email_improvements feature flag.
$settings = array_filter( $settings );
/**
* Filters the email settings array.
*
* @since 2.1.0
*
* @param array $settings Array of email settings.
*/
return apply_filters( 'woocommerce_email_settings', $settings );
}
/**
* Get custom fonts for emails.
*/
public function get_custom_fonts() {
$custom_fonts = array();
if ( wp_is_block_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': $to = $email->is_customer_email() ? __( 'Customer', 'woocommerce' ) : $email->get_recipient(); $cc = false; $bcc = false; if ( FeaturesUtil::feature_is_enabled( 'email_improvements' ) ) { $ccs = $email->get_cc_recipient(); $bccs = $email->get_bcc_recipient(); // Translators: %s: comma-separated email addresses to which the email is cc-ed. $cc = $ccs ? sprintf( __( 'Cc: %s', 'woocommerce' ), $ccs ) : false; // Translators: %s: comma-separated email addresses to which the email is bcc-ed. $bcc = $bccs ? sprintf( __( 'Bcc: %s', 'woocommerce' ), $bccs ) : false; if ( $cc || $bcc ) { // Translators: %s: comma-separated email addresses to which the email is sent. $to = sprintf( __( 'To: %s', 'woocommerce' ), $to ); } } $allowed_tags = array( 'b' => array() ); echo '';
echo wp_kses( $to, $allowed_tags );
if ( $cc ) {
echo ' ' . wp_kses( $cc, $allowed_tags ); } if ( $bcc ) { echo ' ' . wp_kses( $bcc, $allowed_tags ); } echo ' | ';
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: /** * Fires when rendering a custom column in the email settings table. * * @since 2.1.0 * * @param WC_Email $email The email object. */ do_action( 'woocommerce_email_setting_column_' . $key, $email ); break; } } echo '