WC_Settings_Emails

WC_Settings_Emails.

Defined (1)

The class is defined in the following location(s).

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