class-wc-email-customer-note.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /**
  3. * Class WC_Email_Customer_Note 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_Note', false ) ) :
  11. /**
  12. * Customer Note Order Email.
  13. *
  14. * Customer note emails are sent when you add a note to an order.
  15. *
  16. * @class WC_Email_Customer_Note
  17. * @version 2.3.0
  18. * @package WooCommerce/Classes/Emails
  19. * @extends WC_Email
  20. */
  21. class WC_Email_Customer_Note extends WC_Email {
  22. /**
  23. * Customer note.
  24. *
  25. * @var string
  26. */
  27. public $customer_note;
  28. /**
  29. * Constructor.
  30. */
  31. public function __construct() {
  32. $this->id = 'customer_note';
  33. $this->customer_email = true;
  34. $this->title = __( 'Customer note', 'woocommerce' );
  35. $this->description = __( 'Customer note emails are sent when you add a note to an order.', 'woocommerce' );
  36. $this->template_html = 'emails/customer-note.php';
  37. $this->template_plain = 'emails/plain/customer-note.php';
  38. $this->placeholders = array(
  39. '{site_title}' => $this->get_blogname(),
  40. '{order_date}' => '',
  41. '{order_number}' => '',
  42. );
  43. // Triggers.
  44. add_action( 'woocommerce_new_customer_note_notification', array( $this, 'trigger' ) );
  45. // Call parent constructor.
  46. parent::__construct();
  47. }
  48. /**
  49. * Get email subject.
  50. *
  51. * @since 3.1.0
  52. * @return string
  53. */
  54. public function get_default_subject() {
  55. return __( 'Note added to your {site_title} order from {order_date}', 'woocommerce' );
  56. }
  57. /**
  58. * Get email heading.
  59. *
  60. * @since 3.1.0
  61. * @return string
  62. */
  63. public function get_default_heading() {
  64. return __( 'A note has been added to your order', 'woocommerce' );
  65. }
  66. /**
  67. * Trigger.
  68. *
  69. * @param array $args Email arguments.
  70. */
  71. public function trigger( $args ) {
  72. $this->setup_locale();
  73. if ( ! empty( $args ) ) {
  74. $defaults = array(
  75. 'order_id' => '',
  76. 'customer_note' => '',
  77. );
  78. $args = wp_parse_args( $args, $defaults );
  79. $order_id = $args['order_id'];
  80. $customer_note = $args['customer_note'];
  81. if ( $order_id ) {
  82. $this->object = wc_get_order( $order_id );
  83. if ( $this->object ) {
  84. $this->recipient = $this->object->get_billing_email();
  85. $this->customer_note = $customer_note;
  86. $this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
  87. $this->placeholders['{order_number}'] = $this->object->get_order_number();
  88. }
  89. }
  90. }
  91. if ( $this->is_enabled() && $this->get_recipient() ) {
  92. $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
  93. }
  94. $this->restore_locale();
  95. }
  96. /**
  97. * Get content html.
  98. *
  99. * @access public
  100. * @return string
  101. */
  102. public function get_content_html() {
  103. return wc_get_template_html(
  104. $this->template_html, array(
  105. 'order' => $this->object,
  106. 'email_heading' => $this->get_heading(),
  107. 'customer_note' => $this->customer_note,
  108. 'sent_to_admin' => false,
  109. 'plain_text' => false,
  110. 'email' => $this,
  111. )
  112. );
  113. }
  114. /**
  115. * Get content plain.
  116. *
  117. * @access public
  118. * @return string
  119. */
  120. public function get_content_plain() {
  121. return wc_get_template_html(
  122. $this->template_plain, array(
  123. 'order' => $this->object,
  124. 'email_heading' => $this->get_heading(),
  125. 'customer_note' => $this->customer_note,
  126. 'sent_to_admin' => false,
  127. 'plain_text' => true,
  128. 'email' => $this,
  129. )
  130. );
  131. }
  132. }
  133. endif;
  134. return new WC_Email_Customer_Note();