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

https://gitlab.com/webkod3r/tripolis · PHP · 204 lines · 121 code · 26 blank · 57 comment · 9 complexity · 8a84297d80dbe83000ec8b231fd81cc1 MD5 · raw file

  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit; // Exit if accessed directly
  4. }
  5. if ( ! class_exists( 'WC_Email_Customer_Invoice' ) ) :
  6. /**
  7. * Customer Invoice.
  8. *
  9. * An email sent to the customer via admin.
  10. *
  11. * @class WC_Email_Customer_Invoice
  12. * @version 2.3.0
  13. * @package WooCommerce/Classes/Emails
  14. * @author WooThemes
  15. * @extends WC_Email
  16. */
  17. class WC_Email_Customer_Invoice extends WC_Email {
  18. /**
  19. * Strings to find in subjects/headings.
  20. *
  21. * @var array
  22. */
  23. public $find;
  24. /**
  25. * Strings to replace in subjects/headings.
  26. *
  27. * @var array
  28. */
  29. public $replace;
  30. /**
  31. * Constructor.
  32. */
  33. function __construct() {
  34. $this->id = 'customer_invoice';
  35. $this->title = __( 'Customer invoice', 'woocommerce' );
  36. $this->description = __( 'Customer invoice emails can be sent to customers containing their order information and payment links.', 'woocommerce' );
  37. $this->template_html = 'emails/customer-invoice.php';
  38. $this->template_plain = 'emails/plain/customer-invoice.php';
  39. $this->subject = __( 'Invoice for order {order_number} from {order_date}', 'woocommerce');
  40. $this->heading = __( 'Invoice for order {order_number}', 'woocommerce');
  41. $this->subject_paid = __( 'Your {site_title} order from {order_date}', 'woocommerce');
  42. $this->heading_paid = __( 'Order {order_number} details', 'woocommerce');
  43. // Call parent constructor
  44. parent::__construct();
  45. $this->customer_email = true;
  46. $this->manual = true;
  47. $this->heading_paid = $this->get_option( 'heading_paid', $this->heading_paid );
  48. $this->subject_paid = $this->get_option( 'subject_paid', $this->subject_paid );
  49. }
  50. /**
  51. * Trigger.
  52. *
  53. * @param int|WC_Order $order
  54. */
  55. function trigger( $order ) {
  56. if ( ! is_object( $order ) ) {
  57. $order = wc_get_order( absint( $order ) );
  58. }
  59. if ( $order ) {
  60. $this->object = $order;
  61. $this->recipient = $this->object->billing_email;
  62. $this->find['order-date'] = '{order_date}';
  63. $this->find['order-number'] = '{order_number}';
  64. $this->replace['order-date'] = date_i18n( wc_date_format(), strtotime( $this->object->order_date ) );
  65. $this->replace['order-number'] = $this->object->get_order_number();
  66. }
  67. if ( ! $this->get_recipient() ) {
  68. return;
  69. }
  70. $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
  71. }
  72. /**
  73. * Get email subject.
  74. *
  75. * @access public
  76. * @return string
  77. */
  78. function get_subject() {
  79. if ( $this->object->has_status( array( 'processing', 'completed' ) ) ) {
  80. return apply_filters( 'woocommerce_email_subject_customer_invoice_paid', $this->format_string( $this->subject_paid ), $this->object );
  81. } else {
  82. return apply_filters( 'woocommerce_email_subject_customer_invoice', $this->format_string( $this->subject ), $this->object );
  83. }
  84. }
  85. /**
  86. * Get email heading.
  87. *
  88. * @access public
  89. * @return string
  90. */
  91. function get_heading() {
  92. if ( $this->object->has_status( array( 'completed', 'processing' ) ) ) {
  93. return apply_filters( 'woocommerce_email_heading_customer_invoice_paid', $this->format_string( $this->heading_paid ), $this->object );
  94. } else {
  95. return apply_filters( 'woocommerce_email_heading_customer_invoice', $this->format_string( $this->heading ), $this->object );
  96. }
  97. }
  98. /**
  99. * Get content html.
  100. *
  101. * @access public
  102. * @return string
  103. */
  104. function get_content_html() {
  105. return wc_get_template_html( $this->template_html, array(
  106. 'order' => $this->object,
  107. 'email_heading' => $this->get_heading(),
  108. 'sent_to_admin' => false,
  109. 'plain_text' => false,
  110. 'email' => $this
  111. ) );
  112. }
  113. /**
  114. * Get content plain.
  115. *
  116. * @access public
  117. * @return string
  118. */
  119. function get_content_plain() {
  120. return wc_get_template_html( $this->template_plain, array(
  121. 'order' => $this->object,
  122. 'email_heading' => $this->get_heading(),
  123. 'sent_to_admin' => false,
  124. 'plain_text' => true,
  125. 'email' => $this
  126. ) );
  127. }
  128. /**
  129. * Initialise settings form fields.
  130. */
  131. function init_form_fields() {
  132. $this->form_fields = array(
  133. 'subject' => array(
  134. 'title' => __( 'Email Subject', 'woocommerce' ),
  135. 'type' => 'text',
  136. 'description' => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->subject ),
  137. 'placeholder' => '',
  138. 'default' => '',
  139. 'desc_tip' => true
  140. ),
  141. 'heading' => array(
  142. 'title' => __( 'Email Heading', 'woocommerce' ),
  143. 'type' => 'text',
  144. 'description' => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->heading ),
  145. 'placeholder' => '',
  146. 'default' => '',
  147. 'desc_tip' => true
  148. ),
  149. 'subject_paid' => array(
  150. 'title' => __( 'Email Subject (paid)', 'woocommerce' ),
  151. 'type' => 'text',
  152. 'description' => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->subject_paid ),
  153. 'placeholder' => '',
  154. 'default' => '',
  155. 'desc_tip' => true
  156. ),
  157. 'heading_paid' => array(
  158. 'title' => __( 'Email Heading (paid)', 'woocommerce' ),
  159. 'type' => 'text',
  160. 'description' => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->heading_paid ),
  161. 'placeholder' => '',
  162. 'default' => '',
  163. 'desc_tip' => true
  164. ),
  165. 'email_type' => array(
  166. 'title' => __( 'Email Type', 'woocommerce' ),
  167. 'type' => 'select',
  168. 'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
  169. 'default' => 'html',
  170. 'class' => 'email_type wc-enhanced-select',
  171. 'options' => $this->get_email_type_options(),
  172. 'desc_tip' => true
  173. )
  174. );
  175. }
  176. }
  177. endif;
  178. return new WC_Email_Customer_Invoice();