class-wc-email-customer-invoice.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. /**
  3. * Class WC_Email_Customer_Invoice 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_Invoice', false ) ) :
  11. /**
  12. * Customer Invoice.
  13. *
  14. * An email sent to the customer via admin.
  15. *
  16. * @class WC_Email_Customer_Invoice
  17. * @version 2.3.0
  18. * @package WooCommerce/Classes/Emails
  19. * @extends WC_Email
  20. */
  21. class WC_Email_Customer_Invoice extends WC_Email {
  22. /**
  23. * Constructor.
  24. */
  25. public function __construct() {
  26. $this->id = 'customer_invoice';
  27. $this->customer_email = true;
  28. $this->title = __( 'Customer invoice / Order details', 'woocommerce' );
  29. $this->description = __( 'Customer invoice emails can be sent to customers containing their order information and payment links.', 'woocommerce' );
  30. $this->template_html = 'emails/customer-invoice.php';
  31. $this->template_plain = 'emails/plain/customer-invoice.php';
  32. $this->placeholders = array(
  33. '{site_title}' => $this->get_blogname(),
  34. '{order_date}' => '',
  35. '{order_number}' => '',
  36. );
  37. // Call parent constructor.
  38. parent::__construct();
  39. $this->manual = true;
  40. }
  41. /**
  42. * Get email subject.
  43. *
  44. * @param bool $paid Whether the order has been paid or not.
  45. * @since 3.1.0
  46. * @return string
  47. */
  48. public function get_default_subject( $paid = false ) {
  49. if ( $paid ) {
  50. return __( 'Your {site_title} order from {order_date}', 'woocommerce' );
  51. } else {
  52. return __( 'Invoice for order {order_number}', 'woocommerce' );
  53. }
  54. }
  55. /**
  56. * Get email heading.
  57. *
  58. * @param bool $paid Whether the order has been paid or not.
  59. * @since 3.1.0
  60. * @return string
  61. */
  62. public function get_default_heading( $paid = false ) {
  63. if ( $paid ) {
  64. return __( 'Your order details', 'woocommerce' );
  65. } else {
  66. return __( 'Invoice for order {order_number}', 'woocommerce' );
  67. }
  68. }
  69. /**
  70. * Get email subject.
  71. *
  72. * @access public
  73. * @return string
  74. */
  75. public function get_subject() {
  76. if ( $this->object->has_status( array( 'completed', 'processing' ) ) ) {
  77. $subject = $this->get_option( 'subject_paid', $this->get_default_subject( true ) );
  78. return apply_filters( 'woocommerce_email_subject_customer_invoice_paid', $this->format_string( $subject ), $this->object );
  79. }
  80. $subject = $this->get_option( 'subject', $this->get_default_subject() );
  81. return apply_filters( 'woocommerce_email_subject_customer_invoice', $this->format_string( $subject ), $this->object );
  82. }
  83. /**
  84. * Get email heading.
  85. *
  86. * @access public
  87. * @return string
  88. */
  89. public function get_heading() {
  90. if ( $this->object->has_status( wc_get_is_paid_statuses() ) ) {
  91. $heading = $this->get_option( 'heading_paid', $this->get_default_heading( true ) );
  92. return apply_filters( 'woocommerce_email_heading_customer_invoice_paid', $this->format_string( $heading ), $this->object );
  93. }
  94. $heading = $this->get_option( 'heading', $this->get_default_heading() );
  95. return apply_filters( 'woocommerce_email_heading_customer_invoice', $this->format_string( $heading ), $this->object );
  96. }
  97. /**
  98. * Trigger the sending of this email.
  99. *
  100. * @param int $order_id The order ID.
  101. * @param WC_Order $order Order object.
  102. */
  103. public function trigger( $order_id, $order = false ) {
  104. $this->setup_locale();
  105. if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
  106. $order = wc_get_order( $order_id );
  107. }
  108. if ( is_a( $order, 'WC_Order' ) ) {
  109. $this->object = $order;
  110. $this->recipient = $this->object->get_billing_email();
  111. $this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
  112. $this->placeholders['{order_number}'] = $this->object->get_order_number();
  113. }
  114. if ( $this->get_recipient() ) {
  115. $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
  116. }
  117. $this->restore_locale();
  118. }
  119. /**
  120. * Get content html.
  121. *
  122. * @access public
  123. * @return string
  124. */
  125. public function get_content_html() {
  126. return wc_get_template_html(
  127. $this->template_html, array(
  128. 'order' => $this->object,
  129. 'email_heading' => $this->get_heading(),
  130. 'sent_to_admin' => false,
  131. 'plain_text' => false,
  132. 'email' => $this,
  133. )
  134. );
  135. }
  136. /**
  137. * Get content plain.
  138. *
  139. * @access public
  140. * @return string
  141. */
  142. public function get_content_plain() {
  143. return wc_get_template_html(
  144. $this->template_plain, array(
  145. 'order' => $this->object,
  146. 'email_heading' => $this->get_heading(),
  147. 'sent_to_admin' => false,
  148. 'plain_text' => true,
  149. 'email' => $this,
  150. )
  151. );
  152. }
  153. /**
  154. * Initialise settings form fields.
  155. */
  156. public function init_form_fields() {
  157. $this->form_fields = array(
  158. 'subject' => array(
  159. 'title' => __( 'Subject', 'woocommerce' ),
  160. 'type' => 'text',
  161. 'desc_tip' => true,
  162. /* translators: %s: list of placeholders */
  163. 'description' => sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>{site_title}, {order_date}, {order_number}</code>' ),
  164. 'placeholder' => $this->get_default_subject(),
  165. 'default' => '',
  166. ),
  167. 'heading' => array(
  168. 'title' => __( 'Email heading', 'woocommerce' ),
  169. 'type' => 'text',
  170. 'desc_tip' => true,
  171. /* translators: %s: list of placeholders */
  172. 'description' => sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>{site_title}, {order_date}, {order_number}</code>' ),
  173. 'placeholder' => $this->get_default_heading(),
  174. 'default' => '',
  175. ),
  176. 'subject_paid' => array(
  177. 'title' => __( 'Subject (paid)', 'woocommerce' ),
  178. 'type' => 'text',
  179. 'desc_tip' => true,
  180. /* translators: %s: list of placeholders */
  181. 'description' => sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>{site_title}, {order_date}, {order_number}</code>' ),
  182. 'placeholder' => $this->get_default_subject( true ),
  183. 'default' => '',
  184. ),
  185. 'heading_paid' => array(
  186. 'title' => __( 'Email heading (paid)', 'woocommerce' ),
  187. 'type' => 'text',
  188. 'desc_tip' => true,
  189. /* translators: %s: list of placeholders */
  190. 'description' => sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>{site_title}, {order_date}, {order_number}</code>' ),
  191. 'placeholder' => $this->get_default_heading( true ),
  192. 'default' => '',
  193. ),
  194. 'email_type' => array(
  195. 'title' => __( 'Email type', 'woocommerce' ),
  196. 'type' => 'select',
  197. 'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
  198. 'default' => 'html',
  199. 'class' => 'email_type wc-enhanced-select',
  200. 'options' => $this->get_email_type_options(),
  201. 'desc_tip' => true,
  202. ),
  203. );
  204. }
  205. }
  206. endif;
  207. return new WC_Email_Customer_Invoice();