Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 487 lines (348 sloc) 15.302 kb
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
1 <?php
2 /**
ce84132 Mike Jolley Minor fixes and comments
mikejolley authored
3 * Email
4 *
5 * WooCommerce Emails Class which handles the sending on transactional emails and email templates
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
6 *
0836ce0 Mike Jolley Better class names (final)
mikejolley authored
7 * @class WC_Email
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
8 * @package WooCommerce
9 * @category Class
10 * @author WooThemes
11 */
0836ce0 Mike Jolley Better class names (final)
mikejolley authored
12 class WC_Email {
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
13
14 private $_from_address;
15 private $_from_name;
16
17 /** constructor */
18 function __construct() {
19 $this->_from_name = get_option('woocommerce_email_from_name');
20 $this->_from_address = get_option('woocommerce_email_from_address');
21
22 /**
23 * Email Header + Footer
24 **/
25 add_action('woocommerce_email_header', array(&$this, 'email_header'));
26 add_action('woocommerce_email_footer', array(&$this, 'email_footer'));
27
28 /**
29 * Add order meta to email templates
30 **/
31 add_action('woocommerce_email_after_order_table', array(&$this, 'order_meta'), 10, 2);
32
33 /**
34 * Hooks for sending emails during store events
35 **/
36 add_action('woocommerce_low_stock_notification', array(&$this, 'low_stock'));
37 add_action('woocommerce_no_stock_notification', array(&$this, 'no_stock'));
38 add_action('woocommerce_product_on_backorder_notification', array(&$this, 'backorder'));
39
40 add_action('woocommerce_order_status_pending_to_processing_notification', array(&$this, 'new_order'));
41 add_action('woocommerce_order_status_pending_to_completed_notification', array(&$this, 'new_order'));
42 add_action('woocommerce_order_status_pending_to_on-hold_notification', array(&$this, 'new_order'));
43 add_action('woocommerce_order_status_failed_to_processing_notification', array(&$this, 'new_order'));
44 add_action('woocommerce_order_status_failed_to_completed_notification', array(&$this, 'new_order'));
45
46 add_action('woocommerce_order_status_pending_to_processing_notification', array(&$this, 'customer_processing_order'));
47 add_action('woocommerce_order_status_pending_to_on-hold_notification', array(&$this, 'customer_processing_order'));
48
49 add_action('woocommerce_order_status_completed_notification', array(&$this, 'customer_completed_order'));
50
51 add_action('woocommerce_new_customer_note_notification', array(&$this, 'customer_note'));
52
53 // Let 3rd parties unhook the above via this hook
54 do_action( 'woocommerce_email', $this );
55 }
56
57 function get_from_name() {
58 return $this->_from_name;
59 }
60
61 function get_from_address() {
62 return $this->_from_address;
63 }
64
65 function get_content_type() {
66 return 'text/html';
67 }
68
3b5272e Mike Jolley Improved template loader
mikejolley authored
69 function email_header( $email_heading ) {
70 woocommerce_get_template('emails/email-header.php', array( 'email_heading' => $email_heading ));
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
71 }
72
73 function email_footer() {
3b5272e Mike Jolley Improved template loader
mikejolley authored
74 woocommerce_get_template('emails/email-footer.php');
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
75 }
76
77 /**
78 * Wraps a message in the woocommerce mail template
79 **/
23a3776 Mike Jolley Tweaks to order/validation class to improve performance
mikejolley authored
80 function wrap_message( $email_heading, $message ) {
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
81 // Buffer
82 ob_start();
83
3b5272e Mike Jolley Improved template loader
mikejolley authored
84 do_action('woocommerce_email_header', $email_heading);
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
85
86 echo wpautop(wptexturize( $message ));
87
88 do_action('woocommerce_email_footer');
89
90 // Get contents
7831db2 Mike Jolley Minor changes.
mikejolley authored
91 $message = ob_get_clean();
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
92
93 return $message;
94 }
95
d9b4307 Mike Jolley Added back headers Closes #635.
mikejolley authored
96 function send( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = "" ) {
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
97 add_filter( 'wp_mail_from', array(&$this, 'get_from_address') );
98 add_filter( 'wp_mail_from_name', array(&$this, 'get_from_name') );
99 add_filter( 'wp_mail_content_type', array(&$this, 'get_content_type') );
100
41f35f1 Mike Jolley Fixes odd premature end of headers issue
mikejolley authored
101 ob_start();
102
7831db2 Mike Jolley Minor changes.
mikejolley authored
103 wp_mail( $to, $subject, $message, $headers, $attachments );
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
104
41f35f1 Mike Jolley Fixes odd premature end of headers issue
mikejolley authored
105 ob_end_clean();
106
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
107 // Unhook
108 remove_filter( 'wp_mail_from', array(&$this, 'get_from_address') );
109 remove_filter( 'wp_mail_from_name', array(&$this, 'get_from_name') );
110 remove_filter( 'wp_mail_content_type', array(&$this, 'get_content_type') );
111 }
112
113 /**
114 * New order
115 **/
116 function new_order( $order_id ) {
117
0836ce0 Mike Jolley Better class names (final)
mikejolley authored
118 $order = new WC_Order( $order_id );
6dff689 Mike Jolley Fixes
mikejolley authored
119
f74e041 Mike Jolley Renamed textdomain Closes #444.
mikejolley authored
120 $email_heading = __('New Customer Order', 'woocommerce');
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
121
074ff1e Mike Jolley Blog name encoding
mikejolley authored
122 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
123
124 $subject = apply_filters( 'woocommerce_email_subject_new_order', sprintf( __( '[%s] New Customer Order (# %s)', 'woocommerce' ), $blogname, $order_id ), $order );
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
125
126 // Buffer
127 ob_start();
128
129 // Get mail template
3b5272e Mike Jolley Improved template loader
mikejolley authored
130 woocommerce_get_template('emails/admin-new-order.php', array(
131 'order' => $order,
132 'email_heading' => $email_heading
133 ));
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
134
135 // Get contents
136 $message = ob_get_clean();
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
137
138 // CC, BCC, additional headers
26f47e8 Mike Jolley More consistent email headers/attachments
mikejolley authored
139 $headers = apply_filters('woocommerce_email_headers', '', 'new_order');
140
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
141 // Attachments
26f47e8 Mike Jolley More consistent email headers/attachments
mikejolley authored
142 $attachments = apply_filters('woocommerce_email_attachments', '', 'new_order');
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
143
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
144 // Send the mail
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
145 $this->send( get_option('woocommerce_new_order_email_recipient'), $subject, $message, $headers, $attachments);
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
146 }
147
148 /**
149 * Processing Order
150 **/
151 function customer_processing_order( $order_id ) {
152
0836ce0 Mike Jolley Better class names (final)
mikejolley authored
153 $order = new WC_Order( $order_id );
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
154
f74e041 Mike Jolley Renamed textdomain Closes #444.
mikejolley authored
155 $email_heading = __('Order Received', 'woocommerce');
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
156
074ff1e Mike Jolley Blog name encoding
mikejolley authored
157 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
158
159 $subject = apply_filters( 'woocommerce_email_subject_customer_procesing_order', sprintf( __( '[%s] Order Received', 'woocommerce' ), $blogname ), $order );
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
160
161 // Buffer
162 ob_start();
163
164 // Get mail template
3b5272e Mike Jolley Improved template loader
mikejolley authored
165 woocommerce_get_template('emails/customer-processing-order.php', array(
166 'order' => $order,
167 'email_heading' => $email_heading
168 ));
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
169
170 // Get contents
171 $message = ob_get_clean();
48f11d8 Mike Jolley Filters for customer email attachments
mikejolley authored
172
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
173 // CC, BCC, additional headers
26f47e8 Mike Jolley More consistent email headers/attachments
mikejolley authored
174 $headers = apply_filters('woocommerce_email_headers', '', 'customer_processing_order');
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
175
48f11d8 Mike Jolley Filters for customer email attachments
mikejolley authored
176 // Attachments
26f47e8 Mike Jolley More consistent email headers/attachments
mikejolley authored
177 $attachments = apply_filters('woocommerce_email_attachments', '', 'customer_processing_order');
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
178
179 // Send the mail
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
180 $this->send( $order->billing_email, $subject, $message, $headers, $attachments );
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
181 }
182
183 /**
184 * Completed Order
185 **/
186 function customer_completed_order( $order_id ) {
187
0836ce0 Mike Jolley Better class names (final)
mikejolley authored
188 $order = new WC_Order( $order_id );
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
189
53e194a Mike Jolley has_downloadable_item fix
mikejolley authored
190 if ($order->has_downloadable_item()) :
f74e041 Mike Jolley Renamed textdomain Closes #444.
mikejolley authored
191 $subject = __('[%s] Order Complete/Download Links', 'woocommerce');
192 $email_heading = __('Order Complete/Download Links', 'woocommerce');
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
193 else :
f74e041 Mike Jolley Renamed textdomain Closes #444.
mikejolley authored
194 $subject = __('[%s] Order Complete', 'woocommerce');
195 $email_heading = __('Order Complete', 'woocommerce');
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
196 endif;
197
092fe41 Spencer Finnell Allow email subjects to be filtered.
spencerfinnell authored
198 $email_heading = apply_filters( 'woocommerce_completed_order_customer_notification_subject', $email_heading );
074ff1e Mike Jolley Blog name encoding
mikejolley authored
199
200 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
201
202 $subject = apply_filters( 'woocommerce_email_subject_customer_completed_order', sprintf( $subject, $blogname ), $order );
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
203
204 // Buffer
205 ob_start();
206
207 // Get mail template
3b5272e Mike Jolley Improved template loader
mikejolley authored
208 woocommerce_get_template('emails/customer-completed-order.php', array(
209 'order' => $order,
210 'email_heading' => $email_heading
211 ));
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
212
213 // Get contents
214 $message = ob_get_clean();
48f11d8 Mike Jolley Filters for customer email attachments
mikejolley authored
215
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
216 // CC, BCC, additional headers
26f47e8 Mike Jolley More consistent email headers/attachments
mikejolley authored
217 $headers = apply_filters('woocommerce_email_headers', '', 'customer_completed_order');
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
218
48f11d8 Mike Jolley Filters for customer email attachments
mikejolley authored
219 // Attachments
26f47e8 Mike Jolley More consistent email headers/attachments
mikejolley authored
220 $attachments = apply_filters('woocommerce_email_attachments', '', 'customer_completed_order');
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
221
222 // Send the mail
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
223 $this->send( $order->billing_email, $subject, $message, $headers, $attachments );
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
224 }
225
226 /**
35fadb0 Mike Jolley More consistent template file naming, broken checkout into templates
mikejolley authored
227 * Pay for order - invoice
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
228 **/
35fadb0 Mike Jolley More consistent template file naming, broken checkout into templates
mikejolley authored
229 function customer_invoice( $pay_for_order ) {
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
230
231 $order = $pay_for_order;
232
074ff1e Mike Jolley Blog name encoding
mikejolley authored
233 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
234
f692cf5 Mike Jolley 'Invoice' for completed/pending emails re-sends download links etc. Clos...
mikejolley authored
235 if ( $order->status == 'processing' || $order->status == 'completed' ) {
236 $email_heading = sprintf( __('Your order on %s', 'woocommerce'), $blogname );
237 $subject = apply_filters( 'woocommerce_email_subject_customer_invoice_paid', sprintf( __( '[%s] Your order', 'woocommerce' ), $blogname ), $order );
238 } else {
239 $email_heading = sprintf( __('Invoice for Order %s', 'woocommerce'), $order->get_order_number() );
240 $subject = apply_filters( 'woocommerce_email_subject_customer_invoice', sprintf( __( '[%s] Pay for Order', 'woocommerce' ), $blogname ), $order );
241 }
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
242
243 // Buffer
244 ob_start();
245
246 // Get mail template
3b5272e Mike Jolley Improved template loader
mikejolley authored
247 woocommerce_get_template('emails/customer-invoice.php', array(
248 'order' => $order,
249 'email_heading' => $email_heading
250 ));
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
251
252 // Get contents
253 $message = ob_get_clean();
48f11d8 Mike Jolley Filters for customer email attachments
mikejolley authored
254
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
255 // CC, BCC, additional headers
26f47e8 Mike Jolley More consistent email headers/attachments
mikejolley authored
256 $headers = apply_filters('woocommerce_email_headers', '', 'customer_invoice');
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
257
48f11d8 Mike Jolley Filters for customer email attachments
mikejolley authored
258 // Attachments
26f47e8 Mike Jolley More consistent email headers/attachments
mikejolley authored
259 $attachments = apply_filters('woocommerce_email_attachments', '', 'customer_invoice');
48f11d8 Mike Jolley Filters for customer email attachments
mikejolley authored
260
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
261 // Send the mail
26f47e8 Mike Jolley More consistent email headers/attachments
mikejolley authored
262 $this->send( $order->billing_email, $subject, $message, $headers, $attachments );
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
263 }
264
265 /**
266 * Customer notes
267 **/
268 function customer_note( $args ) {
269
270 $defaults = array(
271 'order_id' => '',
272 'customer_note' => ''
273 );
274
275 $args = wp_parse_args( $args, $defaults );
276
35d1d56 Mike Jolley Made product global, setup automatically, and removed the need to call t...
mikejolley authored
277 extract( $args );
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
278
279 if (!$order_id || !$customer_note) return;
280
0836ce0 Mike Jolley Better class names (final)
mikejolley authored
281 $order = new WC_Order( $order_id );
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
282
f74e041 Mike Jolley Renamed textdomain Closes #444.
mikejolley authored
283 $email_heading = __('A note has been added to your order', 'woocommerce');
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
284
074ff1e Mike Jolley Blog name encoding
mikejolley authored
285 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
286
287 $subject = apply_filters( 'woocommerce_email_subject_customer_note', sprintf( __( '[%s] A note has been added to your order', 'woocommerce' ), $blogname ), $order );
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
288
289 // Buffer
290 ob_start();
291
292 // Get mail template
3b5272e Mike Jolley Improved template loader
mikejolley authored
293 woocommerce_get_template('emails/customer-note.php', array(
294 'order' => $order,
295 'email_heading' => $email_heading,
296 'customer_note' => $customer_note
297 ));
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
298
299 // Get contents
300 $message = ob_get_clean();
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
301
302 // CC, BCC, additional headers
26f47e8 Mike Jolley More consistent email headers/attachments
mikejolley authored
303 $headers = apply_filters('woocommerce_email_headers', '', 'customer_note');
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
304
305 // Attachments
26f47e8 Mike Jolley More consistent email headers/attachments
mikejolley authored
306 $attachments = apply_filters('woocommerce_email_attachments', '', 'customer_note');
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
307
308 // Send the mail
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
309 $this->send( $order->billing_email, $subject, $message, $headers, $attachments );
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
310 }
311
312 /**
313 * Low stock notification email
314 **/
315 function low_stock( $product ) {
074ff1e Mike Jolley Blog name encoding
mikejolley authored
316
317 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
318
319 $subject = apply_filters( 'woocommerce_email_subject_low_stock', sprintf( '[%s] %s', $blogname, __( 'Product low in stock', 'woocommerce' ) ), $product );
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
320
ed9d57d Mike Jolley stock title
mikejolley authored
321 $sku = ($product->sku) ? '(' . $product->sku . ') ' : '';
322
2acd63d Mike Jolley Fix notices
mikejolley authored
323 if ( ! empty( $product->variation_id ) )
ed9d57d Mike Jolley stock title
mikejolley authored
324 $title = sprintf(__('Variation #%s of %s', 'woocommerce'), $product->variation_id, get_the_title($product->id)) . ' ' . $sku;
325 else
326 $title = sprintf(__('Product #%s - %s', 'woocommerce'), $product->id, get_the_title($product->id)) . ' ' . $sku;
327
328 $message = $title . __('is low in stock.', 'woocommerce');
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
329
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
330 // CC, BCC, additional headers
26f47e8 Mike Jolley More consistent email headers/attachments
mikejolley authored
331 $headers = apply_filters('woocommerce_email_headers', '', 'low_stock');
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
332
333 // Attachments
26f47e8 Mike Jolley More consistent email headers/attachments
mikejolley authored
334 $attachments = apply_filters('woocommerce_email_attachments', '', 'low_stock');
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
335
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
336 // Send the mail
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
337 wp_mail( get_option('woocommerce_stock_email_recipient'), $subject, $message, $headers, $attachments );
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
338 }
339
340 /**
341 * No stock notification email
342 **/
343 function no_stock( $product ) {
344
074ff1e Mike Jolley Blog name encoding
mikejolley authored
345 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
346
347 $subject = apply_filters( 'woocommerce_email_subject_no_stock', sprintf( '[%s] %s', $blogname, __( 'Product out of stock', 'woocommerce' ) ), $product );
ed9d57d Mike Jolley stock title
mikejolley authored
348
349 $sku = ($product->sku) ? '(' . $product->sku . ') ' : '';
350
2acd63d Mike Jolley Fix notices
mikejolley authored
351 if ( ! empty( $product->variation_id ) )
ed9d57d Mike Jolley stock title
mikejolley authored
352 $title = sprintf(__('Variation #%s of %s', 'woocommerce'), $product->variation_id, get_the_title($product->id)) . ' ' . $sku;
353 else
354 $title = sprintf(__('Product #%s - %s', 'woocommerce'), $product->id, get_the_title($product->id)) . ' ' . $sku;
355
356 $message = $title . __('is out of stock.', 'woocommerce');
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
357
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
358 // CC, BCC, additional headers
26f47e8 Mike Jolley More consistent email headers/attachments
mikejolley authored
359 $headers = apply_filters('woocommerce_email_headers', '', 'no_stock');
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
360
361 // Attachments
26f47e8 Mike Jolley More consistent email headers/attachments
mikejolley authored
362 $attachments = apply_filters('woocommerce_email_attachments', '', 'no_stock');
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
363
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
364 // Send the mail
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
365 wp_mail( get_option('woocommerce_stock_email_recipient'), $subject, $message, $headers, $attachments );
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
366 }
367
368
369 /**
370 * Backorder notification email
371 **/
372 function backorder( $args ) {
373
374 $defaults = array(
375 'product' => '',
129cf88 Mike Jolley Order # in backorder notification.
mikejolley authored
376 'quantity' => '',
377 'order_id' => ''
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
378 );
379
380 $args = wp_parse_args( $args, $defaults );
381
35d1d56 Mike Jolley Made product global, setup automatically, and removed the need to call t...
mikejolley authored
382 extract( $args );
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
383
384 if (!$product || !$quantity) return;
385
074ff1e Mike Jolley Blog name encoding
mikejolley authored
386 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
387
388 $subject = apply_filters( 'woocommerce_email_subject_backorder', sprintf( '[%s] %s', $blogname, __( 'Product Backorder', 'woocommerce' ) ), $product );
ed9d57d Mike Jolley stock title
mikejolley authored
389
390 $sku = ($product->sku) ? ' (' . $product->sku . ')' : '';
391
2acd63d Mike Jolley Fix notices
mikejolley authored
392 if ( ! empty( $product->variation_id ) )
ed9d57d Mike Jolley stock title
mikejolley authored
393 $title = sprintf(__('Variation #%s of %s', 'woocommerce'), $product->variation_id, get_the_title($product->id)) . $sku;
394 else
395 $title = sprintf(__('Product #%s - %s', 'woocommerce'), $product->id, get_the_title($product->id)) . $sku;
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
396
ed9d57d Mike Jolley stock title
mikejolley authored
397 $message = sprintf(__('%s units of %s have been backordered in order #%s.', 'woocommerce'), $quantity, $title, $order_id );
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
398
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
399 // CC, BCC, additional headers
26f47e8 Mike Jolley More consistent email headers/attachments
mikejolley authored
400 $headers = apply_filters('woocommerce_email_headers', '', 'backorder');
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
401
402 // Attachments
26f47e8 Mike Jolley More consistent email headers/attachments
mikejolley authored
403 $attachments = apply_filters('woocommerce_email_attachments', '', 'backorder');
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
404
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
405 // Send the mail
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
406 wp_mail( get_option('woocommerce_stock_email_recipient'), $subject, $message, $headers, $attachments );
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
407 }
408
409 /**
410 * Add order meta to email templates
411 **/
412 function order_meta( $order, $sent_to_admin ) {
413
414 $meta = array();
415 $show_fields = apply_filters('woocommerce_email_order_meta_keys', array('coupons'), $sent_to_admin);
416
417 if ($order->customer_note) :
01c92ea Mike Jolley Minor fixes
mikejolley authored
418 $meta[__('Note', 'woocommerce')] = wptexturize($order->customer_note);
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
419 endif;
420
421 if ($show_fields) foreach ($show_fields as $field) :
422
423 $value = get_post_meta( $order->id, $field, true );
424 if ($value) $meta[ucwords(esc_attr($field))] = wptexturize($value);
425
426 endforeach;
427
428 if (sizeof($meta)>0) :
f74e041 Mike Jolley Renamed textdomain Closes #444.
mikejolley authored
429 echo '<h2>'.__('Order information', 'woocommerce').'</h2>';
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
430 foreach ($meta as $key=>$value) :
431 echo '<p><strong>'.$key.':</strong> '.$value.'</p>';
432 endforeach;
433 endif;
434 }
435
436 /**
437 * Customer new account welcome email
438 **/
439 function customer_new_account( $user_id, $plaintext_pass ) {
440
441 if (!$user_id || !$plaintext_pass) return;
442
443 $user = new WP_User($user_id);
444
445 $user_login = stripslashes($user->user_login);
446 $user_email = stripslashes($user->user_email);
447 $user_pass = $plaintext_pass;
448
449 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
450
f74e041 Mike Jolley Renamed textdomain Closes #444.
mikejolley authored
451 $subject = apply_filters( 'woocommerce_email_subject_customer_new_account', sprintf( __( 'Your account on %s', 'woocommerce'), $blogname ), $user );
ab7953a Mike Jolley Don't mail the password
mikejolley authored
452 $email_heading = sprintf( __( 'Welcome to %s', 'woocommerce'), $blogname );
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
453
454 // Buffer
455 ob_start();
456
457 // Get mail template
3b5272e Mike Jolley Improved template loader
mikejolley authored
458 woocommerce_get_template('emails/customer-new-account.php', array(
459 'user_login' => $user_login,
460 'user_pass' => $user_pass,
461 'blogname' => $blogname,
462 'email_heading' => $email_heading
463 ));
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
464
465 // Get contents
466 $message = ob_get_clean();
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
467
468 // CC, BCC, additional headers
26f47e8 Mike Jolley More consistent email headers/attachments
mikejolley authored
469 $headers = apply_filters('woocommerce_email_headers', '', 'customer_new_account');
470
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
471 // Attachments
26f47e8 Mike Jolley More consistent email headers/attachments
mikejolley authored
472 $attachments = apply_filters('woocommerce_email_attachments', '', 'customer_new_account');
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
473
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
474 // Send the mail
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
475 $this->send( $user_email, $subject, $message, $headers, $attachments );
733b514 Mike Jolley Moved email functions to classes, and made posts only save once (faster)
mikejolley authored
476 }
477
0836ce0 Mike Jolley Better class names (final)
mikejolley authored
478 }
479
480 /** Depreciated */
481 class woocommerce_email extends WC_Email {
482 public function __construct() {
483 _deprecated_function( 'woocommerce_email', '1.4', 'WC_Email()' );
484 parent::__construct();
485 }
77fceab James Koster Attachments for all mail, additional header data (bcc/cc, etc)
jameskoster authored
486 }
Something went wrong with that request. Please try again.