class-wc-email-customer-on-hold-order.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * Class WC_Email_Customer_On_Hold_Order file.
  4. *
  5. * @package WooCommerce\Emails
  6. */
  7. if ( ! defined( 'ABSPATH' ) ) {
  8. exit; // Exit if accessed directly.
  9. }
  10. if ( ! class_exists( 'WC_Email_Customer_On_Hold_Order', false ) ) :
  11. /**
  12. * Customer On-hold Order Email.
  13. *
  14. * An email sent to the customer when a new order is on-hold for.
  15. *
  16. * @class WC_Email_Customer_On_Hold_Order
  17. * @version 2.6.0
  18. * @package WooCommerce/Classes/Emails
  19. * @extends WC_Email
  20. */
  21. class WC_Email_Customer_On_Hold_Order extends WC_Email {
  22. /**
  23. * Constructor.
  24. */
  25. public function __construct() {
  26. $this->id = 'customer_on_hold_order';
  27. $this->customer_email = true;
  28. $this->title = __( 'Order on-hold', 'woocommerce' );
  29. $this->description = __( 'This is an order notification sent to customers containing order details after an order is placed on-hold.', 'woocommerce' );
  30. $this->template_html = 'emails/customer-on-hold-order.php';
  31. $this->template_plain = 'emails/plain/customer-on-hold-order.php';
  32. $this->placeholders = array(
  33. '{site_title}' => $this->get_blogname(),
  34. '{order_date}' => '',
  35. '{order_number}' => '',
  36. );
  37. // Triggers for this email.
  38. add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $this, 'trigger' ), 10, 2 );
  39. add_action( 'woocommerce_order_status_failed_to_on-hold_notification', array( $this, 'trigger' ), 10, 2 );
  40. // Call parent constructor.
  41. parent::__construct();
  42. }
  43. /**
  44. * Get email subject.
  45. *
  46. * @since 3.1.0
  47. * @return string
  48. */
  49. public function get_default_subject() {
  50. return __( 'Your {site_title} order receipt from {order_date}', 'woocommerce' );
  51. }
  52. /**
  53. * Get email heading.
  54. *
  55. * @since 3.1.0
  56. * @return string
  57. */
  58. public function get_default_heading() {
  59. return __( 'Thank you for your order', 'woocommerce' );
  60. }
  61. /**
  62. * Trigger the sending of this email.
  63. *
  64. * @param int $order_id The order ID.
  65. * @param WC_Order|false $order Order object.
  66. */
  67. public function trigger( $order_id, $order = false ) {
  68. $this->setup_locale();
  69. if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
  70. $order = wc_get_order( $order_id );
  71. }
  72. if ( is_a( $order, 'WC_Order' ) ) {
  73. $this->object = $order;
  74. $this->recipient = $this->object->get_billing_email();
  75. $this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
  76. $this->placeholders['{order_number}'] = $this->object->get_order_number();
  77. }
  78. if ( $this->is_enabled() && $this->get_recipient() ) {
  79. $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
  80. }
  81. $this->restore_locale();
  82. }
  83. /**
  84. * Get content html.
  85. *
  86. * @access public
  87. * @return string
  88. */
  89. public function get_content_html() {
  90. return wc_get_template_html(
  91. $this->template_html, array(
  92. 'order' => $this->object,
  93. 'email_heading' => $this->get_heading(),
  94. 'sent_to_admin' => false,
  95. 'plain_text' => false,
  96. 'email' => $this,
  97. )
  98. );
  99. }
  100. /**
  101. * Get content plain.
  102. *
  103. * @access public
  104. * @return string
  105. */
  106. public function get_content_plain() {
  107. return wc_get_template_html(
  108. $this->template_plain, array(
  109. 'order' => $this->object,
  110. 'email_heading' => $this->get_heading(),
  111. 'sent_to_admin' => false,
  112. 'plain_text' => true,
  113. 'email' => $this,
  114. )
  115. );
  116. }
  117. }
  118. endif;
  119. return new WC_Email_Customer_On_Hold_Order();