/wp-content/plugins/woocommerce/includes/emails/class-wc-email-customer-completed-order.php

https://gitlab.com/hunt9310/ras · PHP · 191 lines · 120 code · 23 blank · 48 comment · 11 complexity · fef12062bd868bd027dd9136250f5a3d MD5 · raw file

  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit; // Exit if accessed directly
  4. }
  5. if ( ! class_exists( 'WC_Email_Customer_Completed_Order' ) ) :
  6. /**
  7. * Customer Completed Order Email.
  8. *
  9. * Order complete emails are sent to the customer when the order is marked complete and usual indicates that the order has been shipped.
  10. *
  11. * @class WC_Email_Customer_Completed_Order
  12. * @version 2.0.0
  13. * @package WooCommerce/Classes/Emails
  14. * @author WooThemes
  15. * @extends WC_Email
  16. */
  17. class WC_Email_Customer_Completed_Order extends WC_Email {
  18. /**
  19. * Constructor.
  20. */
  21. public function __construct() {
  22. $this->id = 'customer_completed_order';
  23. $this->customer_email = true;
  24. $this->title = __( 'Completed order', 'woocommerce' );
  25. $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' );
  26. $this->heading = __( 'Your order is complete', 'woocommerce' );
  27. $this->subject = __( 'Your {site_title} order from {order_date} is complete', 'woocommerce' );
  28. $this->template_html = 'emails/customer-completed-order.php';
  29. $this->template_plain = 'emails/plain/customer-completed-order.php';
  30. // Triggers for this email
  31. add_action( 'woocommerce_order_status_completed_notification', array( $this, 'trigger' ) );
  32. // Other settings
  33. $this->heading_downloadable = $this->get_option( 'heading_downloadable', __( 'Your order is complete - download your files', 'woocommerce' ) );
  34. $this->subject_downloadable = $this->get_option( 'subject_downloadable', __( 'Your {site_title} order from {order_date} is complete - download your files', 'woocommerce' ) );
  35. // Call parent constuctor
  36. parent::__construct();
  37. }
  38. /**
  39. * Trigger.
  40. *
  41. * @param int $order_id
  42. */
  43. public function trigger( $order_id ) {
  44. if ( $order_id ) {
  45. $this->object = wc_get_order( $order_id );
  46. $this->recipient = $this->object->billing_email;
  47. $this->find['order-date'] = '{order_date}';
  48. $this->find['order-number'] = '{order_number}';
  49. $this->replace['order-date'] = date_i18n( wc_date_format(), strtotime( $this->object->order_date ) );
  50. $this->replace['order-number'] = $this->object->get_order_number();
  51. }
  52. if ( ! $this->is_enabled() || ! $this->get_recipient() ) {
  53. return;
  54. }
  55. $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
  56. }
  57. /**
  58. * Get email subject.
  59. *
  60. * @access public
  61. * @return string
  62. */
  63. public function get_subject() {
  64. if ( ! empty( $this->object ) && $this->object->has_downloadable_item() ) {
  65. return apply_filters( 'woocommerce_email_subject_customer_completed_order', $this->format_string( $this->subject_downloadable ), $this->object );
  66. } else {
  67. return apply_filters( 'woocommerce_email_subject_customer_completed_order', $this->format_string( $this->subject ), $this->object );
  68. }
  69. }
  70. /**
  71. * Get email heading.
  72. *
  73. * @access public
  74. * @return string
  75. */
  76. public function get_heading() {
  77. if ( ! empty( $this->object ) && $this->object->has_downloadable_item() ) {
  78. return apply_filters( 'woocommerce_email_heading_customer_completed_order', $this->format_string( $this->heading_downloadable ), $this->object );
  79. } else {
  80. return apply_filters( 'woocommerce_email_heading_customer_completed_order', $this->format_string( $this->heading ), $this->object );
  81. }
  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( $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. * Get content plain.
  100. *
  101. * @return string
  102. */
  103. public function get_content_plain() {
  104. return wc_get_template_html( $this->template_plain, array(
  105. 'order' => $this->object,
  106. 'email_heading' => $this->get_heading(),
  107. 'sent_to_admin' => false,
  108. 'plain_text' => true,
  109. 'email' => $this
  110. ) );
  111. }
  112. /**
  113. * Initialise settings form fields.
  114. */
  115. public function init_form_fields() {
  116. $this->form_fields = array(
  117. 'enabled' => array(
  118. 'title' => __( 'Enable/Disable', 'woocommerce' ),
  119. 'type' => 'checkbox',
  120. 'label' => __( 'Enable this email notification', 'woocommerce' ),
  121. 'default' => 'yes'
  122. ),
  123. 'subject' => array(
  124. 'title' => __( 'Subject', 'woocommerce' ),
  125. 'type' => 'text',
  126. 'description' => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->subject ),
  127. 'placeholder' => '',
  128. 'default' => '',
  129. 'desc_tip' => true
  130. ),
  131. 'heading' => array(
  132. 'title' => __( 'Email Heading', 'woocommerce' ),
  133. 'type' => 'text',
  134. 'description' => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->heading ),
  135. 'placeholder' => '',
  136. 'default' => '',
  137. 'desc_tip' => true
  138. ),
  139. 'subject_downloadable' => array(
  140. 'title' => __( 'Subject (downloadable)', 'woocommerce' ),
  141. 'type' => 'text',
  142. 'description' => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->subject_downloadable ),
  143. 'placeholder' => '',
  144. 'default' => '',
  145. 'desc_tip' => true
  146. ),
  147. 'heading_downloadable' => array(
  148. 'title' => __( 'Email Heading (downloadable)', 'woocommerce' ),
  149. 'type' => 'text',
  150. 'description' => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->heading_downloadable ),
  151. 'placeholder' => '',
  152. 'default' => '',
  153. 'desc_tip' => true
  154. ),
  155. 'email_type' => array(
  156. 'title' => __( 'Email type', 'woocommerce' ),
  157. 'type' => 'select',
  158. 'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
  159. 'default' => 'html',
  160. 'class' => 'email_type wc-enhanced-select',
  161. 'options' => $this->get_email_type_options(),
  162. 'desc_tip' => true
  163. )
  164. );
  165. }
  166. }
  167. endif;
  168. return new WC_Email_Customer_Completed_Order();