Нет описания

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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 3.5.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. '{order_date}' => '',
  40. '{order_number}' => '',
  41. );
  42. // Triggers.
  43. add_action( 'woocommerce_new_customer_note_notification', array( $this, 'trigger' ) );
  44. // Call parent constructor.
  45. parent::__construct();
  46. }
  47. /**
  48. * Get email subject.
  49. *
  50. * @since 3.1.0
  51. * @return string
  52. */
  53. public function get_default_subject() {
  54. return __( 'Note added to your {site_title} order from {order_date}', 'woocommerce' );
  55. }
  56. /**
  57. * Get email heading.
  58. *
  59. * @since 3.1.0
  60. * @return string
  61. */
  62. public function get_default_heading() {
  63. return __( 'A note has been added to your order', 'woocommerce' );
  64. }
  65. /**
  66. * Trigger.
  67. *
  68. * @param array $args Email arguments.
  69. */
  70. public function trigger( $args ) {
  71. $this->setup_locale();
  72. if ( ! empty( $args ) ) {
  73. $defaults = array(
  74. 'order_id' => '',
  75. 'customer_note' => '',
  76. );
  77. $args = wp_parse_args( $args, $defaults );
  78. $order_id = $args['order_id'];
  79. $customer_note = $args['customer_note'];
  80. if ( $order_id ) {
  81. $this->object = wc_get_order( $order_id );
  82. if ( $this->object ) {
  83. $this->recipient = $this->object->get_billing_email();
  84. $this->customer_note = $customer_note;
  85. $this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
  86. $this->placeholders['{order_number}'] = $this->object->get_order_number();
  87. }
  88. }
  89. }
  90. if ( $this->is_enabled() && $this->get_recipient() ) {
  91. $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
  92. }
  93. $this->restore_locale();
  94. }
  95. /**
  96. * Get content html.
  97. *
  98. * @return string
  99. */
  100. public function get_content_html() {
  101. return wc_get_template_html(
  102. $this->template_html,
  103. array(
  104. 'order' => $this->object,
  105. 'email_heading' => $this->get_heading(),
  106. 'additional_content' => $this->get_additional_content(),
  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. * @return string
  118. */
  119. public function get_content_plain() {
  120. return wc_get_template_html(
  121. $this->template_plain,
  122. array(
  123. 'order' => $this->object,
  124. 'email_heading' => $this->get_heading(),
  125. 'additional_content' => $this->get_additional_content(),
  126. 'customer_note' => $this->customer_note,
  127. 'sent_to_admin' => false,
  128. 'plain_text' => true,
  129. 'email' => $this,
  130. )
  131. );
  132. }
  133. /**
  134. * Default content to show below main email content.
  135. *
  136. * @since 3.7.0
  137. * @return string
  138. */
  139. public function get_default_additional_content() {
  140. return __( 'Thanks for reading.', 'woocommerce' );
  141. }
  142. }
  143. endif;
  144. return new WC_Email_Customer_Note();