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
if ( ! class_exists ( 'WC_Settings_Emails' ) ) :
/**
* WC_Settings_Emails
*/
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
add_filter ( 'woocommerce_settings_tabs_array' , array ( $this , 'add_settings_page' ), 20 );
add_action ( 'woocommerce_sections_' . $this -> id , array ( $this , 'output_sections' ) );
add_action ( 'woocommerce_settings_' . $this -> id , array ( $this , 'output' ) );
add_action ( 'woocommerce_settings_save_' . $this -> id , array ( $this , 'save' ) );
}
/**
* Get sections
*
* @ return array
*/
public function get_sections () {
2014-08-31 08:22:03 +00:00
2013-07-26 14:36:28 +00:00
$sections = array (
2014-08-31 08:22:03 +00:00
'' => __ ( 'Email Options' , 'woocommerce' )
2013-07-26 14:36:28 +00:00
);
// 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
2015-06-16 13:47:03 +00:00
foreach ( $email_templates as $email_id => $email ) {
2013-10-25 10:53:53 +00:00
$title = empty ( $email -> title ) ? ucfirst ( $email -> id ) : ucfirst ( $email -> title );
2013-07-26 14:36:28 +00:00
2015-06-16 13:47:03 +00:00
$sections [ strtolower ( $email_id ) ] = esc_html ( $title );
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
}
/**
* Get settings array
*
* @ 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
array ( 'type' => 'sectionend' , 'id' => 'email_recipient_options' ),
2014-08-31 08:22:03 +00:00
array ( 'title' => __ ( 'Email Sender Options' , 'woocommerce' ), 'type' => 'title' , 'desc' => __ ( 'The following options affect the sender (email address and name) used in WooCommerce emails.' , 'woocommerce' ), 'id' => 'email_options' ),
2013-07-26 14:36:28 +00:00
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( '"From" Name' , 'woocommerce' ),
'desc' => '' ,
'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' ) ),
2014-08-31 08:22:03 +00:00
'autoload' => false
2013-07-26 14:36:28 +00:00
),
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( '"From" Email Address' , 'woocommerce' ),
'desc' => '' ,
'id' => 'woocommerce_email_from_address' ,
'type' => 'email' ,
2013-07-26 14:36:28 +00:00
'custom_attributes' => array (
2014-08-31 08:22:03 +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' ),
2014-08-31 08:22:03 +00:00
'autoload' => false
2013-07-26 14:36:28 +00:00
),
array ( 'type' => 'sectionend' , 'id' => 'email_options' ),
2015-02-18 15:47:30 +00:00
array ( 'title' => __ ( 'Email Template' , 'woocommerce' ), 'type' => 'title' , 'desc' => sprintf ( __ ( 'This section lets you customise the WooCommerce emails. <a href="%s" target="_blank">Click here to preview your email template</a>. For more advanced control copy <code>woocommerce/templates/emails/</code> to <code>yourtheme/woocommerce/emails/</code>.' , '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 (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Header Image' , 'woocommerce' ),
2015-02-18 15:47:30 +00:00
'desc' => sprintf ( __ ( 'Enter a URL to an image you want to show in the email\'s header. Upload your image using the <a href="%s">media uploader</a>.' , 'woocommerce' ), admin_url ( 'media-new.php' ) ),
2014-08-31 08:22:03 +00:00
'id' => 'woocommerce_email_header_image' ,
'type' => 'text' ,
'css' => 'min-width:300px;' ,
'default' => '' ,
'autoload' => false
2013-07-26 14:36:28 +00:00
),
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Email Footer Text' , 'woocommerce' ),
'desc' => __ ( 'The text to appear in the footer of WooCommerce emails.' , 'woocommerce' ),
'id' => 'woocommerce_email_footer_text' ,
'css' => 'width:100%; height: 75px;' ,
'type' => 'textarea' ,
2015-02-18 15:47:30 +00:00
'default' => get_bloginfo ( 'name' , 'display' ) . ' - ' . __ ( 'Powered by WooCommerce' , 'woocommerce' ),
2014-08-31 08:22:03 +00:00
'autoload' => false
2013-07-26 14:36:28 +00:00
),
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Base Colour' , 'woocommerce' ),
'desc' => __ ( 'The base colour for WooCommerce email templates. Default <code>#557da1</code>.' , 'woocommerce' ),
'id' => 'woocommerce_email_base_color' ,
'type' => 'color' ,
'css' => 'width:6em;' ,
'default' => '#557da1' ,
'autoload' => false
2013-07-26 14:36:28 +00:00
),
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Background Colour' , 'woocommerce' ),
'desc' => __ ( 'The background colour for WooCommerce email templates. Default <code>#f5f5f5</code>.' , 'woocommerce' ),
'id' => 'woocommerce_email_background_color' ,
'type' => 'color' ,
'css' => 'width:6em;' ,
'default' => '#f5f5f5' ,
'autoload' => false
2013-07-26 14:36:28 +00:00
),
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Email Body Background Colour' , 'woocommerce' ),
'desc' => __ ( 'The main body background colour. Default <code>#fdfdfd</code>.' , 'woocommerce' ),
'id' => 'woocommerce_email_body_background_color' ,
'type' => 'color' ,
'css' => 'width:6em;' ,
'default' => '#fdfdfd' ,
'autoload' => false
2013-07-26 14:36:28 +00:00
),
array (
2014-08-31 08:22:03 +00:00
'title' => __ ( 'Email Body Text Colour' , 'woocommerce' ),
'desc' => __ ( 'The main body text colour. Default <code>#505050</code>.' , 'woocommerce' ),
'id' => 'woocommerce_email_text_color' ,
'type' => 'color' ,
'css' => 'width:6em;' ,
'default' => '#505050' ,
'autoload' => false
2013-07-26 14:36:28 +00:00
),
array ( 'type' => 'sectionend' , 'id' => 'email_template_options' ),
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
}
/**
* Output the settings
*/
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 ) {
2014-08-31 08:22:03 +00:00
foreach ( $email_templates as $email ) {
2013-07-26 14:36:28 +00:00
if ( strtolower ( get_class ( $email ) ) == $current_section ) {
$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 );
}
}
/**
* Save settings
*/
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 ) {
if ( $current_section === sanitize_title ( $email_id ) ) {
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 );
}
}
}
}
endif ;
2014-08-31 08:22:03 +00:00
return new WC_Settings_Emails ();