Nessuna descrizione

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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 3.5.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. '{order_date}' => '',
  34. '{order_number}' => '',
  35. );
  36. // Call parent constructor.
  37. parent::__construct();
  38. $this->manual = true;
  39. }
  40. /**
  41. * Get email subject.
  42. *
  43. * @param bool $paid Whether the order has been paid or not.
  44. * @since 3.1.0
  45. * @return string
  46. */
  47. public function get_default_subject( $paid = false ) {
  48. if ( $paid ) {
  49. return __( 'Invoice for order #{order_number} on {site_title}', 'woocommerce' );
  50. } else {
  51. return __( 'Your latest {site_title} invoice', 'woocommerce' );
  52. }
  53. }
  54. /**
  55. * Get email heading.
  56. *
  57. * @param bool $paid Whether the order has been paid or not.
  58. * @since 3.1.0
  59. * @return string
  60. */
  61. public function get_default_heading( $paid = false ) {
  62. if ( $paid ) {
  63. return __( 'Invoice for order #{order_number}', 'woocommerce' );
  64. } else {
  65. return __( 'Your invoice for order #{order_number}', 'woocommerce' );
  66. }
  67. }
  68. /**
  69. * Get email subject.
  70. *
  71. * @return string
  72. */
  73. public function get_subject() {
  74. if ( $this->object->has_status( array( 'completed', 'processing' ) ) ) {
  75. $subject = $this->get_option( 'subject_paid', $this->get_default_subject( true ) );
  76. return apply_filters( 'woocommerce_email_subject_customer_invoice_paid', $this->format_string( $subject ), $this->object, $this );
  77. }
  78. $subject = $this->get_option( 'subject', $this->get_default_subject() );
  79. return apply_filters( 'woocommerce_email_subject_customer_invoice', $this->format_string( $subject ), $this->object, $this );
  80. }
  81. /**
  82. * Get email heading.
  83. *
  84. * @return string
  85. */
  86. public function get_heading() {
  87. if ( $this->object->has_status( wc_get_is_paid_statuses() ) ) {
  88. $heading = $this->get_option( 'heading_paid', $this->get_default_heading( true ) );
  89. return apply_filters( 'woocommerce_email_heading_customer_invoice_paid', $this->format_string( $heading ), $this->object, $this );
  90. }
  91. $heading = $this->get_option( 'heading', $this->get_default_heading() );
  92. return apply_filters( 'woocommerce_email_heading_customer_invoice', $this->format_string( $heading ), $this->object, $this );
  93. }
  94. /**
  95. * Default content to show below main email content.
  96. *
  97. * @since 3.7.0
  98. * @return string
  99. */
  100. public function get_default_additional_content() {
  101. return __( 'Thanks for using {site_url}!', 'woocommerce' );
  102. }
  103. /**
  104. * Trigger the sending of this email.
  105. *
  106. * @param int $order_id The order ID.
  107. * @param WC_Order $order Order object.
  108. */
  109. public function trigger( $order_id, $order = false ) {
  110. $this->setup_locale();
  111. if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
  112. $order = wc_get_order( $order_id );
  113. }
  114. if ( is_a( $order, 'WC_Order' ) ) {
  115. $this->object = $order;
  116. $this->recipient = $this->object->get_billing_email();
  117. $this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
  118. $this->placeholders['{order_number}'] = $this->object->get_order_number();
  119. }
  120. if ( $this->get_recipient() ) {
  121. $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
  122. }
  123. $this->restore_locale();
  124. }
  125. /**
  126. * Get content html.
  127. *
  128. * @return string
  129. */
  130. public function get_content_html() {
  131. return wc_get_template_html(
  132. $this->template_html,
  133. array(
  134. 'order' => $this->object,
  135. 'email_heading' => $this->get_heading(),
  136. 'additional_content' => $this->get_additional_content(),
  137. 'sent_to_admin' => false,
  138. 'plain_text' => false,
  139. 'email' => $this,
  140. )
  141. );
  142. }
  143. /**
  144. * Get content plain.
  145. *
  146. * @return string
  147. */
  148. public function get_content_plain() {
  149. return wc_get_template_html(
  150. $this->template_plain,
  151. array(
  152. 'order' => $this->object,
  153. 'email_heading' => $this->get_heading(),
  154. 'additional_content' => $this->get_additional_content(),
  155. 'sent_to_admin' => false,
  156. 'plain_text' => true,
  157. 'email' => $this,
  158. )
  159. );
  160. }
  161. /**
  162. * Initialise settings form fields.
  163. */
  164. public function init_form_fields() {
  165. /* translators: %s: list of placeholders */
  166. $placeholder_text = sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>' . esc_html( implode( '</code>, <code>', array_keys( $this->placeholders ) ) ) . '</code>' );
  167. $this->form_fields = array(
  168. 'subject' => array(
  169. 'title' => __( 'Subject', 'woocommerce' ),
  170. 'type' => 'text',
  171. 'desc_tip' => true,
  172. 'description' => $placeholder_text,
  173. 'placeholder' => $this->get_default_subject(),
  174. 'default' => '',
  175. ),
  176. 'heading' => array(
  177. 'title' => __( 'Email heading', 'woocommerce' ),
  178. 'type' => 'text',
  179. 'desc_tip' => true,
  180. 'description' => $placeholder_text,
  181. 'placeholder' => $this->get_default_heading(),
  182. 'default' => '',
  183. ),
  184. 'subject_paid' => array(
  185. 'title' => __( 'Subject (paid)', 'woocommerce' ),
  186. 'type' => 'text',
  187. 'desc_tip' => true,
  188. 'description' => $placeholder_text,
  189. 'placeholder' => $this->get_default_subject( true ),
  190. 'default' => '',
  191. ),
  192. 'heading_paid' => array(
  193. 'title' => __( 'Email heading (paid)', 'woocommerce' ),
  194. 'type' => 'text',
  195. 'desc_tip' => true,
  196. 'description' => $placeholder_text,
  197. 'placeholder' => $this->get_default_heading( true ),
  198. 'default' => '',
  199. ),
  200. 'additional_content' => array(
  201. 'title' => __( 'Additional content', 'woocommerce' ),
  202. 'description' => __( 'Text to appear below the main email content.', 'woocommerce' ) . ' ' . $placeholder_text,
  203. 'css' => 'width:400px; height: 75px;',
  204. 'placeholder' => __( 'N/A', 'woocommerce' ),
  205. 'type' => 'textarea',
  206. 'default' => $this->get_default_additional_content(),
  207. 'desc_tip' => true,
  208. ),
  209. 'email_type' => array(
  210. 'title' => __( 'Email type', 'woocommerce' ),
  211. 'type' => 'select',
  212. 'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
  213. 'default' => 'html',
  214. 'class' => 'email_type wc-enhanced-select',
  215. 'options' => $this->get_email_type_options(),
  216. 'desc_tip' => true,
  217. ),
  218. );
  219. }
  220. }
  221. endif;
  222. return new WC_Email_Customer_Invoice();