2013-07-26 14:36:28 +00:00
< ? php
/**
* WooCommerce Email Settings
*
2014-08-31 08:22:03 +00:00
* @ author WooThemes
* @ category Admin
* @ package WooCommerce / Admin
2013-07-26 14:36:28 +00:00
* @ version 2.1 . 0
*/
2014-09-20 19:55:47 +00:00
if ( ! defined ( 'ABSPATH' ) ) {
exit ; // Exit if accessed directly
}
2013-07-26 14:36:28 +00:00
2017-02-16 11:46:01 +00:00
if ( ! class_exists ( 'WC_Settings_Emails' , false ) ) :
2013-07-26 14:36:28 +00:00
/**
2015-11-03 13:31:20 +00:00
* WC_Settings_Emails .
2013-07-26 14:36:28 +00:00
*/
class WC_Settings_Emails extends WC_Settings_Page {
/**
* Constructor .
*/
public function __construct () {
$this -> id = 'email' ;
2013-08-22 10:58:03 +00:00
$this -> label = __ ( 'Emails' , 'woocommerce' );
2013-07-26 14:36:28 +00:00
2015-11-02 16:27:00 +00:00
add_action ( 'woocommerce_admin_field_email_notification' , array ( $this , 'email_notification_setting' ) );
2017-08-12 00:36:35 +00:00
parent :: __construct ();
2013-07-26 14:36:28 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Get sections .
2013-07-26 14:36:28 +00:00
*
* @ return array
*/
public function get_sections () {
$sections = array (
2016-10-12 10:16:30 +00:00
'' => __ ( 'Email options' , 'woocommerce' ),
2013-07-26 14:36:28 +00:00
);
2014-02-17 14:30:37 +00:00
return apply_filters ( 'woocommerce_get_sections_' . $this -> id , $sections );
2013-07-26 14:36:28 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Get settings array .
2013-07-26 14:36:28 +00:00
*
* @ return array
*/
public function get_settings () {
2015-02-18 15:47:30 +00:00
$settings = apply_filters ( 'woocommerce_email_settings' , array (
2013-07-26 14:36:28 +00:00
2016-10-12 10:16:30 +00:00
array ( 'title' => __ ( 'Email notifications' , 'woocommerce' ), 'desc' => __ ( 'Email notifications sent from WooCommerce are listed below. Click on an email to configure it.' , 'woocommerce' ), 'type' => 'title' , 'id' => 'email_notification_settings' ),
2015-11-02 16:27:00 +00:00
array ( 'type' => 'email_notification' ),
array ( 'type' => 'sectionend' , 'id' => 'email_notification_settings' ),
2013-07-26 14:36:28 +00:00
array ( 'type' => 'sectionend' , 'id' => 'email_recipient_options' ),
2016-10-12 10:16:30 +00:00
array ( 'title' => __ ( 'Email sender options' , 'woocommerce' ), 'type' => 'title' , 'desc' => '' , 'id' => 'email_options' ),
2013-07-26 14:36:28 +00:00
array (
2016-10-12 10:16:30 +00:00
'title' => __ ( '"From" name' , 'woocommerce' ),
2017-04-26 12:51:53 +00:00
'desc' => __ ( 'How the sender name appears in outgoing WooCommerce emails.' , 'woocommerce' ),
2014-08-31 08:22:03 +00:00
'id' => 'woocommerce_email_from_name' ,
'type' => 'text' ,
'css' => 'min-width:300px;' ,
2015-02-18 15:47:30 +00:00
'default' => esc_attr ( get_bloginfo ( 'name' , 'display' ) ),
2015-11-02 16:27:00 +00:00
'autoload' => false ,
2016-08-27 01:46:45 +00:00
'desc_tip' => true ,
2013-07-26 14:36:28 +00:00
),
array (
2016-10-12 10:16:30 +00:00
'title' => __ ( '"From" address' , 'woocommerce' ),
2017-04-26 12:51:53 +00:00
'desc' => __ ( 'How the sender email appears in outgoing WooCommerce emails.' , 'woocommerce' ),
2014-08-31 08:22:03 +00:00
'id' => 'woocommerce_email_from_address' ,
'type' => 'email' ,
2013-07-26 14:36:28 +00:00
'custom_attributes' => array (
2016-08-27 01:46:45 +00:00
'multiple' => 'multiple' ,
2013-07-26 14:36:28 +00:00
),
2014-08-31 08:22:03 +00:00
'css' => 'min-width:300px;' ,
2015-02-18 15:47:30 +00:00
'default' => get_option ( 'admin_email' ),
2015-11-02 16:27:00 +00:00
'autoload' => false ,
2016-08-27 01:46:45 +00:00
'desc_tip' => true ,
2013-07-26 14:36:28 +00:00
),
array ( 'type' => 'sectionend' , 'id' => 'email_options' ),
2016-10-12 10:16:30 +00:00
array ( 'title' => __ ( 'Email template' , 'woocommerce' ), 'type' => 'title' , 'desc' => sprintf ( __ ( 'This section lets you customize the WooCommerce emails. <a href="%s" target="_blank">Click here to preview your email template</a>.' , 'woocommerce' ), wp_nonce_url ( admin_url ( '?preview_woocommerce_mail=true' ), 'preview-mail' ) ), 'id' => 'email_template_options' ),
2013-07-26 14:36:28 +00:00
array (
2016-10-12 10:16:30 +00:00
'title' => __ ( 'Header image' , 'woocommerce' ),
2015-11-02 16:27:00 +00:00
'desc' => __ ( 'URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).' , 'woocommerce' ),
'id' => 'woocommerce_email_header_image' ,
'type' => 'text' ,
'css' => 'min-width:300px;' ,
'placeholder' => __ ( 'N/A' , 'woocommerce' ),
'default' => '' ,
'autoload' => false ,
2016-08-27 01:46:45 +00:00
'desc_tip' => true ,
2013-07-26 14:36:28 +00:00
),
array (
2016-10-12 10:16:30 +00:00
'title' => __ ( 'Footer text' , 'woocommerce' ),
2017-10-28 02:18:53 +00:00
'desc' => __ ( 'The text to appear in the footer of WooCommerce emails.' , 'woocommerce' )
. ' ' . sprintf ( __ ( 'Available placeholders: %s' , 'woocommerce' ), '{site_title}' ),
2015-11-02 16:27:00 +00:00
'id' => 'woocommerce_email_footer_text' ,
'css' => 'width:300px; height: 75px;' ,
'placeholder' => __ ( 'N/A' , 'woocommerce' ),
'type' => 'textarea' ,
2017-10-28 02:18:53 +00:00
'default' => '{site_title}' ,
2015-11-02 16:27:00 +00:00
'autoload' => false ,
2016-08-27 01:46:45 +00:00
'desc_tip' => true ,
2013-07-26 14:36:28 +00:00
),
array (
2016-12-19 11:28:09 +00:00
'title' => __ ( 'Base color' , 'woocommerce' ),
2016-10-29 17:32:38 +00:00
/* translators: %s: default color */
2016-12-19 11:28:09 +00:00
'desc' => sprintf ( __ ( 'The base color for WooCommerce email templates. Default %s.' , 'woocommerce' ), '<code>#96588a</code>' ),
2014-08-31 08:22:03 +00:00
'id' => 'woocommerce_email_base_color' ,
'type' => 'color' ,
'css' => 'width:6em;' ,
2016-08-22 23:59:56 +00:00
'default' => '#96588a' ,
2015-11-02 16:27:00 +00:00
'autoload' => false ,
2016-08-27 01:46:45 +00:00
'desc_tip' => true ,
2013-07-26 14:36:28 +00:00
),
array (
2016-12-19 11:28:09 +00:00
'title' => __ ( 'Background color' , 'woocommerce' ),
2016-10-29 17:32:38 +00:00
/* translators: %s: default color */
2016-12-19 11:28:09 +00:00
'desc' => sprintf ( __ ( 'The background color for WooCommerce email templates. Default %s.' , 'woocommerce' ), '<code>#f7f7f7</code>' ),
2014-08-31 08:22:03 +00:00
'id' => 'woocommerce_email_background_color' ,
'type' => 'color' ,
'css' => 'width:6em;' ,
2016-08-22 23:59:56 +00:00
'default' => '#f7f7f7' ,
2015-11-02 16:27:00 +00:00
'autoload' => false ,
2016-08-27 01:46:45 +00:00
'desc_tip' => true ,
2013-07-26 14:36:28 +00:00
),
array (
2016-12-19 11:28:09 +00:00
'title' => __ ( 'Body background color' , 'woocommerce' ),
2016-10-29 17:32:38 +00:00
/* translators: %s: default color */
2016-12-19 11:28:09 +00:00
'desc' => sprintf ( __ ( 'The main body background color. Default %s.' , 'woocommerce' ), '<code>#ffffff</code>' ),
2014-08-31 08:22:03 +00:00
'id' => 'woocommerce_email_body_background_color' ,
'type' => 'color' ,
'css' => 'width:6em;' ,
2016-08-22 23:59:56 +00:00
'default' => '#ffffff' ,
2015-11-02 16:27:00 +00:00
'autoload' => false ,
2016-08-27 01:46:45 +00:00
'desc_tip' => true ,
2013-07-26 14:36:28 +00:00
),
array (
2016-12-19 11:28:09 +00:00
'title' => __ ( 'Body text color' , 'woocommerce' ),
2016-10-29 17:32:38 +00:00
/* translators: %s: default color */
2016-12-19 11:28:09 +00:00
'desc' => sprintf ( __ ( 'The main body text color. Default %s.' , 'woocommerce' ), '<code>#3c3c3c</code>' ),
2014-08-31 08:22:03 +00:00
'id' => 'woocommerce_email_text_color' ,
'type' => 'color' ,
'css' => 'width:6em;' ,
2016-08-22 23:59:56 +00:00
'default' => '#3c3c3c' ,
2015-11-02 16:27:00 +00:00
'autoload' => false ,
2016-08-27 01:46:45 +00:00
'desc_tip' => true ,
2013-07-26 14:36:28 +00:00
),
2016-09-12 14:40:28 +00:00
array ( 'type' => 'sectionend' , 'id' => 'email_template_options' ),
2013-07-26 14:36:28 +00:00
2014-09-12 11:20:06 +00:00
) );
return apply_filters ( 'woocommerce_get_settings_' . $this -> id , $settings );
2013-07-26 14:36:28 +00:00
}
/**
2015-11-03 13:31:20 +00:00
* Output the settings .
2013-07-26 14:36:28 +00:00
*/
public function output () {
global $current_section ;
// Define emails that can be customised here
2014-08-31 08:22:03 +00:00
$mailer = WC () -> mailer ();
$email_templates = $mailer -> get_emails ();
2013-07-26 14:36:28 +00:00
if ( $current_section ) {
2015-06-17 01:36:36 +00:00
foreach ( $email_templates as $email_key => $email ) {
if ( strtolower ( $email_key ) == $current_section ) {
2013-07-26 14:36:28 +00:00
$email -> admin_options ();
break ;
}
}
2014-08-31 08:22:03 +00:00
} else {
2013-07-26 14:36:28 +00:00
$settings = $this -> get_settings ();
WC_Admin_Settings :: output_fields ( $settings );
}
}
/**
2015-11-03 13:31:20 +00:00
* Save settings .
2013-07-26 14:36:28 +00:00
*/
public function save () {
global $current_section ;
if ( ! $current_section ) {
2015-05-29 16:38:25 +00:00
WC_Admin_Settings :: save_fields ( $this -> get_settings () );
2013-07-26 14:36:28 +00:00
} else {
2015-05-29 16:38:25 +00:00
$wc_emails = WC_Emails :: instance ();
2014-12-12 12:48:55 +00:00
2015-05-29 16:38:25 +00:00
if ( in_array ( $current_section , array_map ( 'sanitize_title' , array_keys ( $wc_emails -> get_emails () ) ) ) ) {
2015-06-13 14:15:58 +00:00
foreach ( $wc_emails -> get_emails () as $email_id => $email ) {
2016-09-09 00:14:28 +00:00
if ( sanitize_title ( $email_id ) === $current_section ) {
2015-06-16 18:46:54 +00:00
do_action ( 'woocommerce_update_options_' . $this -> id . '_' . $email -> id );
2015-05-29 16:38:25 +00:00
}
}
2013-07-26 14:36:28 +00:00
} else {
do_action ( 'woocommerce_update_options_' . $this -> id . '_' . $current_section );
}
}
}
2015-11-02 16:27:00 +00:00
/**
2015-12-16 06:25:17 +00:00
* Output email notification settings .
2015-11-02 16:27:00 +00:00
*/
public function email_notification_setting () {
// Define emails that can be customised here
$mailer = WC () -> mailer ();
$email_templates = $mailer -> get_emails ();
?>
< tr valign = " top " >
< td class = " wc_emails_wrapper " colspan = " 2 " >
< table class = " wc_emails widefat " cellspacing = " 0 " >
< thead >
< tr >
< ? php
$columns = apply_filters ( 'woocommerce_email_setting_columns' , array (
'status' => '' ,
'name' => __ ( 'Email' , 'woocommerce' ),
2016-10-12 10:16:30 +00:00
'email_type' => __ ( 'Content type' , 'woocommerce' ),
2015-11-03 15:40:10 +00:00
'recipient' => __ ( 'Recipient(s)' , 'woocommerce' ),
2016-08-27 01:46:45 +00:00
'actions' => '' ,
2015-11-02 16:27:00 +00:00
) );
foreach ( $columns as $key => $column ) {
echo '<th class="wc-email-settings-table-' . esc_attr ( $key ) . '">' . esc_html ( $column ) . '</th>' ;
}
?>
</ tr >
</ thead >
< tbody >
< ? php
foreach ( $email_templates as $email_key => $email ) {
echo '<tr>' ;
foreach ( $columns as $key => $column ) {
switch ( $key ) {
case 'name' :
echo '<td class="wc-email-settings-table-' . esc_attr ( $key ) . ' " >
2015-12-16 06:25:17 +00:00
< a href = " ' . admin_url( 'admin.php?page=wc-settings&tab=email§ion=' . strtolower( $email_key ) ) . ' " > ' . $email->get_title() . ' </ a >
2015-11-03 16:12:13 +00:00
' . wc_help_tip( $email->get_description() ) . '
2015-11-02 16:27:00 +00:00
</ td > ' ;
break ;
case 'recipient' :
echo '<td class="wc-email-settings-table-' . esc_attr ( $key ) . ' " >
2015-11-03 15:40:10 +00:00
' . esc_html( $email->is_customer_email() ? __( ' Customer ', ' woocommerce ' ) : $email->get_recipient() ) . '
2015-11-02 16:27:00 +00:00
</ td > ' ;
break ;
case 'status' :
echo '<td class="wc-email-settings-table-' . esc_attr ( $key ) . '">' ;
2015-11-03 15:40:10 +00:00
if ( $email -> is_manual () ) {
2017-03-13 05:39:46 +00:00
echo '<span class="status-manual tips" data-tip="' . esc_attr__ ( 'Manually sent' , 'woocommerce' ) . '">' . esc_html__ ( 'Manual' , 'woocommerce' ) . '</span>' ;
2015-11-03 15:40:10 +00:00
} elseif ( $email -> is_enabled () ) {
2017-03-13 05:39:46 +00:00
echo '<span class="status-enabled tips" data-tip="' . esc_attr__ ( 'Enabled' , 'woocommerce' ) . '">' . esc_html__ ( 'Yes' , 'woocommerce' ) . '</span>' ;
2015-11-03 15:40:10 +00:00
} else {
2017-03-13 05:39:46 +00:00
echo '<span class="status-disabled tips" data-tip="' . esc_attr__ ( 'Disabled' , 'woocommerce' ) . '">-</span>' ;
2015-11-03 15:40:10 +00:00
}
2015-11-02 16:27:00 +00:00
echo '</td>' ;
break ;
case 'email_type' :
echo '<td class="wc-email-settings-table-' . esc_attr ( $key ) . ' " >
2015-11-03 15:40:10 +00:00
' . esc_html( $email->get_content_type() ) . '
2015-11-02 16:27:00 +00:00
</ td > ' ;
break ;
case 'actions' :
echo '<td class="wc-email-settings-table-' . esc_attr ( $key ) . ' " >
2017-03-13 05:39:46 +00:00
< a class = " button alignright tips " data - tip = " ' . esc_attr__( 'Configure', 'woocommerce' ) . ' " href = " ' . admin_url( 'admin.php?page=wc-settings&tab=email§ion=' . strtolower( $email_key ) ) . ' " > ' . esc_html__( ' Configure ', ' woocommerce ' ) . ' </ a >
2015-11-02 16:27:00 +00:00
</ td > ' ;
break ;
default :
do_action ( 'woocommerce_email_setting_column_' . $key , $email );
break ;
}
}
echo '</tr>' ;
}
?>
</ tbody >
</ table >
</ td >
</ tr >
< ? php
}
2013-07-26 14:36:28 +00:00
}
endif ;
2014-08-31 08:22:03 +00:00
return new WC_Settings_Emails ();