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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. '{site_title}' => $this->get_blogname(),
  34. '{order_date}' => '',
  35. '{order_number}' => '',
  36. );
  37. // Triggers for this email.
  38. add_action( 'woocommerce_order_status_completed_notification', array( $this, 'trigger' ), 10, 2 );
  39. // Call parent constructor.
  40. parent::__construct();
  41. }
  42. /**
  43. * Trigger the sending of this email.
  44. *
  45. * @param int $order_id The order ID.
  46. * @param WC_Order|false $order Order object.
  47. */
  48. public function trigger( $order_id, $order = false ) {
  49. $this->setup_locale();
  50. if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
  51. $order = wc_get_order( $order_id );
  52. }
  53. if ( is_a( $order, 'WC_Order' ) ) {
  54. $this->object = $order;
  55. $this->recipient = $this->object->get_billing_email();
  56. $this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
  57. $this->placeholders['{order_number}'] = $this->object->get_order_number();
  58. }
  59. if ( $this->is_enabled() && $this->get_recipient() ) {
  60. $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
  61. }
  62. $this->restore_locale();
  63. }
  64. /**
  65. * Get email subject.
  66. *
  67. * @since 3.1.0
  68. * @return string
  69. */
  70. public function get_default_subject() {
  71. return __( 'Your {site_title} order from {order_date} is complete', 'woocommerce' );
  72. }
  73. /**
  74. * Get email heading.
  75. *
  76. * @since 3.1.0
  77. * @return string
  78. */
  79. public function get_default_heading() {
  80. return __( 'Your order is complete', 'woocommerce' );
  81. }
  82. /**
  83. * Get content html.
  84. *
  85. * @access public
  86. * @return string
  87. */
  88. public function get_content_html() {
  89. return wc_get_template_html(
  90. $this->template_html, array(
  91. 'order' => $this->object,
  92. 'email_heading' => $this->get_heading(),
  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, array(
  107. 'order' => $this->object,
  108. 'email_heading' => $this->get_heading(),
  109. 'sent_to_admin' => false,
  110. 'plain_text' => true,
  111. 'email' => $this,
  112. )
  113. );
  114. }
  115. /**
  116. * Initialise settings form fields.
  117. */
  118. public function init_form_fields() {
  119. $this->form_fields = array(
  120. 'enabled' => array(
  121. 'title' => __( 'Enable/Disable', 'woocommerce' ),
  122. 'type' => 'checkbox',
  123. 'label' => __( 'Enable this email notification', 'woocommerce' ),
  124. 'default' => 'yes',
  125. ),
  126. 'subject' => array(
  127. 'title' => __( 'Subject', 'woocommerce' ),
  128. 'type' => 'text',
  129. 'desc_tip' => true,
  130. /* translators: %s: list of placeholders */
  131. 'description' => sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>{site_title}, {order_date}, {order_number}</code>' ),
  132. 'placeholder' => $this->get_default_subject(),
  133. 'default' => '',
  134. ),
  135. 'heading' => array(
  136. 'title' => __( 'Email heading', 'woocommerce' ),
  137. 'type' => 'text',
  138. 'desc_tip' => true,
  139. /* translators: %s: list of placeholders */
  140. 'description' => sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>{site_title}, {order_date}, {order_number}</code>' ),
  141. 'placeholder' => $this->get_default_heading(),
  142. 'default' => '',
  143. ),
  144. 'email_type' => array(
  145. 'title' => __( 'Email type', 'woocommerce' ),
  146. 'type' => 'select',
  147. 'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
  148. 'default' => 'html',
  149. 'class' => 'email_type wc-enhanced-select',
  150. 'options' => $this->get_email_type_options(),
  151. 'desc_tip' => true,
  152. ),
  153. );
  154. }
  155. }
  156. endif;
  157. return new WC_Email_Customer_Completed_Order();