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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 1 year ago admin 1 year ago blocks 1 year ago cli 1 year ago customizer 1 year ago data-stores 1 year ago emails 1 year ago export 1 year ago gateways 1 year ago import 1 year ago integrations 1 year ago interfaces 1 year ago legacy 1 year ago libraries 1 year ago log-handlers 1 year ago payment-tokens 1 year ago queue 1 year ago react-admin 1 year ago rest-api 1 year ago shipping 1 year ago shortcodes 1 year ago theme-support 1 year ago tracks 1 year ago traits 1 year ago walkers 1 year ago wccom-site 1 year ago widgets 1 year ago class-wc-ajax.php 1 year ago class-wc-api.php 1 year ago class-wc-auth.php 1 year ago class-wc-autoloader.php 1 year ago class-wc-background-emailer.php 1 year ago class-wc-background-updater.php 1 year ago class-wc-breadcrumb.php 1 year ago class-wc-cache-helper.php 1 year ago class-wc-cart-fees.php 1 year ago class-wc-cart-session.php 1 year ago class-wc-cart-totals.php 1 year ago class-wc-cart.php 1 year ago class-wc-checkout.php 1 year ago class-wc-cli.php 1 year ago class-wc-comments.php 1 year ago class-wc-countries.php 1 year ago class-wc-coupon.php 1 year ago class-wc-customer-download-log.php 1 year ago class-wc-customer-download.php 1 year ago class-wc-customer.php 1 year ago class-wc-data-exception.php 1 year ago class-wc-data-store.php 1 year ago class-wc-datetime.php 1 year ago class-wc-deprecated-action-hooks.php 1 year ago class-wc-deprecated-filter-hooks.php 1 year ago class-wc-discounts.php 1 year ago class-wc-download-handler.php 1 year ago class-wc-emails.php 1 year ago class-wc-embed.php 1 year ago class-wc-form-handler.php 1 year ago class-wc-frontend-scripts.php 1 year ago class-wc-geo-ip.php 1 year ago class-wc-geolite-integration.php 1 year ago class-wc-geolocation.php 1 year ago class-wc-https.php 1 year ago class-wc-install.php 1 year ago class-wc-integrations.php 1 year ago class-wc-log-levels.php 1 year ago class-wc-logger.php 1 year ago class-wc-meta-data.php 1 year ago class-wc-order-factory.php 1 year ago class-wc-order-item-coupon.php 1 year ago class-wc-order-item-fee.php 1 year ago class-wc-order-item-meta.php 1 year ago class-wc-order-item-product.php 1 year ago class-wc-order-item-shipping.php 1 year ago class-wc-order-item-tax.php 1 year ago class-wc-order-item.php 1 year ago class-wc-order-query.php 1 year ago class-wc-order-refund.php 1 year ago class-wc-order.php 1 year ago class-wc-payment-gateways.php 1 year ago class-wc-payment-tokens.php 1 year ago class-wc-post-data.php 1 year ago class-wc-post-types.php 1 year ago class-wc-privacy-background-process.php 1 year ago class-wc-privacy-erasers.php 1 year ago class-wc-privacy-exporters.php 1 year ago class-wc-privacy.php 1 year ago class-wc-product-attribute.php 1 year ago class-wc-product-download.php 1 year ago class-wc-product-external.php 1 year ago class-wc-product-factory.php 1 year ago class-wc-product-grouped.php 1 year ago class-wc-product-query.php 1 year ago class-wc-product-simple.php 1 year ago class-wc-product-variable.php 1 year ago class-wc-product-variation.php 1 year ago class-wc-query.php 1 year ago class-wc-rate-limiter.php 1 year ago class-wc-regenerate-images-request.php 1 year ago class-wc-regenerate-images.php 1 year ago class-wc-register-wp-admin-settings.php 1 year ago class-wc-rest-authentication.php 1 year ago class-wc-rest-exception.php 1 year ago class-wc-session-handler.php 1 year ago class-wc-shipping-rate.php 1 year ago class-wc-shipping-zone.php 1 year ago class-wc-shipping-zones.php 1 year ago class-wc-shipping.php 1 year ago class-wc-shortcodes.php 1 year ago class-wc-structured-data.php 1 year ago class-wc-tax.php 1 year ago class-wc-template-loader.php 1 year ago class-wc-tracker.php 1 year ago class-wc-validation.php 1 year ago class-wc-webhook.php 1 year ago class-woocommerce.php 1 year ago wc-account-functions.php 1 year ago wc-attribute-functions.php 1 year ago wc-cart-functions.php 1 year ago wc-conditional-functions.php 1 year ago wc-core-functions.php 1 year ago wc-coupon-functions.php 1 year ago wc-deprecated-functions.php 1 year ago wc-formatting-functions.php 1 year ago wc-notice-functions.php 1 year ago wc-order-functions.php 1 year ago wc-order-item-functions.php 1 year ago wc-page-functions.php 1 year ago wc-product-functions.php 1 year ago wc-rest-functions.php 1 year ago wc-stock-functions.php 1 year ago wc-template-functions.php 1 year ago wc-template-hooks.php 1 year ago wc-term-functions.php 1 year ago wc-update-functions.php 1 year ago wc-user-functions.php 1 year ago wc-webhook-functions.php 1 year ago wc-widget-functions.php 1 year ago
class-wc-emails.php
802 lines
1 <?php
2 /**
3 * Transactional Emails Controller
4 *
5 * WooCommerce Emails Class which handles the sending on transactional emails and email templates. This class loads in available emails.
6 *
7 * @package WooCommerce\Classes\Emails
8 * @version 2.3.0
9 */
10
11 use Automattic\Jetpack\Constants;
12 use Automattic\WooCommerce\Blocks\Package;
13 use Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFields;
14
15 defined( 'ABSPATH' ) || exit;
16
17 /**
18 * Emails class.
19 */
20 class WC_Emails {
21
22 /**
23 * Array of email notification classes
24 *
25 * @var WC_Email[]
26 */
27 public $emails = array();
28
29 /**
30 * The single instance of the class
31 *
32 * @var WC_Emails
33 */
34 protected static $_instance = null;
35
36 /**
37 * Background emailer class.
38 *
39 * @var WC_Background_Emailer
40 */
41 protected static $background_emailer = null;
42
43 /**
44 * Main WC_Emails Instance.
45 *
46 * Ensures only one instance of WC_Emails is loaded or can be loaded.
47 *
48 * @since 2.1
49 * @static
50 * @return WC_Emails Main instance
51 */
52 public static function instance() {
53 if ( is_null( self::$_instance ) ) {
54 self::$_instance = new self();
55 }
56 return self::$_instance;
57 }
58
59 /**
60 * Cloning is forbidden.
61 *
62 * @since 2.1
63 */
64 public function __clone() {
65 wc_doing_it_wrong( __FUNCTION__, __( 'Cloning is forbidden.', 'woocommerce' ), '2.1' );
66 }
67
68 /**
69 * Unserializing instances of this class is forbidden.
70 *
71 * @since 2.1
72 */
73 public function __wakeup() {
74 wc_doing_it_wrong( __FUNCTION__, __( 'Unserializing instances of this class is forbidden.', 'woocommerce' ), '2.1' );
75 }
76
77 /**
78 * Hook in all transactional emails.
79 */
80 public static function init_transactional_emails() {
81 $email_actions = apply_filters(
82 'woocommerce_email_actions',
83 array(
84 'woocommerce_low_stock',
85 'woocommerce_no_stock',
86 'woocommerce_product_on_backorder',
87 'woocommerce_order_status_pending_to_processing',
88 'woocommerce_order_status_pending_to_completed',
89 'woocommerce_order_status_processing_to_cancelled',
90 'woocommerce_order_status_pending_to_failed',
91 'woocommerce_order_status_pending_to_on-hold',
92 'woocommerce_order_status_failed_to_processing',
93 'woocommerce_order_status_failed_to_completed',
94 'woocommerce_order_status_failed_to_on-hold',
95 'woocommerce_order_status_cancelled_to_processing',
96 'woocommerce_order_status_cancelled_to_completed',
97 'woocommerce_order_status_cancelled_to_on-hold',
98 'woocommerce_order_status_on-hold_to_processing',
99 'woocommerce_order_status_on-hold_to_cancelled',
100 'woocommerce_order_status_on-hold_to_failed',
101 'woocommerce_order_status_completed',
102 'woocommerce_order_fully_refunded',
103 'woocommerce_order_partially_refunded',
104 'woocommerce_new_customer_note',
105 'woocommerce_created_customer',
106 )
107 );
108
109 if ( apply_filters( 'woocommerce_defer_transactional_emails', false ) ) {
110 self::$background_emailer = new WC_Background_Emailer();
111
112 foreach ( $email_actions as $action ) {
113 add_action( $action, array( __CLASS__, 'queue_transactional_email' ), 10, 10 );
114 }
115 } else {
116 foreach ( $email_actions as $action ) {
117 add_action( $action, array( __CLASS__, 'send_transactional_email' ), 10, 10 );
118 }
119 }
120 }
121
122 /**
123 * Queues transactional email so it's not sent in current request if enabled,
124 * otherwise falls back to send now.
125 *
126 * @param mixed ...$args Optional arguments.
127 */
128 public static function queue_transactional_email( ...$args ) {
129 if ( is_a( self::$background_emailer, 'WC_Background_Emailer' ) ) {
130 self::$background_emailer->push_to_queue(
131 array(
132 'filter' => current_filter(),
133 'args' => func_get_args(),
134 )
135 );
136 } else {
137 self::send_transactional_email( ...$args );
138 }
139 }
140
141 /**
142 * Init the mailer instance and call the notifications for the current filter.
143 *
144 * @internal
145 *
146 * @param string $filter Filter name.
147 * @param array $args Email args (default: []).
148 */
149 public static function send_queued_transactional_email( $filter = '', $args = array() ) {
150 if ( apply_filters( 'woocommerce_allow_send_queued_transactional_email', true, $filter, $args ) ) {
151 self::instance(); // Init self so emails exist.
152
153 // Ensure gateways are loaded in case they need to insert data into the emails.
154 WC()->payment_gateways();
155 WC()->shipping();
156
157 do_action_ref_array( $filter . '_notification', $args );
158 }
159 }
160
161 /**
162 * Init the mailer instance and call the notifications for the current filter.
163 *
164 * @internal
165 *
166 * @param array $args Email args (default: []).
167 */
168 public static function send_transactional_email( $args = array() ) {
169 try {
170 $args = func_get_args();
171 self::instance(); // Init self so emails exist.
172 do_action_ref_array( current_filter() . '_notification', $args );
173 } catch ( Exception $e ) {
174 $error = 'Transactional email triggered fatal error for callback ' . current_filter();
175 $logger = wc_get_logger();
176 $logger->critical(
177 $error . PHP_EOL,
178 array(
179 'source' => 'transactional-emails',
180 )
181 );
182 if ( Constants::is_true( 'WP_DEBUG' ) ) {
183 trigger_error( $error, E_USER_WARNING ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped, WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
184 }
185 }
186 }
187
188 /**
189 * Constructor for the email class hooks in all emails that can be sent.
190 */
191 public function __construct() {
192 $this->init();
193
194 // Email Header, Footer and content hooks.
195 add_action( 'woocommerce_email_header', array( $this, 'email_header' ) );
196 add_action( 'woocommerce_email_footer', array( $this, 'email_footer' ) );
197 add_action( 'woocommerce_email_order_details', array( $this, 'order_downloads' ), 10, 4 );
198 add_action( 'woocommerce_email_order_details', array( $this, 'order_details' ), 10, 4 );
199 add_action( 'woocommerce_email_order_meta', array( $this, 'order_meta' ), 10, 3 );
200 add_action( 'woocommerce_email_customer_details', array( $this, 'customer_details' ), 10, 3 );
201 add_action( 'woocommerce_email_customer_details', array( $this, 'email_addresses' ), 20, 3 );
202 add_action( 'woocommerce_email_customer_details', array( $this, 'additional_checkout_fields' ), 30, 3 );
203 add_action( 'woocommerce_email_customer_address_section', array( $this, 'additional_address_fields' ), 30, 4 );
204
205 // Hooks for sending emails during store events.
206 add_action( 'woocommerce_low_stock_notification', array( $this, 'low_stock' ) );
207 add_action( 'woocommerce_no_stock_notification', array( $this, 'no_stock' ) );
208 add_action( 'woocommerce_product_on_backorder_notification', array( $this, 'backorder' ) );
209 add_action( 'woocommerce_created_customer_notification', array( $this, 'customer_new_account' ), 10, 3 );
210
211 // Hook for replacing {site_title} in email-footer.
212 add_filter( 'woocommerce_email_footer_text', array( $this, 'replace_placeholders' ) );
213
214 // Let 3rd parties unhook the above via this hook.
215 do_action( 'woocommerce_email', $this );
216 }
217
218 /**
219 * Init email classes.
220 */
221 public function init() {
222 // Include email classes.
223 include_once __DIR__ . '/emails/class-wc-email.php';
224
225 $this->emails['WC_Email_New_Order'] = include __DIR__ . '/emails/class-wc-email-new-order.php';
226 $this->emails['WC_Email_Cancelled_Order'] = include __DIR__ . '/emails/class-wc-email-cancelled-order.php';
227 $this->emails['WC_Email_Failed_Order'] = include __DIR__ . '/emails/class-wc-email-failed-order.php';
228 $this->emails['WC_Email_Customer_On_Hold_Order'] = include __DIR__ . '/emails/class-wc-email-customer-on-hold-order.php';
229 $this->emails['WC_Email_Customer_Processing_Order'] = include __DIR__ . '/emails/class-wc-email-customer-processing-order.php';
230 $this->emails['WC_Email_Customer_Completed_Order'] = include __DIR__ . '/emails/class-wc-email-customer-completed-order.php';
231 $this->emails['WC_Email_Customer_Refunded_Order'] = include __DIR__ . '/emails/class-wc-email-customer-refunded-order.php';
232 $this->emails['WC_Email_Customer_Invoice'] = include __DIR__ . '/emails/class-wc-email-customer-invoice.php';
233 $this->emails['WC_Email_Customer_Note'] = include __DIR__ . '/emails/class-wc-email-customer-note.php';
234 $this->emails['WC_Email_Customer_Reset_Password'] = include __DIR__ . '/emails/class-wc-email-customer-reset-password.php';
235 $this->emails['WC_Email_Customer_New_Account'] = include __DIR__ . '/emails/class-wc-email-customer-new-account.php';
236
237 $this->emails = apply_filters( 'woocommerce_email_classes', $this->emails );
238 }
239
240 /**
241 * Return the email classes - used in admin to load settings.
242 *
243 * @return WC_Email[]
244 */
245 public function get_emails() {
246 return $this->emails;
247 }
248
249 /**
250 * Get from name for email.
251 *
252 * @return string
253 */
254 public function get_from_name() {
255 return wp_specialchars_decode( get_option( 'woocommerce_email_from_name' ), ENT_QUOTES );
256 }
257
258 /**
259 * Get from email address.
260 *
261 * @return string
262 */
263 public function get_from_address() {
264 return sanitize_email( get_option( 'woocommerce_email_from_address' ) );
265 }
266
267 /**
268 * Get the email header.
269 *
270 * @param mixed $email_heading Heading for the email.
271 */
272 public function email_header( $email_heading ) {
273 wc_get_template( 'emails/email-header.php', array( 'email_heading' => $email_heading ) );
274 }
275
276 /**
277 * Get the email footer.
278 */
279 public function email_footer() {
280 wc_get_template( 'emails/email-footer.php' );
281 }
282
283 /**
284 * Replace placeholder text in strings.
285 *
286 * @since 3.7.0
287 * @param string $string Email footer text.
288 * @return string Email footer text with any replacements done.
289 */
290 public function replace_placeholders( $string ) {
291 $domain = wp_parse_url( home_url(), PHP_URL_HOST );
292
293 return str_replace(
294 array(
295 '{site_title}',
296 '{site_address}',
297 '{site_url}',
298 '{woocommerce}',
299 '{WooCommerce}',
300 ),
301 array(
302 $this->get_blogname(),
303 $domain,
304 $domain,
305 '<a href="https://woocommerce.com">WooCommerce</a>',
306 '<a href="https://woocommerce.com">WooCommerce</a>',
307 ),
308 $string
309 );
310 }
311
312 /**
313 * Filter callback to replace {site_title} in email footer
314 *
315 * @since 3.3.0
316 * @deprecated 3.7.0
317 * @param string $string Email footer text.
318 * @return string Email footer text with any replacements done.
319 */
320 public function email_footer_replace_site_title( $string ) {
321 wc_deprecated_function( 'WC_Emails::email_footer_replace_site_title', '3.7.0', 'WC_Emails::replace_placeholders' );
322 return $this->replace_placeholders( $string );
323 }
324
325 /**
326 * Wraps a message in the woocommerce mail template.
327 *
328 * @param string $email_heading Heading text.
329 * @param string $message Email message.
330 * @param bool $plain_text Set true to send as plain text. Default to false.
331 *
332 * @return string
333 */
334 public function wrap_message( $email_heading, $message, $plain_text = false ) {
335 // Buffer.
336 ob_start();
337
338 do_action( 'woocommerce_email_header', $email_heading, null );
339
340 echo wpautop( wptexturize( $message ) ); // WPCS: XSS ok.
341
342 do_action( 'woocommerce_email_footer', null );
343
344 // Get contents.
345 $message = ob_get_clean();
346
347 return $message;
348 }
349
350 /**
351 * Send the email.
352 *
353 * @param mixed $to Receiver.
354 * @param mixed $subject Email subject.
355 * @param mixed $message Message.
356 * @param string $headers Email headers (default: "Content-Type: text/html\r\n").
357 * @param string $attachments Attachments (default: "").
358 * @return bool
359 */
360 public function send( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = '' ) {
361 // Send.
362 $email = new WC_Email();
363 return $email->send( $to, $subject, $message, $headers, $attachments );
364 }
365
366 /**
367 * Prepare and send the customer invoice email on demand.
368 *
369 * @param int|WC_Order $order Order instance or ID.
370 */
371 public function customer_invoice( $order ) {
372 $email = $this->emails['WC_Email_Customer_Invoice'];
373
374 if ( ! is_object( $order ) ) {
375 $order = wc_get_order( absint( $order ) );
376 }
377
378 $email->trigger( $order->get_id(), $order );
379 }
380
381 /**
382 * Customer new account welcome email.
383 *
384 * @param int $customer_id Customer ID.
385 * @param array $new_customer_data New customer data.
386 * @param bool $password_generated If password is generated.
387 */
388 public function customer_new_account( $customer_id, $new_customer_data = array(), $password_generated = false ) {
389 if ( ! $customer_id ) {
390 return;
391 }
392
393 $user_pass = ! empty( $new_customer_data['user_pass'] ) ? $new_customer_data['user_pass'] : '';
394
395 $email = $this->emails['WC_Email_Customer_New_Account'];
396 $email->trigger( $customer_id, $user_pass, $password_generated );
397 }
398
399 /**
400 * Show the order details table
401 *
402 * @param WC_Order $order Order instance.
403 * @param bool $sent_to_admin If should sent to admin.
404 * @param bool $plain_text If is plain text email.
405 * @param string $email Email address.
406 */
407 public function order_details( $order, $sent_to_admin = false, $plain_text = false, $email = '' ) {
408 if ( $plain_text ) {
409 wc_get_template(
410 'emails/plain/email-order-details.php',
411 array(
412 'order' => $order,
413 'sent_to_admin' => $sent_to_admin,
414 'plain_text' => $plain_text,
415 'email' => $email,
416 )
417 );
418 } else {
419 wc_get_template(
420 'emails/email-order-details.php',
421 array(
422 'order' => $order,
423 'sent_to_admin' => $sent_to_admin,
424 'plain_text' => $plain_text,
425 'email' => $email,
426 )
427 );
428 }
429 }
430
431 /**
432 * Show order downloads in a table.
433 *
434 * @since 3.2.0
435 * @param WC_Order $order Order instance.
436 * @param bool $sent_to_admin If should sent to admin.
437 * @param bool $plain_text If is plain text email.
438 * @param string $email Email address.
439 */
440 public function order_downloads( $order, $sent_to_admin = false, $plain_text = false, $email = '' ) {
441 $show_downloads = $order->has_downloadable_item() && $order->is_download_permitted() && ! $sent_to_admin && ! is_a( $email, 'WC_Email_Customer_Refunded_Order' );
442
443 if ( ! $show_downloads ) {
444 return;
445 }
446
447 $downloads = $order->get_downloadable_items();
448 $columns = apply_filters(
449 'woocommerce_email_downloads_columns',
450 array(
451 'download-product' => __( 'Product', 'woocommerce' ),
452 'download-expires' => __( 'Expires', 'woocommerce' ),
453 'download-file' => __( 'Download', 'woocommerce' ),
454 )
455 );
456
457 if ( $plain_text ) {
458 wc_get_template(
459 'emails/plain/email-downloads.php',
460 array(
461 'order' => $order,
462 'sent_to_admin' => $sent_to_admin,
463 'plain_text' => $plain_text,
464 'email' => $email,
465 'downloads' => $downloads,
466 'columns' => $columns,
467 )
468 );
469 } else {
470 wc_get_template(
471 'emails/email-downloads.php',
472 array(
473 'order' => $order,
474 'sent_to_admin' => $sent_to_admin,
475 'plain_text' => $plain_text,
476 'email' => $email,
477 'downloads' => $downloads,
478 'columns' => $columns,
479 )
480 );
481 }
482 }
483
484 /**
485 * Add order meta to email templates.
486 *
487 * @param WC_Order $order Order instance.
488 * @param bool $sent_to_admin If should sent to admin.
489 * @param bool $plain_text If is plain text email.
490 */
491 public function order_meta( $order, $sent_to_admin = false, $plain_text = false ) {
492 $fields = apply_filters( 'woocommerce_email_order_meta_fields', array(), $sent_to_admin, $order );
493
494 /**
495 * Deprecated woocommerce_email_order_meta_keys filter.
496 *
497 * @since 2.3.0
498 */
499 $_fields = apply_filters( 'woocommerce_email_order_meta_keys', array(), $sent_to_admin );
500
501 if ( $_fields ) {
502 foreach ( $_fields as $key => $field ) {
503 if ( is_numeric( $key ) ) {
504 $key = $field;
505 }
506
507 $fields[ $key ] = array(
508 'label' => wptexturize( $key ),
509 'value' => wptexturize( $order->get_meta( $field ) ),
510 );
511 }
512 }
513
514 if ( $fields ) {
515
516 if ( $plain_text ) {
517
518 foreach ( $fields as $field ) {
519 if ( isset( $field['label'] ) && isset( $field['value'] ) && $field['value'] ) {
520 echo $field['label'] . ': ' . $field['value'] . "\n"; // WPCS: XSS ok.
521 }
522 }
523 } else {
524
525 foreach ( $fields as $field ) {
526 if ( isset( $field['label'] ) && isset( $field['value'] ) && $field['value'] ) {
527 echo '<p><strong>' . $field['label'] . ':</strong> ' . $field['value'] . '</p>'; // WPCS: XSS ok.
528 }
529 }
530 }
531 }
532 }
533
534 /**
535 * Is customer detail field valid?
536 *
537 * @param array $field Field data to check if is valid.
538 * @return boolean
539 */
540 public function customer_detail_field_is_valid( $field ) {
541 return isset( $field['label'] ) && ! empty( $field['value'] );
542 }
543
544 /**
545 * Allows developers to add additional customer details to templates.
546 *
547 * In versions prior to 3.2 this was used for notes, phone and email but this data has moved.
548 *
549 * @param WC_Order $order Order instance.
550 * @param bool $sent_to_admin If should sent to admin.
551 * @param bool $plain_text If is plain text email.
552 */
553 public function customer_details( $order, $sent_to_admin = false, $plain_text = false ) {
554 if ( ! is_a( $order, 'WC_Order' ) ) {
555 return;
556 }
557
558 $fields = array_filter( apply_filters( 'woocommerce_email_customer_details_fields', array(), $sent_to_admin, $order ), array( $this, 'customer_detail_field_is_valid' ) );
559
560 if ( ! empty( $fields ) ) {
561 if ( $plain_text ) {
562 wc_get_template( 'emails/plain/email-customer-details.php', array( 'fields' => $fields ) );
563 } else {
564 wc_get_template( 'emails/email-customer-details.php', array( 'fields' => $fields ) );
565 }
566 }
567 }
568
569 /**
570 * Get the email addresses.
571 *
572 * @param WC_Order $order Order instance.
573 * @param bool $sent_to_admin If should sent to admin.
574 * @param bool $plain_text If is plain text email.
575 */
576 public function email_addresses( $order, $sent_to_admin = false, $plain_text = false ) {
577 if ( ! is_a( $order, 'WC_Order' ) ) {
578 return;
579 }
580 if ( $plain_text ) {
581 wc_get_template(
582 'emails/plain/email-addresses.php',
583 array(
584 'order' => $order,
585 'sent_to_admin' => $sent_to_admin,
586 )
587 );
588 } else {
589 wc_get_template(
590 'emails/email-addresses.php',
591 array(
592 'order' => $order,
593 'sent_to_admin' => $sent_to_admin,
594 )
595 );
596 }
597 }
598
599 /**
600 * Renders any additional fields captured during block based checkout.
601 *
602 * @param WC_Order $order Order instance.
603 * @param bool $sent_to_admin If email is sent to admin.
604 * @param bool $plain_text If this is a plain text email.
605 */
606 public function additional_checkout_fields( $order, $sent_to_admin = false, $plain_text = false ) {
607 if ( ! is_a( $order, 'WC_Order' ) ) {
608 return;
609 }
610
611 $checkout_fields = Package::container()->get( CheckoutFields::class );
612 $fields = array_merge(
613 $checkout_fields->get_order_additional_fields_with_values( $order, 'contact', 'other', 'view' ),
614 $checkout_fields->get_order_additional_fields_with_values( $order, 'order', 'other', 'view' ),
615 );
616
617 if ( ! $fields ) {
618 return;
619 }
620
621 if ( $plain_text ) {
622 echo "\n" . esc_html( wc_strtoupper( __( 'Additional information', 'woocommerce' ) ) ) . "\n\n";
623 foreach ( $fields as $field ) {
624 printf( "%s: %s\n", wp_kses_post( $field['label'] ), wp_kses_post( $field['value'] ) );
625 }
626 } else {
627 echo '<h2>' . esc_html__( 'Additional information', 'woocommerce' ) . '</h2>';
628 echo '<ul class="additional-fields" style="margin-bottom: 40px;">';
629 foreach ( $fields as $field ) {
630 printf( '<li><strong>%s</strong>: %s</li>', wp_kses_post( $field['label'] ), wp_kses_post( $field['value'] ) );
631 }
632 echo '</ul>';
633 }
634 }
635
636 /**
637 * Renders any additional address fields captured during block based checkout.
638 *
639 * @param string $address_type Address type.
640 * @param WC_Order $order Order instance.
641 * @param bool $sent_to_admin If email is sent to admin.
642 * @param bool $plain_text If this is a plain text email.
643 */
644 public function additional_address_fields( $address_type, $order, $sent_to_admin = false, $plain_text = false ) {
645 if ( ! is_a( $order, 'WC_Order' ) ) {
646 return;
647 }
648
649 $checkout_fields = Package::container()->get( CheckoutFields::class );
650 $fields = $checkout_fields->get_order_additional_fields_with_values( $order, 'address', $address_type, 'view' );
651
652 if ( ! $fields ) {
653 return;
654 }
655
656 foreach ( $fields as $field ) {
657 if ( $plain_text ) {
658 printf( "%s: %s\n", wp_kses_post( $field['label'] ), wp_kses_post( $field['value'] ) );
659 } else {
660 printf( '<br><strong>%s</strong>: %s', wp_kses_post( $field['label'] ), wp_kses_post( $field['value'] ) );
661 }
662 }
663 }
664
665 /**
666 * Get blog name formatted for emails.
667 *
668 * @return string
669 */
670 private function get_blogname() {
671 return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
672 }
673
674 /**
675 * Low stock notification email.
676 *
677 * @param WC_Product $product Product instance.
678 */
679 public function low_stock( $product ) {
680 if ( 'no' === get_option( 'woocommerce_notify_low_stock', 'yes' ) ) {
681 return;
682 }
683
684 /**
685 * Determine if the current product should trigger a low stock notification
686 *
687 * @param int $product_id - The low stock product id
688 *
689 * @since 4.7.0
690 */
691 if ( false === apply_filters( 'woocommerce_should_send_low_stock_notification', true, $product->get_id() ) ) {
692 return;
693 }
694
695 $subject = sprintf( '[%s] %s', $this->get_blogname(), __( 'Product low in stock', 'woocommerce' ) );
696 $message = sprintf(
697 /* translators: 1: product name 2: items in stock */
698 __( '%1$s is low in stock. There are %2$d left.', 'woocommerce' ),
699 html_entity_decode( wp_strip_all_tags( $product->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ),
700 html_entity_decode( wp_strip_all_tags( $product->get_stock_quantity() ) )
701 );
702
703 wp_mail(
704 apply_filters( 'woocommerce_email_recipient_low_stock', get_option( 'woocommerce_stock_email_recipient' ), $product, null ),
705 apply_filters( 'woocommerce_email_subject_low_stock', $subject, $product, null ),
706 apply_filters( 'woocommerce_email_content_low_stock', $message, $product ),
707 apply_filters( 'woocommerce_email_headers', '', 'low_stock', $product, null ),
708 apply_filters( 'woocommerce_email_attachments', array(), 'low_stock', $product, null )
709 );
710 }
711
712 /**
713 * No stock notification email.
714 *
715 * @param WC_Product $product Product instance.
716 */
717 public function no_stock( $product ) {
718 if ( 'no' === get_option( 'woocommerce_notify_no_stock', 'yes' ) ) {
719 return;
720 }
721
722 /**
723 * Determine if the current product should trigger a no stock notification
724 *
725 * @param int $product_id - The out of stock product id
726 *
727 * @since 4.6.0
728 */
729 if ( false === apply_filters( 'woocommerce_should_send_no_stock_notification', true, $product->get_id() ) ) {
730 return;
731 }
732
733 $subject = sprintf( '[%s] %s', $this->get_blogname(), __( 'Product out of stock', 'woocommerce' ) );
734 /* translators: %s: product name */
735 $message = sprintf( __( '%s is out of stock.', 'woocommerce' ), html_entity_decode( wp_strip_all_tags( $product->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ) );
736
737 wp_mail(
738 apply_filters( 'woocommerce_email_recipient_no_stock', get_option( 'woocommerce_stock_email_recipient' ), $product, null ),
739 apply_filters( 'woocommerce_email_subject_no_stock', $subject, $product, null ),
740 apply_filters( 'woocommerce_email_content_no_stock', $message, $product ),
741 apply_filters( 'woocommerce_email_headers', '', 'no_stock', $product, null ),
742 apply_filters( 'woocommerce_email_attachments', array(), 'no_stock', $product, null )
743 );
744 }
745
746 /**
747 * Backorder notification email.
748 *
749 * @param array $args Arguments.
750 */
751 public function backorder( $args ) {
752 $args = wp_parse_args(
753 $args,
754 array(
755 'product' => '',
756 'quantity' => '',
757 'order_id' => '',
758 )
759 );
760
761 $order = wc_get_order( $args['order_id'] );
762 if (
763 ! $args['product'] ||
764 ! is_object( $args['product'] ) ||
765 ! $args['quantity'] ||
766 ! $order
767 ) {
768 return;
769 }
770
771 $subject = sprintf( '[%s] %s', $this->get_blogname(), __( 'Product backorder', 'woocommerce' ) );
772 /* translators: 1: product quantity 2: product name 3: order number */
773 $message = sprintf( __( '%1$s units of %2$s have been backordered in order #%3$s.', 'woocommerce' ), $args['quantity'], html_entity_decode( wp_strip_all_tags( $args['product']->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ), $order->get_order_number() );
774
775 wp_mail(
776 apply_filters( 'woocommerce_email_recipient_backorder', get_option( 'woocommerce_stock_email_recipient' ), $args, null ),
777 apply_filters( 'woocommerce_email_subject_backorder', $subject, $args, null ),
778 apply_filters( 'woocommerce_email_content_backorder', $message, $args ),
779 apply_filters( 'woocommerce_email_headers', '', 'backorder', $args, null ),
780 apply_filters( 'woocommerce_email_attachments', array(), 'backorder', $args, null )
781 );
782 }
783
784 /**
785 * Adds Schema.org markup for order in JSON-LD format.
786 *
787 * @deprecated 3.0.0
788 * @see WC_Structured_Data::generate_order_data()
789 *
790 * @since 2.6.0
791 * @param WC_Order $order Order instance.
792 * @param bool $sent_to_admin If should sent to admin.
793 * @param bool $plain_text If is plain text email.
794 */
795 public function order_schema_markup( $order, $sent_to_admin = false, $plain_text = false ) {
796 wc_deprecated_function( 'WC_Emails::order_schema_markup', '3.0', 'WC_Structured_Data::generate_order_data' );
797
798 WC()->structured_data->generate_order_data( $order, $sent_to_admin, $plain_text );
799 WC()->structured_data->output_structured_data();
800 }
801 }
802