forked from woocommerce/woocommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwoocommerce_emails.php
248 lines (179 loc) · 6.92 KB
/
woocommerce_emails.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<?php
/**
* WooCommerce Emails
*
* Email handling for important shop events.
*
* @package WooCommerce
* @category Emails
* @author WooThemes
*/
/**
* Mail from name/email
**/
function woocommerce_mail_from_name( $name ) {
return get_option('woocommerce_email_from_name');
}
function woocommerce_mail_from( $email ) {
return get_option('woocommerce_email_from_address');
}
/**
* HTML emails from WooCommerce
**/
function woocommerce_mail( $to, $subject, $message ) {
add_filter( 'wp_mail_from', 'woocommerce_mail_from' );
add_filter( 'wp_mail_from_name', 'woocommerce_mail_from_name' );
add_filter( 'wp_mail_content_type', 'woocommerce_email_content_type' );
// Send the mail
wp_mail( $to, $subject, $message );
// Unhook
remove_filter( 'wp_mail_from', 'woocommerce_mail_from' );
remove_filter( 'wp_mail_from_name', 'woocommerce_mail_from_name' );
remove_filter( 'wp_mail_content_type', 'woocommerce_email_content_type' );
}
/**
* Email Header
**/
add_action('woocommerce_email_header', 'woocommerce_email_header');
function woocommerce_email_header() {
woocommerce_get_template('emails/email_header.php', false);
}
/**
* Email Footer
**/
add_action('woocommerce_email_footer', 'woocommerce_email_footer');
function woocommerce_email_footer() {
woocommerce_get_template('emails/email_footer.php', false);
}
/**
* HTML email type
**/
function woocommerce_email_content_type($content_type){
return 'text/html';
}
/**
* Fix recieve password mail links
**/
function woocommerce_retrieve_password_message($content){
return htmlspecialchars($content);
}
/**
* Hooks for emails
**/
add_action('woocommerce_low_stock_notification', 'woocommerce_low_stock_notification');
add_action('woocommerce_no_stock_notification', 'woocommerce_no_stock_notification');
add_action('woocommerce_product_on_backorder_notification', 'woocommerce_product_on_backorder_notification', 1, 2);
/**
* New order notification email template
**/
add_action('woocommerce_order_status_pending_to_processing', 'woocommerce_new_order_notification');
add_action('woocommerce_order_status_pending_to_completed', 'woocommerce_new_order_notification');
add_action('woocommerce_order_status_pending_to_on-hold', 'woocommerce_new_order_notification');
add_action('woocommerce_order_status_failed_to_processing', 'woocommerce_new_order_notification');
add_action('woocommerce_order_status_failed_to_completed', 'woocommerce_new_order_notification');
function woocommerce_new_order_notification( $id ) {
global $order_id, $email_heading;
$order_id = $id;
$email_heading = __('New Customer Order', 'woothemes');
$subject = sprintf(__('[%s] New Customer Order (# %s)', 'woothemes'), get_bloginfo('name'), $order_id);
// Buffer
ob_start();
// Get mail template
woocommerce_get_template('emails/new_order.php', false);
// Get contents
$message = ob_get_clean();
// Send the mail
woocommerce_mail( get_option('admin_email'), $subject, $message );
}
/**
* Processing order notification email template
**/
add_action('woocommerce_order_status_pending_to_processing', 'woocommerce_processing_order_customer_notification');
add_action('woocommerce_order_status_pending_to_on-hold', 'woocommerce_processing_order_customer_notification');
function woocommerce_processing_order_customer_notification( $id ) {
global $order_id, $email_heading;
$order_id = $id;
$order = &new woocommerce_order( $order_id );
$email_heading = __('Order Received', 'woothemes');
$subject = sprintf(__('[%s] Order Received', 'woothemes'), get_bloginfo('name'));
// Buffer
ob_start();
// Get mail template
woocommerce_get_template('emails/customer_processing_order.php', false);
// Get contents
$message = ob_get_clean();
// Send the mail
woocommerce_mail( $order->billing_email, $subject, $message );
}
/**
* Completed order notification email template - this one includes download links for downloadable products
**/
add_action('woocommerce_order_status_completed', 'woocommerce_completed_order_customer_notification');
function woocommerce_completed_order_customer_notification( $id ) {
global $order_id, $email_heading;
$order_id = $id;
$order = &new woocommerce_order( $order_id );
if ($order->has_downloadable_item()) :
$email_heading = __('[%s] Order Complete/Download Links', 'woothemes');
else :
$email_heading = __('[%s] Order Complete', 'woothemes');
endif;
$email_heading = apply_filters('woocommerce_completed_order_customer_notification_subject', $email_heading);
$subject = sprintf($email_heading, get_bloginfo('name'));
// Buffer
ob_start();
// Get mail template
woocommerce_get_template('emails/customer_completed_order.php', false);
// Get contents
$message = ob_get_clean();
// Send the mail
woocommerce_mail( $order->billing_email, $subject, $message );
}
/**
* Pay for order notification email template - this one includes a payment link
**/
function woocommerce_pay_for_order_customer_notification( $id ) {
global $order_id, $email_heading;
$order_id = $id;
$order = &new woocommerce_order( $order_id );
$email_heading = __('Pay for Order', 'woothemes');
$subject = sprintf(__('[%s] Pay for Order', 'woothemes'), get_bloginfo('name'));
// Buffer
ob_start();
// Get mail template
woocommerce_get_template('emails/customer_pay_for_order.php', false);
// Get contents
$message = ob_get_clean();
// Send the mail
woocommerce_mail( $order->billing_email, $subject, $message );
}
/**
* Low stock notification email
**/
function woocommerce_low_stock_notification( $product ) {
$_product = &new woocommerce_product($product);
$subject = '[' . get_bloginfo('name') . '] ' . __('Product low in stock', 'woothemes');
$message = '#' . $_product->id .' '. $_product->get_title() . ' ('. $_product->sku.') ' . __('is low in stock.', 'woothemes');
$message = wordwrap( html_entity_decode( strip_tags( $message ) ), 70 );
wp_mail( get_option('admin_email'), $subject, $message );
}
/**
* No stock notification email
**/
function woocommerce_no_stock_notification( $product ) {
$_product = &new woocommerce_product($product);
$subject = '[' . get_bloginfo('name') . '] ' . __('Product out of stock', 'woothemes');
$message = '#' . $_product->id .' '. $_product->get_title() . ' ('. $_product->sku.') ' . __('is out of stock.', 'woothemes');
$message = wordwrap( html_entity_decode( strip_tags( $message ) ), 70 );
wp_mail( get_option('admin_email'), $subject, $message );
}
/**
* Backorder notification email
**/
function woocommerce_product_on_backorder_notification( $product, $amount ) {
$_product = &new woocommerce_product($product);
$subject = '[' . get_bloginfo('name') . '] ' . __('Product Backorder', 'woothemes');
$message = $amount . __(' units of #', 'woothemes') . $_product->id .' '. $_product->get_title() . ' ('. $_product->sku.') ' . __('have been backordered.', 'woothemes');
$message = wordwrap( html_entity_decode( strip_tags( $message ) ), 70 );
wp_mail( get_option('admin_email'), $subject, $message );
}