1 <?php
2 3 4 5 6 7 8 9
10
11 if ( ! defined( 'ABSPATH' ) ) exit;
12
13 if ( ! class_exists( 'WC_Settings_Emails' ) ) :
14
15 16 17
18 class WC_Settings_Emails extends WC_Settings_Page {
19
20 21 22
23 public function __construct() {
24 $this->id = 'email';
25 $this->label = __( 'Emails', 'woocommerce' );
26
27 add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
28 add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections' ) );
29 add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
30 add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) );
31 }
32
33 34 35 36 37
38 public function get_sections() {
39 $sections = array(
40 '' => __( 'Email Options', 'woocommerce' )
41 );
42
43
44 $mailer = WC()->mailer();
45 $email_templates = $mailer->get_emails();
46
47 foreach ( $email_templates as $email ) {
48 $title = empty( $email->title ) ? ucfirst( $email->id ) : ucfirst( $email->title );
49
50 $sections[ strtolower( get_class( $email ) ) ] = esc_html( $title );
51 }
52
53 return $sections;
54 }
55
56 57 58 59 60
61 public function get_settings() {
62 return apply_filters('woocommerce_email_settings', array(
63
64 array( 'type' => 'sectionend', 'id' => 'email_recipient_options' ),
65
66 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' ),
67
68 array(
69 'title' => __( '"From" Name', 'woocommerce' ),
70 'desc' => '',
71 'id' => 'woocommerce_email_from_name',
72 'type' => 'text',
73 'css' => 'min-width:300px;',
74 'default' => esc_attr(get_bloginfo('title')),
75 'autoload' => false
76 ),
77
78 array(
79 'title' => __( '"From" Email Address', 'woocommerce' ),
80 'desc' => '',
81 'id' => 'woocommerce_email_from_address',
82 'type' => 'email',
83 'custom_attributes' => array(
84 'multiple' => 'multiple'
85 ),
86 'css' => 'min-width:300px;',
87 'default' => get_option('admin_email'),
88 'autoload' => false
89 ),
90
91 array( 'type' => 'sectionend', 'id' => 'email_options' ),
92
93 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' ),
94
95 array(
96 'title' => __( 'Header Image', 'woocommerce' ),
97 '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')),
98 'id' => 'woocommerce_email_header_image',
99 'type' => 'text',
100 'css' => 'min-width:300px;',
101 'default' => '',
102 'autoload' => false
103 ),
104
105 array(
106 'title' => __( 'Email Footer Text', 'woocommerce' ),
107 'desc' => __( 'The text to appear in the footer of WooCommerce emails.', 'woocommerce' ),
108 'id' => 'woocommerce_email_footer_text',
109 'css' => 'width:100%; height: 75px;',
110 'type' => 'textarea',
111 'default' => get_bloginfo('title') . ' - ' . __( 'Powered by WooCommerce', 'woocommerce' ),
112 'autoload' => false
113 ),
114
115 array(
116 'title' => __( 'Base Colour', 'woocommerce' ),
117 'desc' => __( 'The base colour for WooCommerce email templates. Default <code>#557da1</code>.', 'woocommerce' ),
118 'id' => 'woocommerce_email_base_color',
119 'type' => 'color',
120 'css' => 'width:6em;',
121 'default' => '#557da1',
122 'autoload' => false
123 ),
124
125 array(
126 'title' => __( 'Background Colour', 'woocommerce' ),
127 'desc' => __( 'The background colour for WooCommerce email templates. Default <code>#f5f5f5</code>.', 'woocommerce' ),
128 'id' => 'woocommerce_email_background_color',
129 'type' => 'color',
130 'css' => 'width:6em;',
131 'default' => '#f5f5f5',
132 'autoload' => false
133 ),
134
135 array(
136 'title' => __( 'Email Body Background Colour', 'woocommerce' ),
137 'desc' => __( 'The main body background colour. Default <code>#fdfdfd</code>.', 'woocommerce' ),
138 'id' => 'woocommerce_email_body_background_color',
139 'type' => 'color',
140 'css' => 'width:6em;',
141 'default' => '#fdfdfd',
142 'autoload' => false
143 ),
144
145 array(
146 'title' => __( 'Email Body Text Colour', 'woocommerce' ),
147 'desc' => __( 'The main body text colour. Default <code>#505050</code>.', 'woocommerce' ),
148 'id' => 'woocommerce_email_text_color',
149 'type' => 'color',
150 'css' => 'width:6em;',
151 'default' => '#505050',
152 'autoload' => false
153 ),
154
155 array( 'type' => 'sectionend', 'id' => 'email_template_options' ),
156
157 ));
158 }
159
160 161 162
163 public function output() {
164 global $current_section;
165
166
167 $mailer = WC()->mailer();
168 $email_templates = $mailer->get_emails();
169
170 if ( $current_section ) {
171 foreach ( $email_templates as $email ) {
172 if ( strtolower( get_class( $email ) ) == $current_section ) {
173 $email->admin_options();
174 break;
175 }
176 }
177 } else {
178 $settings = $this->get_settings();
179
180 WC_Admin_Settings::output_fields( $settings );
181 }
182 }
183
184 185 186
187 public function save() {
188 global $current_section;
189
190 if ( ! $current_section ) {
191
192 $settings = $this->get_settings();
193 WC_Admin_Settings::save_fields( $settings );
194
195 } else {
196
197
198 $mailer = WC()->mailer();
199
200 if ( class_exists( $current_section ) ) {
201 $current_section_class = new $current_section();
202 do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section_class->id );
203 WC()->mailer()->init();
204 } else {
205 do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section );
206 }
207 }
208 }
209 }
210
211 endif;
212
213 return new WC_Settings_Emails();