abstracts
8 years ago
admin
8 years ago
api
8 years ago
cli
8 years ago
data-stores
8 years ago
emails
8 years ago
gateways
8 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
8 years ago
theme-support
9 years ago
vendor
9 years ago
walkers
9 years ago
widgets
8 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
8 years ago
class-wc-checkout.php
8 years ago
class-wc-cli.php
9 years ago
class-wc-comments.php
9 years ago
class-wc-countries.php
8 years ago
class-wc-coupon.php
8 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
8 years ago
class-wc-download-handler.php
9 years ago
class-wc-emails.php
8 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
8 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
8 years ago
class-wc-order-item-product.php
8 years ago
class-wc-order-item-shipping.php
8 years ago
class-wc-order-item-tax.php
9 years ago
class-wc-order-item.php
8 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
8 years ago
class-wc-post-types.php
9 years ago
class-wc-product-attribute.php
8 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
8 years ago
class-wc-product-simple.php
9 years ago
class-wc-product-variable.php
8 years ago
class-wc-product-variation.php
8 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
8 years ago
class-wc-shipping-zones.php
9 years ago
class-wc-shipping.php
9 years ago
class-wc-shortcodes.php
8 years ago
class-wc-structured-data.php
8 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
8 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
8 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
8 years ago
wc-order-item-functions.php
8 years ago
wc-page-functions.php
9 years ago
wc-product-functions.php
8 years ago
wc-rest-functions.php
8 years ago
wc-stock-functions.php
9 years ago
wc-template-functions.php
8 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
557 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’ 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’ 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_processing_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', false ) ) { |
| 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 | * Queues transactional email so it's not sent in current request if enabled, |
| 106 | * otherwise falls back to send now. |
| 107 | */ |
| 108 | public static function queue_transactional_email() { |
| 109 | if ( is_a( self::$background_emailer, 'WC_Background_Emailer' ) ) { |
| 110 | self::$background_emailer->push_to_queue( array( |
| 111 | 'filter' => current_filter(), |
| 112 | 'args' => func_get_args(), |
| 113 | ) ); |
| 114 | } else { |
| 115 | call_user_func_array( array( __CLASS__, 'send_transactional_email' ), func_get_args() ); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Init the mailer instance and call the notifications for the current filter. |
| 121 | * |
| 122 | * @internal |
| 123 | * |
| 124 | * @param string $filter Filter name. |
| 125 | * @param array $args Email args (default: []). |
| 126 | */ |
| 127 | public static function send_queued_transactional_email( $filter = '', $args = array() ) { |
| 128 | if ( apply_filters( 'woocommerce_allow_send_queued_transactional_email', true, $filter, $args ) ) { |
| 129 | self::instance(); // Init self so emails exist. |
| 130 | |
| 131 | // Ensure gateways are loaded in case they need to insert data into the emails. |
| 132 | WC()->payment_gateways(); |
| 133 | WC()->shipping(); |
| 134 | |
| 135 | do_action_ref_array( $filter . '_notification', $args ); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Init the mailer instance and call the notifications for the current filter. |
| 141 | * |
| 142 | * @internal |
| 143 | * |
| 144 | * @param array $args Email args (default: []). |
| 145 | */ |
| 146 | public static function send_transactional_email( $args = array() ) { |
| 147 | try { |
| 148 | $args = func_get_args(); |
| 149 | self::instance(); // Init self so emails exist. |
| 150 | do_action_ref_array( current_filter() . '_notification', $args ); |
| 151 | } catch ( Exception $e ) { |
| 152 | if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
| 153 | trigger_error( 'Transactional email triggered fatal error for callback ' . current_filter(), E_USER_WARNING ); |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Constructor for the email class hooks in all emails that can be sent. |
| 160 | * |
| 161 | */ |
| 162 | public function __construct() { |
| 163 | $this->init(); |
| 164 | |
| 165 | // Email Header, Footer and content hooks |
| 166 | add_action( 'woocommerce_email_header', array( $this, 'email_header' ) ); |
| 167 | add_action( 'woocommerce_email_footer', array( $this, 'email_footer' ) ); |
| 168 | add_action( 'woocommerce_email_order_details', array( $this, 'order_details' ), 10, 4 ); |
| 169 | add_action( 'woocommerce_email_order_meta', array( $this, 'order_meta' ), 10, 3 ); |
| 170 | add_action( 'woocommerce_email_customer_details', array( $this, 'customer_details' ), 10, 3 ); |
| 171 | add_action( 'woocommerce_email_customer_details', array( $this, 'email_addresses' ), 20, 3 ); |
| 172 | |
| 173 | // Hooks for sending emails during store events |
| 174 | add_action( 'woocommerce_low_stock_notification', array( $this, 'low_stock' ) ); |
| 175 | add_action( 'woocommerce_no_stock_notification', array( $this, 'no_stock' ) ); |
| 176 | add_action( 'woocommerce_product_on_backorder_notification', array( $this, 'backorder' ) ); |
| 177 | add_action( 'woocommerce_created_customer_notification', array( $this, 'customer_new_account' ), 10, 3 ); |
| 178 | |
| 179 | // Let 3rd parties unhook the above via this hook |
| 180 | do_action( 'woocommerce_email', $this ); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Init email classes. |
| 185 | */ |
| 186 | public function init() { |
| 187 | // Include email classes |
| 188 | include_once( dirname( __FILE__ ) . '/emails/class-wc-email.php' ); |
| 189 | |
| 190 | $this->emails['WC_Email_New_Order'] = include( 'emails/class-wc-email-new-order.php' ); |
| 191 | $this->emails['WC_Email_Cancelled_Order'] = include( 'emails/class-wc-email-cancelled-order.php' ); |
| 192 | $this->emails['WC_Email_Failed_Order'] = include( 'emails/class-wc-email-failed-order.php' ); |
| 193 | $this->emails['WC_Email_Customer_On_Hold_Order'] = include( 'emails/class-wc-email-customer-on-hold-order.php' ); |
| 194 | $this->emails['WC_Email_Customer_Processing_Order'] = include( 'emails/class-wc-email-customer-processing-order.php' ); |
| 195 | $this->emails['WC_Email_Customer_Completed_Order'] = include( 'emails/class-wc-email-customer-completed-order.php' ); |
| 196 | $this->emails['WC_Email_Customer_Refunded_Order'] = include( 'emails/class-wc-email-customer-refunded-order.php' ); |
| 197 | $this->emails['WC_Email_Customer_Invoice'] = include( 'emails/class-wc-email-customer-invoice.php' ); |
| 198 | $this->emails['WC_Email_Customer_Note'] = include( 'emails/class-wc-email-customer-note.php' ); |
| 199 | $this->emails['WC_Email_Customer_Reset_Password'] = include( 'emails/class-wc-email-customer-reset-password.php' ); |
| 200 | $this->emails['WC_Email_Customer_New_Account'] = include( 'emails/class-wc-email-customer-new-account.php' ); |
| 201 | |
| 202 | $this->emails = apply_filters( 'woocommerce_email_classes', $this->emails ); |
| 203 | |
| 204 | // include css inliner |
| 205 | if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
| 206 | include_once( dirname( __FILE__ ) . '/libraries/class-emogrifier.php' ); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Return the email classes - used in admin to load settings. |
| 212 | * |
| 213 | * @return array |
| 214 | */ |
| 215 | public function get_emails() { |
| 216 | return $this->emails; |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Get from name for email. |
| 221 | * |
| 222 | * @return string |
| 223 | */ |
| 224 | public function get_from_name() { |
| 225 | return wp_specialchars_decode( get_option( 'woocommerce_email_from_name' ), ENT_QUOTES ); |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * Get from email address. |
| 230 | * |
| 231 | * @return string |
| 232 | */ |
| 233 | public function get_from_address() { |
| 234 | return sanitize_email( get_option( 'woocommerce_email_from_address' ) ); |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Get the email header. |
| 239 | * |
| 240 | * @param mixed $email_heading heading for the email |
| 241 | */ |
| 242 | public function email_header( $email_heading ) { |
| 243 | wc_get_template( 'emails/email-header.php', array( 'email_heading' => $email_heading ) ); |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Get the email footer. |
| 248 | */ |
| 249 | public function email_footer() { |
| 250 | wc_get_template( 'emails/email-footer.php' ); |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * Wraps a message in the woocommerce mail template. |
| 255 | * |
| 256 | * @param mixed $email_heading |
| 257 | * @param string $message |
| 258 | * @return string |
| 259 | */ |
| 260 | public function wrap_message( $email_heading, $message, $plain_text = false ) { |
| 261 | // Buffer |
| 262 | ob_start(); |
| 263 | |
| 264 | do_action( 'woocommerce_email_header', $email_heading ); |
| 265 | |
| 266 | echo wpautop( wptexturize( $message ) ); |
| 267 | |
| 268 | do_action( 'woocommerce_email_footer' ); |
| 269 | |
| 270 | // Get contents |
| 271 | $message = ob_get_clean(); |
| 272 | |
| 273 | return $message; |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * Send the email. |
| 278 | * |
| 279 | * @param mixed $to |
| 280 | * @param mixed $subject |
| 281 | * @param mixed $message |
| 282 | * @param string $headers (default: "Content-Type: text/html\r\n") |
| 283 | * @param string $attachments (default: "") |
| 284 | * @return bool |
| 285 | */ |
| 286 | public function send( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = "" ) { |
| 287 | // Send |
| 288 | $email = new WC_Email(); |
| 289 | return $email->send( $to, $subject, $message, $headers, $attachments ); |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Prepare and send the customer invoice email on demand. |
| 294 | */ |
| 295 | public function customer_invoice( $order ) { |
| 296 | $email = $this->emails['WC_Email_Customer_Invoice']; |
| 297 | |
| 298 | if ( ! is_object( $order ) ) { |
| 299 | $order = wc_get_order( absint( $order ) ); |
| 300 | } |
| 301 | |
| 302 | $email->trigger( $order->get_id(), $order ); |
| 303 | } |
| 304 | |
| 305 | /** |
| 306 | * Customer new account welcome email. |
| 307 | * |
| 308 | * @param int $customer_id |
| 309 | * @param array $new_customer_data |
| 310 | */ |
| 311 | public function customer_new_account( $customer_id, $new_customer_data = array(), $password_generated = false ) { |
| 312 | if ( ! $customer_id ) { |
| 313 | return; |
| 314 | } |
| 315 | |
| 316 | $user_pass = ! empty( $new_customer_data['user_pass'] ) ? $new_customer_data['user_pass'] : ''; |
| 317 | |
| 318 | $email = $this->emails['WC_Email_Customer_New_Account']; |
| 319 | $email->trigger( $customer_id, $user_pass, $password_generated ); |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * Show the order details table |
| 324 | */ |
| 325 | public function order_details( $order, $sent_to_admin = false, $plain_text = false, $email = '' ) { |
| 326 | if ( $plain_text ) { |
| 327 | wc_get_template( 'emails/plain/email-order-details.php', array( 'order' => $order, 'sent_to_admin' => $sent_to_admin, 'plain_text' => $plain_text, 'email' => $email ) ); |
| 328 | } else { |
| 329 | wc_get_template( 'emails/email-order-details.php', array( 'order' => $order, 'sent_to_admin' => $sent_to_admin, 'plain_text' => $plain_text, 'email' => $email ) ); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * Add order meta to email templates. |
| 335 | * |
| 336 | * @param mixed $order |
| 337 | * @param bool $sent_to_admin (default: false) |
| 338 | * @param bool $plain_text (default: false) |
| 339 | * @return string |
| 340 | */ |
| 341 | public function order_meta( $order, $sent_to_admin = false, $plain_text = false ) { |
| 342 | $fields = apply_filters( 'woocommerce_email_order_meta_fields', array(), $sent_to_admin, $order ); |
| 343 | |
| 344 | /** |
| 345 | * Deprecated woocommerce_email_order_meta_keys filter. |
| 346 | * |
| 347 | * @since 2.3.0 |
| 348 | */ |
| 349 | $_fields = apply_filters( 'woocommerce_email_order_meta_keys', array(), $sent_to_admin ); |
| 350 | |
| 351 | if ( $_fields ) { |
| 352 | foreach ( $_fields as $key => $field ) { |
| 353 | if ( is_numeric( $key ) ) { |
| 354 | $key = $field; |
| 355 | } |
| 356 | |
| 357 | $fields[ $key ] = array( |
| 358 | 'label' => wptexturize( $key ), |
| 359 | 'value' => wptexturize( get_post_meta( $order->get_id(), $field, true ) ), |
| 360 | ); |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | if ( $fields ) { |
| 365 | |
| 366 | if ( $plain_text ) { |
| 367 | |
| 368 | foreach ( $fields as $field ) { |
| 369 | if ( isset( $field['label'] ) && isset( $field['value'] ) && $field['value'] ) { |
| 370 | echo $field['label'] . ': ' . $field['value'] . "\n"; |
| 371 | } |
| 372 | } |
| 373 | } else { |
| 374 | |
| 375 | foreach ( $fields as $field ) { |
| 376 | if ( isset( $field['label'] ) && isset( $field['value'] ) && $field['value'] ) { |
| 377 | echo '<p><strong>' . $field['label'] . ':</strong> ' . $field['value'] . '</p>'; |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * Is customer detail field valid? |
| 386 | * @param array $field |
| 387 | * @return boolean |
| 388 | */ |
| 389 | public function customer_detail_field_is_valid( $field ) { |
| 390 | return isset( $field['label'] ) && ! empty( $field['value'] ); |
| 391 | } |
| 392 | |
| 393 | /** |
| 394 | * Add customer details to email templates. |
| 395 | * |
| 396 | * @param WC_Order $order |
| 397 | * @param bool $sent_to_admin (default: false) |
| 398 | * @param bool $plain_text (default: false) |
| 399 | * @return string |
| 400 | */ |
| 401 | public function customer_details( $order, $sent_to_admin = false, $plain_text = false ) { |
| 402 | if ( ! is_a( $order, 'WC_Order' ) ) { |
| 403 | return; |
| 404 | } |
| 405 | $fields = array(); |
| 406 | |
| 407 | if ( $order->get_customer_note() ) { |
| 408 | $fields['customer_note'] = array( |
| 409 | 'label' => __( 'Note', 'woocommerce' ), |
| 410 | 'value' => wptexturize( $order->get_customer_note() ), |
| 411 | ); |
| 412 | } |
| 413 | |
| 414 | if ( $order->get_billing_email() ) { |
| 415 | $fields['billing_email'] = array( |
| 416 | 'label' => __( 'Email address', 'woocommerce' ), |
| 417 | 'value' => wptexturize( $order->get_billing_email() ), |
| 418 | ); |
| 419 | } |
| 420 | |
| 421 | if ( $order->get_billing_phone() ) { |
| 422 | $fields['billing_phone'] = array( |
| 423 | 'label' => __( 'Phone', 'woocommerce' ), |
| 424 | 'value' => wptexturize( $order->get_billing_phone() ), |
| 425 | ); |
| 426 | } |
| 427 | |
| 428 | $fields = array_filter( apply_filters( 'woocommerce_email_customer_details_fields', $fields, $sent_to_admin, $order ), array( $this, 'customer_detail_field_is_valid' ) ); |
| 429 | |
| 430 | if ( $plain_text ) { |
| 431 | wc_get_template( 'emails/plain/email-customer-details.php', array( 'fields' => $fields ) ); |
| 432 | } else { |
| 433 | wc_get_template( 'emails/email-customer-details.php', array( 'fields' => $fields ) ); |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | /** |
| 438 | * Get the email addresses. |
| 439 | */ |
| 440 | public function email_addresses( $order, $sent_to_admin = false, $plain_text = false ) { |
| 441 | if ( ! is_a( $order, 'WC_Order' ) ) { |
| 442 | return; |
| 443 | } |
| 444 | if ( $plain_text ) { |
| 445 | wc_get_template( 'emails/plain/email-addresses.php', array( 'order' => $order ) ); |
| 446 | } else { |
| 447 | wc_get_template( 'emails/email-addresses.php', array( 'order' => $order ) ); |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | /** |
| 452 | * Get blog name formatted for emails. |
| 453 | * @return string |
| 454 | */ |
| 455 | private function get_blogname() { |
| 456 | return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); |
| 457 | } |
| 458 | |
| 459 | /** |
| 460 | * Low stock notification email. |
| 461 | * |
| 462 | * @param WC_Product $product |
| 463 | */ |
| 464 | public function low_stock( $product ) { |
| 465 | if ( 'no' === get_option( 'woocommerce_notify_low_stock', 'yes' ) ) { |
| 466 | return; |
| 467 | } |
| 468 | |
| 469 | $subject = sprintf( '[%s] %s', $this->get_blogname(), __( 'Product low in stock', 'woocommerce' ) ); |
| 470 | /* translators: 1: product name 2: items in stock */ |
| 471 | $message = sprintf( |
| 472 | __( '%1$s is low in stock. There are %2$d left.', 'woocommerce' ), |
| 473 | html_entity_decode( strip_tags( $product->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ), |
| 474 | html_entity_decode( strip_tags( $product->get_stock_quantity() ) ) |
| 475 | ); |
| 476 | |
| 477 | wp_mail( |
| 478 | apply_filters( 'woocommerce_email_recipient_low_stock', get_option( 'woocommerce_stock_email_recipient' ), $product ), |
| 479 | apply_filters( 'woocommerce_email_subject_low_stock', $subject, $product ), |
| 480 | apply_filters( 'woocommerce_email_content_low_stock', $message, $product ), |
| 481 | apply_filters( 'woocommerce_email_headers', '', 'low_stock', $product ), |
| 482 | apply_filters( 'woocommerce_email_attachments', array(), 'low_stock', $product ) |
| 483 | ); |
| 484 | } |
| 485 | |
| 486 | /** |
| 487 | * No stock notification email. |
| 488 | * |
| 489 | * @param WC_Product $product |
| 490 | */ |
| 491 | public function no_stock( $product ) { |
| 492 | if ( 'no' === get_option( 'woocommerce_notify_no_stock', 'yes' ) ) { |
| 493 | return; |
| 494 | } |
| 495 | |
| 496 | $subject = sprintf( '[%s] %s', $this->get_blogname(), __( 'Product out of stock', 'woocommerce' ) ); |
| 497 | /* translators: %s: product name */ |
| 498 | $message = sprintf( __( '%s is out of stock.', 'woocommerce' ), html_entity_decode( strip_tags( $product->get_formatted_name() ), ENT_QUOTES, get_bloginfo( 'charset' ) ) ); |
| 499 | |
| 500 | wp_mail( |
| 501 | apply_filters( 'woocommerce_email_recipient_no_stock', get_option( 'woocommerce_stock_email_recipient' ), $product ), |
| 502 | apply_filters( 'woocommerce_email_subject_no_stock', $subject, $product ), |
| 503 | apply_filters( 'woocommerce_email_content_no_stock', $message, $product ), |
| 504 | apply_filters( 'woocommerce_email_headers', '', 'no_stock', $product ), |
| 505 | apply_filters( 'woocommerce_email_attachments', array(), 'no_stock', $product ) |
| 506 | ); |
| 507 | } |
| 508 | |
| 509 | /** |
| 510 | * Backorder notification email. |
| 511 | * |
| 512 | * @param array $args |
| 513 | */ |
| 514 | public function backorder( $args ) { |
| 515 | $args = wp_parse_args( $args, array( |
| 516 | 'product' => '', |
| 517 | 'quantity' => '', |
| 518 | 'order_id' => '', |
| 519 | ) ); |
| 520 | |
| 521 | extract( $args ); |
| 522 | |
| 523 | if ( ! $product || ! $quantity || ! ( $order = wc_get_order( $order_id ) ) ) { |
| 524 | return; |
| 525 | } |
| 526 | |
| 527 | $subject = sprintf( '[%s] %s', $this->get_blogname(), __( 'Product backorder', 'woocommerce' ) ); |
| 528 | $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() ); |
| 529 | |
| 530 | wp_mail( |
| 531 | apply_filters( 'woocommerce_email_recipient_backorder', get_option( 'woocommerce_stock_email_recipient' ), $args ), |
| 532 | apply_filters( 'woocommerce_email_subject_backorder', $subject, $args ), |
| 533 | apply_filters( 'woocommerce_email_content_backorder', $message, $args ), |
| 534 | apply_filters( 'woocommerce_email_headers', '', 'backorder', $args ), |
| 535 | apply_filters( 'woocommerce_email_attachments', array(), 'backorder', $args ) |
| 536 | ); |
| 537 | } |
| 538 | |
| 539 | /** |
| 540 | * Adds Schema.org markup for order in JSON-LD format. |
| 541 | * |
| 542 | * @deprecated 3.0.0 |
| 543 | * @see WC_Structured_Data::generate_order_data() |
| 544 | * |
| 545 | * @since 2.6.0 |
| 546 | * @param mixed $order |
| 547 | * @param bool $sent_to_admin (default: false) |
| 548 | * @param bool $plain_text (default: false) |
| 549 | */ |
| 550 | public function order_schema_markup( $order, $sent_to_admin = false, $plain_text = false ) { |
| 551 | wc_deprecated_function( 'WC_Emails::order_schema_markup', '3.0', 'WC_Structured_Data::generate_order_data' ); |
| 552 | |
| 553 | WC()->structured_data->generate_order_data( $order, $sent_to_admin, $plain_text ); |
| 554 | WC()->structured_data->output_structured_data(); |
| 555 | } |
| 556 | } |
| 557 |