/includes/admin/settings/class-wc-settings-emails.php

  1. <?php 
  2. /** 
  3. * WooCommerce Email Settings 
  4. * 
  5. * @author WooThemes 
  6. * @category Admin 
  7. * @package WooCommerce/Admin 
  8. * @version 2.1.0 
  9. */ 
  10.  
  11. if ( ! defined( 'ABSPATH' ) ) { 
  12. exit; // Exit if accessed directly 
  13.  
  14. if ( ! class_exists( 'WC_Settings_Emails', false ) ) : 
  15.  
  16. /** 
  17. * WC_Settings_Emails. 
  18. */ 
  19. class WC_Settings_Emails extends WC_Settings_Page { 
  20.  
  21. /** 
  22. * Constructor. 
  23. */ 
  24. public function __construct() { 
  25. $this->id = 'email'; 
  26. $this->label = __( 'Emails', 'woocommerce' ); 
  27.  
  28. add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 ); 
  29. add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections' ) ); 
  30. add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) ); 
  31. add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) ); 
  32. add_action( 'woocommerce_admin_field_email_notification', array( $this, 'email_notification_setting' ) ); 
  33.  
  34. /** 
  35. * Get sections. 
  36. * 
  37. * @return array 
  38. */ 
  39. public function get_sections() { 
  40. $sections = array( 
  41. '' => __( 'Email options', 'woocommerce' ),  
  42. ); 
  43. return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections ); 
  44.  
  45. /** 
  46. * Get settings array. 
  47. * 
  48. * @return array 
  49. */ 
  50. public function get_settings() { 
  51. $settings = apply_filters( 'woocommerce_email_settings', array( 
  52.  
  53. 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' ),  
  54.  
  55. array( 'type' => 'email_notification' ),  
  56.  
  57. array( 'type' => 'sectionend', 'id' => 'email_notification_settings' ),  
  58.  
  59. array( 'type' => 'sectionend', 'id' => 'email_recipient_options' ),  
  60.  
  61. array( 'title' => __( 'Email sender options', 'woocommerce' ), 'type' => 'title', 'desc' => '', 'id' => 'email_options' ),  
  62.  
  63. array( 
  64. 'title' => __( '"From" name', 'woocommerce' ),  
  65. 'desc' => __( 'How the sender\'s name appears in outgoing WooCommerce emails.', 'woocommerce' ),  
  66. 'id' => 'woocommerce_email_from_name',  
  67. 'type' => 'text',  
  68. 'css' => 'min-width:300px;',  
  69. 'default' => esc_attr( get_bloginfo( 'name', 'display' ) ),  
  70. 'autoload' => false,  
  71. 'desc_tip' => true,  
  72. ),  
  73.  
  74. array( 
  75. 'title' => __( '"From" address', 'woocommerce' ),  
  76. 'desc' => __( 'How the sender\'s email appears in outgoing WooCommerce emails.', 'woocommerce' ),  
  77. 'id' => 'woocommerce_email_from_address',  
  78. 'type' => 'email',  
  79. 'custom_attributes' => array( 
  80. 'multiple' => 'multiple',  
  81. ),  
  82. 'css' => 'min-width:300px;',  
  83. 'default' => get_option( 'admin_email' ),  
  84. 'autoload' => false,  
  85. 'desc_tip' => true,  
  86. ),  
  87.  
  88. array( 'type' => 'sectionend', 'id' => 'email_options' ),  
  89.  
  90. 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' ),  
  91.  
  92. array( 
  93. 'title' => __( 'Header image', 'woocommerce' ),  
  94. 'desc' => __( 'URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'woocommerce' ),  
  95. 'id' => 'woocommerce_email_header_image',  
  96. 'type' => 'text',  
  97. 'css' => 'min-width:300px;',  
  98. 'placeholder' => __( 'N/A', 'woocommerce' ),  
  99. 'default' => '',  
  100. 'autoload' => false,  
  101. 'desc_tip' => true,  
  102. ),  
  103.  
  104. array( 
  105. 'title' => __( 'Footer text', 'woocommerce' ),  
  106. 'desc' => __( 'The text to appear in the footer of WooCommerce emails.', 'woocommerce' ),  
  107. 'id' => 'woocommerce_email_footer_text',  
  108. 'css' => 'width:300px; height: 75px;',  
  109. 'placeholder' => __( 'N/A', 'woocommerce' ),  
  110. 'type' => 'textarea',  
  111. /** translators: %s: site name */ 
  112. 'default' => sprintf( __( '%s - Powered by WooCommerce', 'woocommerce' ), get_bloginfo( 'name', 'display' ) ),  
  113. 'autoload' => false,  
  114. 'desc_tip' => true,  
  115. ),  
  116.  
  117. array( 
  118. 'title' => __( 'Base color', 'woocommerce' ),  
  119. /** translators: %s: default color */ 
  120. 'desc' => sprintf( __( 'The base color for WooCommerce email templates. Default %s.', 'woocommerce' ), '<code>#96588a</code>' ),  
  121. 'id' => 'woocommerce_email_base_color',  
  122. 'type' => 'color',  
  123. 'css' => 'width:6em;',  
  124. 'default' => '#96588a',  
  125. 'autoload' => false,  
  126. 'desc_tip' => true,  
  127. ),  
  128.  
  129. array( 
  130. 'title' => __( 'Background color', 'woocommerce' ),  
  131. /** translators: %s: default color */ 
  132. 'desc' => sprintf( __( 'The background color for WooCommerce email templates. Default %s.', 'woocommerce' ), '<code>#f7f7f7</code>' ),  
  133. 'id' => 'woocommerce_email_background_color',  
  134. 'type' => 'color',  
  135. 'css' => 'width:6em;',  
  136. 'default' => '#f7f7f7',  
  137. 'autoload' => false,  
  138. 'desc_tip' => true,  
  139. ),  
  140.  
  141. array( 
  142. 'title' => __( 'Body background color', 'woocommerce' ),  
  143. /** translators: %s: default color */ 
  144. 'desc' => sprintf( __( 'The main body background color. Default %s.', 'woocommerce' ), '<code>#ffffff</code>' ),  
  145. 'id' => 'woocommerce_email_body_background_color',  
  146. 'type' => 'color',  
  147. 'css' => 'width:6em;',  
  148. 'default' => '#ffffff',  
  149. 'autoload' => false,  
  150. 'desc_tip' => true,  
  151. ),  
  152.  
  153. array( 
  154. 'title' => __( 'Body text color', 'woocommerce' ),  
  155. /** translators: %s: default color */ 
  156. 'desc' => sprintf( __( 'The main body text color. Default %s.', 'woocommerce' ), '<code>#3c3c3c</code>' ),  
  157. 'id' => 'woocommerce_email_text_color',  
  158. 'type' => 'color',  
  159. 'css' => 'width:6em;',  
  160. 'default' => '#3c3c3c',  
  161. 'autoload' => false,  
  162. 'desc_tip' => true,  
  163. ),  
  164.  
  165. array( 'type' => 'sectionend', 'id' => 'email_template_options' ),  
  166.  
  167. ) ); 
  168.  
  169. return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings ); 
  170.  
  171. /** 
  172. * Output the settings. 
  173. */ 
  174. public function output() { 
  175. global $current_section; 
  176.  
  177. // Define emails that can be customised here 
  178. $mailer = WC()->mailer(); 
  179. $email_templates = $mailer->get_emails(); 
  180.  
  181. if ( $current_section ) { 
  182. foreach ( $email_templates as $email_key => $email ) { 
  183. if ( strtolower( $email_key ) == $current_section ) { 
  184. $email->admin_options(); 
  185. break; 
  186. } else { 
  187. $settings = $this->get_settings(); 
  188. WC_Admin_Settings::output_fields( $settings ); 
  189.  
  190. /** 
  191. * Save settings. 
  192. */ 
  193. public function save() { 
  194. global $current_section; 
  195.  
  196. if ( ! $current_section ) { 
  197. WC_Admin_Settings::save_fields( $this->get_settings() ); 
  198.  
  199. } else { 
  200. $wc_emails = WC_Emails::instance(); 
  201.  
  202. if ( in_array( $current_section, array_map( 'sanitize_title', array_keys( $wc_emails->get_emails() ) ) ) ) { 
  203. foreach ( $wc_emails->get_emails() as $email_id => $email ) { 
  204. if ( sanitize_title( $email_id ) === $current_section ) { 
  205. do_action( 'woocommerce_update_options_' . $this->id . '_' . $email->id ); 
  206. } else { 
  207. do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section ); 
  208.  
  209. /** 
  210. * Output email notification settings. 
  211. */ 
  212. public function email_notification_setting() { 
  213. // Define emails that can be customised here 
  214. $mailer = WC()->mailer(); 
  215. $email_templates = $mailer->get_emails(); 
  216. ?> 
  217. <tr valign="top"> 
  218. <td class="wc_emails_wrapper" colspan="2"> 
  219. <table class="wc_emails widefat" cellspacing="0"> 
  220. <thead> 
  221. <tr> 
  222. <?php 
  223. $columns = apply_filters( 'woocommerce_email_setting_columns', array( 
  224. 'status' => '',  
  225. 'name' => __( 'Email', 'woocommerce' ),  
  226. 'email_type' => __( 'Content type', 'woocommerce' ),  
  227. 'recipient' => __( 'Recipient(s)', 'woocommerce' ),  
  228. 'actions' => '',  
  229. ) ); 
  230. foreach ( $columns as $key => $column ) { 
  231. echo '<th class="wc-email-settings-table-' . esc_attr( $key ) . '">' . esc_html( $column ) . '</th>'; 
  232. ?> 
  233. </tr> 
  234. </thead> 
  235. <tbody> 
  236. <?php 
  237. foreach ( $email_templates as $email_key => $email ) { 
  238. echo '<tr>'; 
  239.  
  240. foreach ( $columns as $key => $column ) { 
  241.  
  242. switch ( $key ) { 
  243. case 'name' : 
  244. echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '"> 
  245. <a href="' . admin_url( 'admin.php?page=wc-settings&tab=email§ion=' . strtolower( $email_key ) ) . '">' . $email->get_title() . '</a> 
  246. ' . wc_help_tip( $email->get_description() ) . ' 
  247. </td>'; 
  248. break; 
  249. case 'recipient' : 
  250. echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '"> 
  251. ' . esc_html( $email->is_customer_email() ? __( 'Customer', 'woocommerce' ) : $email->get_recipient() ) . ' 
  252. </td>'; 
  253. break; 
  254. case 'status' : 
  255. echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '">'; 
  256.  
  257. if ( $email->is_manual() ) { 
  258. echo '<span class="status-manual tips" data-tip="' . esc_attr__( 'Manually sent', 'woocommerce' ) . '">' . esc_html__( 'Manual', 'woocommerce' ) . '</span>'; 
  259. } elseif ( $email->is_enabled() ) { 
  260. echo '<span class="status-enabled tips" data-tip="' . esc_attr__( 'Enabled', 'woocommerce' ) . '">' . esc_html__( 'Yes', 'woocommerce' ) . '</span>'; 
  261. } else { 
  262. echo '<span class="status-disabled tips" data-tip="' . esc_attr__( 'Disabled', 'woocommerce' ) . '">-</span>'; 
  263.  
  264. echo '</td>'; 
  265. break; 
  266. case 'email_type' : 
  267. echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '"> 
  268. ' . esc_html( $email->get_content_type() ) . ' 
  269. </td>'; 
  270. break; 
  271. case 'actions' : 
  272. echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '"> 
  273. <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> 
  274. </td>'; 
  275. break; 
  276. default : 
  277. do_action( 'woocommerce_email_setting_column_' . $key, $email ); 
  278. break; 
  279.  
  280. echo '</tr>'; 
  281. ?> 
  282. </tbody> 
  283. </table> 
  284. </td> 
  285. </tr> 
  286. <?php 
  287.  
  288. endif; 
  289.  
  290. return new WC_Settings_Emails(); 
.