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0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / class-wc-emails.php
woocommerce / includes Last commit date
abstracts 9 years ago admin 9 years ago api 9 years ago cli 9 years ago data-stores 9 years ago emails 9 years ago gateways 9 years ago interfaces 9 years ago legacy 9 years ago libraries 9 years ago log-handlers 9 years ago payment-tokens 9 years ago shipping 9 years ago shortcodes 9 years ago theme-support 9 years ago vendor 9 years ago walkers 9 years ago widgets 9 years ago class-wc-ajax.php 9 years ago class-wc-api.php 9 years ago class-wc-auth.php 9 years ago class-wc-autoloader.php 9 years ago class-wc-background-emailer.php 9 years ago class-wc-background-updater.php 9 years ago class-wc-breadcrumb.php 9 years ago class-wc-cache-helper.php 9 years ago class-wc-cart.php 9 years ago class-wc-checkout.php 9 years ago class-wc-cli.php 9 years ago class-wc-comments.php 9 years ago class-wc-countries.php 9 years ago class-wc-coupon.php 9 years ago class-wc-customer-download.php 9 years ago class-wc-customer.php 9 years ago class-wc-data-exception.php 9 years ago class-wc-data-store.php 9 years ago class-wc-datetime.php 9 years ago class-wc-deprecated-action-hooks.php 9 years ago class-wc-deprecated-filter-hooks.php 9 years ago class-wc-download-handler.php 9 years ago class-wc-emails.php 9 years ago class-wc-embed.php 9 years ago class-wc-form-handler.php 9 years ago class-wc-frontend-scripts.php 9 years ago class-wc-geo-ip.php 9 years ago class-wc-geolocation.php 9 years ago class-wc-https.php 9 years ago class-wc-install.php 9 years ago class-wc-integrations.php 9 years ago class-wc-legacy-api.php 9 years ago class-wc-log-levels.php 9 years ago class-wc-logger.php 9 years ago class-wc-order-factory.php 9 years ago class-wc-order-item-coupon.php 9 years ago class-wc-order-item-fee.php 9 years ago class-wc-order-item-meta.php 9 years ago class-wc-order-item-product.php 9 years ago class-wc-order-item-shipping.php 9 years ago class-wc-order-item-tax.php 9 years ago class-wc-order-item.php 9 years ago class-wc-order-refund.php 9 years ago class-wc-order.php 9 years ago class-wc-payment-gateways.php 9 years ago class-wc-payment-tokens.php 9 years ago class-wc-post-data.php 9 years ago class-wc-post-types.php 9 years ago class-wc-product-attribute.php 9 years ago class-wc-product-download.php 9 years ago class-wc-product-external.php 9 years ago class-wc-product-factory.php 9 years ago class-wc-product-grouped.php 9 years ago class-wc-product-simple.php 9 years ago class-wc-product-variable.php 9 years ago class-wc-product-variation.php 9 years ago class-wc-query.php 9 years ago class-wc-register-wp-admin-settings.php 9 years ago class-wc-session-handler.php 9 years ago class-wc-shipping-rate.php 9 years ago class-wc-shipping-zone.php 9 years ago class-wc-shipping-zones.php 9 years ago class-wc-shipping.php 9 years ago class-wc-shortcodes.php 9 years ago class-wc-structured-data.php 9 years ago class-wc-tax.php 9 years ago class-wc-template-loader.php 9 years ago class-wc-tracker.php 9 years ago class-wc-validation.php 9 years ago class-wc-webhook.php 9 years ago wc-account-functions.php 9 years ago wc-attribute-functions.php 9 years ago wc-cart-functions.php 9 years ago wc-conditional-functions.php 9 years ago wc-core-functions.php 9 years ago wc-coupon-functions.php 9 years ago wc-deprecated-functions.php 9 years ago wc-formatting-functions.php 9 years ago wc-notice-functions.php 9 years ago wc-order-functions.php 9 years ago wc-order-item-functions.php 9 years ago wc-page-functions.php 9 years ago wc-product-functions.php 9 years ago wc-rest-functions.php 9 years ago wc-stock-functions.php 9 years ago wc-template-functions.php 9 years ago wc-template-hooks.php 9 years ago wc-term-functions.php 9 years ago wc-update-functions.php 9 years ago wc-user-functions.php 9 years ago wc-webhook-functions.php 9 years ago wc-widget-functions.php 9 years ago
class-wc-emails.php
538 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly
5 }
6
7 /**
8 * Transactional Emails Controller
9 *
10 * WooCommerce Emails Class which handles the sending on transactional emails and email templates. This class loads in available emails.
11 *
12 * @class WC_Emails
13 * @version 2.3.0
14 * @package WooCommerce/Classes/Emails
15 * @category Class
16 * @author WooThemes
17 */
18 class WC_Emails {
19
20 /** @var array Array of email notification classes */
21 public $emails;
22
23 /** @var WC_Emails The single instance of the class */
24 protected static $_instance = null;
25
26 /**
27 * Background emailer class.
28 */
29 protected static $background_emailer;
30
31 /**
32 * Main WC_Emails Instance.
33 *
34 * Ensures only one instance of WC_Emails is loaded or can be loaded.
35 *
36 * @since 2.1
37 * @static
38 * @return WC_Emails Main instance
39 */
40 public static function instance() {
41 if ( is_null( self::$_instance ) ) {
42 self::$_instance = new self();
43 }
44 return self::$_instance;
45 }
46
47 /**
48 * Cloning is forbidden.
49 *
50 * @since 2.1
51 */
52 public function __clone() {
53 wc_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woocommerce' ), '2.1' );
54 }
55
56 /**
57 * Unserializing instances of this class is forbidden.
58 *
59 * @since 2.1
60 */
61 public function __wakeup() {
62 wc_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woocommerce' ), '2.1' );
63 }
64
65 /**
66 * Hook in all transactional emails.
67 */
68 public static function init_transactional_emails() {
69 $email_actions = apply_filters( 'woocommerce_email_actions', array(
70 'woocommerce_low_stock',
71 'woocommerce_no_stock',
72 'woocommerce_product_on_backorder',
73 'woocommerce_order_status_pending_to_processing',
74 'woocommerce_order_status_pending_to_completed',
75 'woocommerce_order_status_pending_to_cancelled',
76 'woocommerce_order_status_pending_to_failed',
77 'woocommerce_order_status_pending_to_on-hold',
78 'woocommerce_order_status_failed_to_processing',
79 'woocommerce_order_status_failed_to_completed',
80 'woocommerce_order_status_failed_to_on-hold',
81 'woocommerce_order_status_on-hold_to_processing',
82 'woocommerce_order_status_on-hold_to_cancelled',
83 'woocommerce_order_status_on-hold_to_failed',
84 'woocommerce_order_status_completed',
85 'woocommerce_order_fully_refunded',
86 'woocommerce_order_partially_refunded',
87 'woocommerce_new_customer_note',
88 'woocommerce_created_customer',
89 ) );
90
91 if ( apply_filters( 'woocommerce_defer_transactional_emails', true ) ) {
92 self::$background_emailer = new WC_Background_Emailer();
93
94 foreach ( $email_actions as $action ) {
95 add_action( $action, array( __CLASS__, 'queue_transactional_email' ), 10, 10 );
96 }
97 } else {
98 foreach ( $email_actions as $action ) {
99 add_action( $action, array( __CLASS__, 'send_transactional_email' ), 10, 10 );
100 }
101 }
102 }
103
104 /**
105 * Queue transactional email so it's not sent in current request.
106 */
107 public static function queue_transactional_email() {
108 self::$background_emailer->push_to_queue( array(
109 'filter' => current_filter(),
110 'args' => func_get_args(),
111 ) );
112 }
113
114 /**
115 * Init the mailer instance and call the notifications for the current filter.
116 *
117 * @internal
118 *
119 * @param string $filter Filter name.
120 * @param array $args Email args (default: []).
121 */
122 public static function send_queued_transactional_email( $filter = '', $args = array() ) {
123 if ( apply_filters( 'woocommerce_allow_send_queued_transactional_email', true, $filter, $args ) ) {
124 self::instance(); // Init self so emails exist.
125
126 // Ensure gateways are loaded in case they need to insert data into the emails.
127 WC()->payment_gateways();
128 WC()->shipping();
129
130 do_action_ref_array( $filter . '_notification', $args );
131 }
132 }
133
134 /**
135 * Init the mailer instance and call the notifications for the current filter.
136 *
137 * @internal
138 *
139 * @param array $args Email args (default: []).
140 */
141 public static function send_transactional_email( $args = array() ) {
142 $args = func_get_args();
143 self::instance(); // Init self so emails exist.
144 do_action_ref_array( current_filter() . '_notification', $args );
145 }
146
147 /**
148 * Constructor for the email class hooks in all emails that can be sent.
149 *
150 */
151 public function __construct() {
152 $this->init();
153
154 // Email Header, Footer and content hooks
155 add_action( 'woocommerce_email_header', array( $this, 'email_header' ) );
156 add_action( 'woocommerce_email_footer', array( $this, 'email_footer' ) );
157 add_action( 'woocommerce_email_order_details', array( $this, 'order_details' ), 10, 4 );
158 add_action( 'woocommerce_email_order_meta', array( $this, 'order_meta' ), 10, 3 );
159 add_action( 'woocommerce_email_customer_details', array( $this, 'customer_details' ), 10, 3 );
160 add_action( 'woocommerce_email_customer_details', array( $this, 'email_addresses' ), 20, 3 );
161
162 // Hooks for sending emails during store events
163 add_action( 'woocommerce_low_stock_notification', array( $this, 'low_stock' ) );
164 add_action( 'woocommerce_no_stock_notification', array( $this, 'no_stock' ) );
165 add_action( 'woocommerce_product_on_backorder_notification', array( $this, 'backorder' ) );
166 add_action( 'woocommerce_created_customer_notification', array( $this, 'customer_new_account' ), 10, 3 );
167
168 // Let 3rd parties unhook the above via this hook
169 do_action( 'woocommerce_email', $this );
170 }
171
172 /**
173 * Init email classes.
174 */
175 public function init() {
176 // Include email classes
177 include_once( dirname( __FILE__ ) . '/emails/class-wc-email.php' );
178
179 $this->emails['WC_Email_New_Order'] = include( 'emails/class-wc-email-new-order.php' );
180 $this->emails['WC_Email_Cancelled_Order'] = include( 'emails/class-wc-email-cancelled-order.php' );
181 $this->emails['WC_Email_Failed_Order'] = include( 'emails/class-wc-email-failed-order.php' );
182 $this->emails['WC_Email_Customer_On_Hold_Order'] = include( 'emails/class-wc-email-customer-on-hold-order.php' );
183 $this->emails['WC_Email_Customer_Processing_Order'] = include( 'emails/class-wc-email-customer-processing-order.php' );
184 $this->emails['WC_Email_Customer_Completed_Order'] = include( 'emails/class-wc-email-customer-completed-order.php' );
185 $this->emails['WC_Email_Customer_Refunded_Order'] = include( 'emails/class-wc-email-customer-refunded-order.php' );
186 $this->emails['WC_Email_Customer_Invoice'] = include( 'emails/class-wc-email-customer-invoice.php' );
187 $this->emails['WC_Email_Customer_Note'] = include( 'emails/class-wc-email-customer-note.php' );
188 $this->emails['WC_Email_Customer_Reset_Password'] = include( 'emails/class-wc-email-customer-reset-password.php' );
189 $this->emails['WC_Email_Customer_New_Account'] = include( 'emails/class-wc-email-customer-new-account.php' );
190
191 $this->emails = apply_filters( 'woocommerce_email_classes', $this->emails );
192
193 // include css inliner
194 if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
195 include_once( dirname( __FILE__ ) . '/libraries/class-emogrifier.php' );
196 }
197 }
198
199 /**
200 * Return the email classes - used in admin to load settings.
201 *
202 * @return array
203 */
204 public function get_emails() {
205 return $this->emails;
206 }
207
208 /**
209 * Get from name for email.
210 *
211 * @return string
212 */
213 public function get_from_name() {
214 return wp_specialchars_decode( get_option( 'woocommerce_email_from_name' ), ENT_QUOTES );
215 }
216
217 /**
218 * Get from email address.
219 *
220 * @return string
221 */
222 public function get_from_address() {
223 return sanitize_email( get_option( 'woocommerce_email_from_address' ) );
224 }
225
226 /**
227 * Get the email header.
228 *
229 * @param mixed $email_heading heading for the email
230 */
231 public function email_header( $email_heading ) {
232 wc_get_template( 'emails/email-header.php', array( 'email_heading' => $email_heading ) );
233 }
234
235 /**
236 * Get the email footer.
237 */
238 public function email_footer() {
239 wc_get_template( 'emails/email-footer.php' );
240 }
241
242 /**
243 * Wraps a message in the woocommerce mail template.
244 *
245 * @param mixed $email_heading
246 * @param string $message
247 * @return string
248 */
249 public function wrap_message( $email_heading, $message, $plain_text = false ) {
250 // Buffer
251 ob_start();
252
253 do_action( 'woocommerce_email_header', $email_heading );
254
255 echo wpautop( wptexturize( $message ) );
256
257 do_action( 'woocommerce_email_footer' );
258
259 // Get contents
260 $message = ob_get_clean();
261
262 return $message;
263 }
264
265 /**
266 * Send the email.
267 *
268 * @param mixed $to
269 * @param mixed $subject
270 * @param mixed $message
271 * @param string $headers (default: "Content-Type: text/html\r\n")
272 * @param string $attachments (default: "")
273 * @return bool
274 */
275 public function send( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = "" ) {
276 // Send
277 $email = new WC_Email();
278 return $email->send( $to, $subject, $message, $headers, $attachments );
279 }
280
281 /**
282 * Prepare and send the customer invoice email on demand.
283 */
284 public function customer_invoice( $order ) {
285 $email = $this->emails['WC_Email_Customer_Invoice'];
286
287 if ( ! is_object( $order ) ) {
288 $order = wc_get_order( absint( $order ) );
289 }
290
291 $email->trigger( $order->get_id(), $order );
292 }
293
294 /**
295 * Customer new account welcome email.
296 *
297 * @param int $customer_id
298 * @param array $new_customer_data
299 */
300 public function customer_new_account( $customer_id, $new_customer_data = array(), $password_generated = false ) {
301 if ( ! $customer_id ) {
302 return;
303 }
304
305 $user_pass = ! empty( $new_customer_data['user_pass'] ) ? $new_customer_data['user_pass'] : '';
306
307 $email = $this->emails['WC_Email_Customer_New_Account'];
308 $email->trigger( $customer_id, $user_pass, $password_generated );
309 }
310
311 /**
312 * Show the order details table
313 */
314 public function order_details( $order, $sent_to_admin = false, $plain_text = false, $email = '' ) {
315 if ( $plain_text ) {
316 wc_get_template( 'emails/plain/email-order-details.php', array( 'order' => $order, 'sent_to_admin' => $sent_to_admin, 'plain_text' => $plain_text, 'email' => $email ) );
317 } else {
318 wc_get_template( 'emails/email-order-details.php', array( 'order' => $order, 'sent_to_admin' => $sent_to_admin, 'plain_text' => $plain_text, 'email' => $email ) );
319 }
320 }
321
322 /**
323 * Add order meta to email templates.
324 *
325 * @param mixed $order
326 * @param bool $sent_to_admin (default: false)
327 * @param bool $plain_text (default: false)
328 * @return string
329 */
330 public function order_meta( $order, $sent_to_admin = false, $plain_text = false ) {
331 $fields = apply_filters( 'woocommerce_email_order_meta_fields', array(), $sent_to_admin, $order );
332
333 /**
334 * Deprecated woocommerce_email_order_meta_keys filter.
335 *
336 * @since 2.3.0
337 */
338 $_fields = apply_filters( 'woocommerce_email_order_meta_keys', array(), $sent_to_admin );
339
340 if ( $_fields ) {
341 foreach ( $_fields as $key => $field ) {
342 if ( is_numeric( $key ) ) {
343 $key = $field;
344 }
345
346 $fields[ $key ] = array(
347 'label' => wptexturize( $key ),
348 'value' => wptexturize( get_post_meta( $order->get_id(), $field, true ) ),
349 );
350 }
351 }
352
353 if ( $fields ) {
354
355 if ( $plain_text ) {
356
357 foreach ( $fields as $field ) {
358 if ( isset( $field['label'] ) && isset( $field['value'] ) && $field['value'] ) {
359 echo $field['label'] . ': ' . $field['value'] . "\n";
360 }
361 }
362 } else {
363
364 foreach ( $fields as $field ) {
365 if ( isset( $field['label'] ) && isset( $field['value'] ) && $field['value'] ) {
366 echo '<p><strong>' . $field['label'] . ':</strong> ' . $field['value'] . '</p>';
367 }
368 }
369 }
370 }
371 }
372
373 /**
374 * Is customer detail field valid?
375 * @param array $field
376 * @return boolean
377 */
378 public function customer_detail_field_is_valid( $field ) {
379 return isset( $field['label'] ) && ! empty( $field['value'] );
380 }
381
382 /**
383 * Add customer details to email templates.
384 *
385 * @param WC_Order $order
386 * @param bool $sent_to_admin (default: false)
387 * @param bool $plain_text (default: false)
388 * @return string
389 */
390 public function customer_details( $order, $sent_to_admin = false, $plain_text = false ) {
391 if ( ! is_a( $order, 'WC_Order' ) ) {
392 return;
393 }
394 $fields = array();
395
396 if ( $order->get_customer_note() ) {
397 $fields['customer_note'] = array(
398 'label' => __( 'Note', 'woocommerce' ),
399 'value' => wptexturize( $order->get_customer_note() ),
400 );
401 }
402
403 if ( $order->get_billing_email() ) {
404 $fields['billing_email'] = array(
405 'label' => __( 'Email address', 'woocommerce' ),
406 'value' => wptexturize( $order->get_billing_email() ),
407 );
408 }
409
410 if ( $order->get_billing_phone() ) {
411 $fields['billing_phone'] = array(
412 'label' => __( 'Phone', 'woocommerce' ),
413 'value' => wptexturize( $order->get_billing_phone() ),
414 );
415 }
416
417 $fields = array_filter( apply_filters( 'woocommerce_email_customer_details_fields', $fields, $sent_to_admin, $order ), array( $this, 'customer_detail_field_is_valid' ) );
418
419 if ( $plain_text ) {
420 wc_get_template( 'emails/plain/email-customer-details.php', array( 'fields' => $fields ) );
421 } else {
422 wc_get_template( 'emails/email-customer-details.php', array( 'fields' => $fields ) );
423 }
424 }
425
426 /**
427 * Get the email addresses.
428 */
429 public function email_addresses( $order, $sent_to_admin = false, $plain_text = false ) {
430 if ( ! is_a( $order, 'WC_Order' ) ) {
431 return;
432 }
433 if ( $plain_text ) {
434 wc_get_template( 'emails/plain/email-addresses.php', array( 'order' => $order ) );
435 } else {
436 wc_get_template( 'emails/email-addresses.php', array( 'order' => $order ) );
437 }
438 }
439
440 /**
441 * Get blog name formatted for emails.
442 * @return string
443 */
444 private function get_blogname() {
445 return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
446 }
447
448 /**
449 * Low stock notification email.
450 *
451 * @param WC_Product $product
452 */
453 public function low_stock( $product ) {
454 $subject = sprintf( '[%s] %s', $this->get_blogname(), __( 'Product low in stock', 'woocommerce' ) );
455 /* translators: 1: product name 2: items in stock */
456 $message = sprintf(
457 __( '%1$s is low in stock. There are %2$d left.', 'woocommerce' ),
458 html_entity_decode( strip_tags( $product->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ),
459 html_entity_decode( strip_tags( $product->get_stock_quantity() ) )
460 );
461
462 wp_mail(
463 apply_filters( 'woocommerce_email_recipient_low_stock', get_option( 'woocommerce_stock_email_recipient' ), $product ),
464 apply_filters( 'woocommerce_email_subject_low_stock', $subject, $product ),
465 apply_filters( 'woocommerce_email_content_low_stock', $message, $product ),
466 apply_filters( 'woocommerce_email_headers', '', 'low_stock', $product ),
467 apply_filters( 'woocommerce_email_attachments', array(), 'low_stock', $product )
468 );
469 }
470
471 /**
472 * No stock notification email.
473 *
474 * @param WC_Product $product
475 */
476 public function no_stock( $product ) {
477 $subject = sprintf( '[%s] %s', $this->get_blogname(), __( 'Product out of stock', 'woocommerce' ) );
478 /* translators: %s: product name */
479 $message = sprintf( __( '%s is out of stock.', 'woocommerce' ), html_entity_decode( strip_tags( $product->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ) );
480
481 wp_mail(
482 apply_filters( 'woocommerce_email_recipient_no_stock', get_option( 'woocommerce_stock_email_recipient' ), $product ),
483 apply_filters( 'woocommerce_email_subject_no_stock', $subject, $product ),
484 apply_filters( 'woocommerce_email_content_no_stock', $message, $product ),
485 apply_filters( 'woocommerce_email_headers', '', 'no_stock', $product ),
486 apply_filters( 'woocommerce_email_attachments', array(), 'no_stock', $product )
487 );
488 }
489
490 /**
491 * Backorder notification email.
492 *
493 * @param array $args
494 */
495 public function backorder( $args ) {
496 $args = wp_parse_args( $args, array(
497 'product' => '',
498 'quantity' => '',
499 'order_id' => '',
500 ) );
501
502 extract( $args );
503
504 if ( ! $product || ! $quantity || ! ( $order = wc_get_order( $order_id ) ) ) {
505 return;
506 }
507
508 $subject = sprintf( '[%s] %s', $this->get_blogname(), __( 'Product backorder', 'woocommerce' ) );
509 $message = sprintf( __( '%1$s units of %2$s have been backordered in order #%3$s.', 'woocommerce' ), $quantity, html_entity_decode( strip_tags( $product->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ), $order->get_order_number() );
510
511 wp_mail(
512 apply_filters( 'woocommerce_email_recipient_backorder', get_option( 'woocommerce_stock_email_recipient' ), $args ),
513 apply_filters( 'woocommerce_email_subject_backorder', $subject, $args ),
514 apply_filters( 'woocommerce_email_content_backorder', $message, $args ),
515 apply_filters( 'woocommerce_email_headers', '', 'backorder', $args ),
516 apply_filters( 'woocommerce_email_attachments', array(), 'backorder', $args )
517 );
518 }
519
520 /**
521 * Adds Schema.org markup for order in JSON-LD format.
522 *
523 * @deprecated 3.0.0
524 * @see WC_Structured_Data::generate_order_data()
525 *
526 * @since 2.6.0
527 * @param mixed $order
528 * @param bool $sent_to_admin (default: false)
529 * @param bool $plain_text (default: false)
530 */
531 public function order_schema_markup( $order, $sent_to_admin = false, $plain_text = false ) {
532 wc_deprecated_function( 'WC_Emails::order_schema_markup', '3.0', 'WC_Structured_Data::generate_order_data' );
533
534 WC()->structured_data->generate_order_data( $order, $sent_to_admin, $plain_text );
535 WC()->structured_data->output_structured_data();
536 }
537 }
538