Ei kuvausta

class-wc-email-customer-completed-order.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * Class WC_Email_Customer_Completed_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_Completed_Order', false ) ) :
  11. /**
  12. * Customer Completed Order Email.
  13. *
  14. * Order complete emails are sent to the customer when the order is marked complete and usual indicates that the order has been shipped.
  15. *
  16. * @class WC_Email_Customer_Completed_Order
  17. * @version 2.0.0
  18. * @package WooCommerce\Classes\Emails
  19. * @extends WC_Email
  20. */
  21. class WC_Email_Customer_Completed_Order extends WC_Email {
  22. /**
  23. * Constructor.
  24. */
  25. public function __construct() {
  26. $this->id = 'customer_completed_order';
  27. $this->customer_email = true;
  28. $this->title = __( 'Completed order', 'woocommerce' );
  29. $this->description = __( 'Order complete emails are sent to customers when their orders are marked completed and usually indicate that their orders have been shipped.', 'woocommerce' );
  30. $this->template_html = 'emails/customer-completed-order.php';
  31. $this->template_plain = 'emails/plain/customer-completed-order.php';
  32. $this->placeholders = array(
  33. '{order_date}' => '',
  34. '{order_number}' => '',
  35. );
  36. // Triggers for this email.
  37. add_action( 'woocommerce_order_status_completed_notification', array( $this, 'trigger' ), 10, 2 );
  38. // Call parent constructor.
  39. parent::__construct();
  40. }
  41. /**
  42. * Trigger the sending of this email.
  43. *
  44. * @param int $order_id The order ID.
  45. * @param WC_Order|false $order Order object.
  46. */
  47. public function trigger( $order_id, $order = false ) {
  48. $this->setup_locale();
  49. if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
  50. $order = wc_get_order( $order_id );
  51. }
  52. if ( is_a( $order, 'WC_Order' ) ) {
  53. $this->object = $order;
  54. $this->recipient = $this->object->get_billing_email();
  55. $this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
  56. $this->placeholders['{order_number}'] = $this->object->get_order_number();
  57. }
  58. if ( $this->is_enabled() && $this->get_recipient() ) {
  59. $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
  60. }
  61. $this->restore_locale();
  62. }
  63. /**
  64. * Get email subject.
  65. *
  66. * @since 3.1.0
  67. * @return string
  68. */
  69. public function get_default_subject() {
  70. return __( 'Your {site_title} order is now complete', 'woocommerce' );
  71. }
  72. /**
  73. * Get email heading.
  74. *
  75. * @since 3.1.0
  76. * @return string
  77. */
  78. public function get_default_heading() {
  79. return __( 'Thanks for shopping with us', 'woocommerce' );
  80. }
  81. /**
  82. * Get content html.
  83. *
  84. * @return string
  85. */
  86. public function get_content_html() {
  87. return wc_get_template_html(
  88. $this->template_html,
  89. array(
  90. 'order' => $this->object,
  91. 'email_heading' => $this->get_heading(),
  92. 'additional_content' => $this->get_additional_content(),
  93. 'sent_to_admin' => false,
  94. 'plain_text' => false,
  95. 'email' => $this,
  96. )
  97. );
  98. }
  99. /**
  100. * Get content plain.
  101. *
  102. * @return string
  103. */
  104. public function get_content_plain() {
  105. return wc_get_template_html(
  106. $this->template_plain,
  107. array(
  108. 'order' => $this->object,
  109. 'email_heading' => $this->get_heading(),
  110. 'additional_content' => $this->get_additional_content(),
  111. 'sent_to_admin' => false,
  112. 'plain_text' => true,
  113. 'email' => $this,
  114. )
  115. );
  116. }
  117. /**
  118. * Default content to show below main email content.
  119. *
  120. * @since 3.7.0
  121. * @return string
  122. */
  123. public function get_default_additional_content() {
  124. return __( 'Thanks for shopping with us.', 'woocommerce' );
  125. }
  126. }
  127. endif;
  128. return new WC_Email_Customer_Completed_Order();