Нема описа

class-wc-email-cancelled-order.php 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. /**
  3. * Class WC_Email_Cancelled_Order file.
  4. *
  5. * @package WooCommerce\Emails
  6. */
  7. if ( ! defined( 'ABSPATH' ) ) {
  8. exit;
  9. }
  10. if ( ! class_exists( 'WC_Email_Cancelled_Order', false ) ) :
  11. /**
  12. * Cancelled Order Email.
  13. *
  14. * An email sent to the admin when an order is cancelled.
  15. *
  16. * @class WC_Email_Cancelled_Order
  17. * @version 2.2.7
  18. * @package WooCommerce\Classes\Emails
  19. * @extends WC_Email
  20. */
  21. class WC_Email_Cancelled_Order extends WC_Email {
  22. /**
  23. * Constructor.
  24. */
  25. public function __construct() {
  26. $this->id = 'cancelled_order';
  27. $this->title = __( 'Cancelled order', 'woocommerce' );
  28. $this->description = __( 'Cancelled order emails are sent to chosen recipient(s) when orders have been marked cancelled (if they were previously processing or on-hold).', 'woocommerce' );
  29. $this->template_html = 'emails/admin-cancelled-order.php';
  30. $this->template_plain = 'emails/plain/admin-cancelled-order.php';
  31. $this->placeholders = array(
  32. '{order_date}' => '',
  33. '{order_number}' => '',
  34. '{order_billing_full_name}' => '',
  35. );
  36. // Triggers for this email.
  37. add_action( 'woocommerce_order_status_processing_to_cancelled_notification', array( $this, 'trigger' ), 10, 2 );
  38. add_action( 'woocommerce_order_status_on-hold_to_cancelled_notification', array( $this, 'trigger' ), 10, 2 );
  39. // Call parent constructor.
  40. parent::__construct();
  41. // Other settings.
  42. $this->recipient = $this->get_option( 'recipient', get_option( 'admin_email' ) );
  43. }
  44. /**
  45. * Get email subject.
  46. *
  47. * @since 3.1.0
  48. * @return string
  49. */
  50. public function get_default_subject() {
  51. return __( '[{site_title}]: Order #{order_number} has been cancelled', 'woocommerce' );
  52. }
  53. /**
  54. * Get email heading.
  55. *
  56. * @since 3.1.0
  57. * @return string
  58. */
  59. public function get_default_heading() {
  60. return __( 'Order Cancelled: #{order_number}', 'woocommerce' );
  61. }
  62. /**
  63. * Trigger the sending of this email.
  64. *
  65. * @param int $order_id The order ID.
  66. * @param WC_Order|false $order Order object.
  67. */
  68. public function trigger( $order_id, $order = false ) {
  69. $this->setup_locale();
  70. if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
  71. $order = wc_get_order( $order_id );
  72. }
  73. if ( is_a( $order, 'WC_Order' ) ) {
  74. $this->object = $order;
  75. $this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
  76. $this->placeholders['{order_number}'] = $this->object->get_order_number();
  77. $this->placeholders['{order_billing_full_name}'] = $this->object->get_formatted_billing_full_name();
  78. }
  79. if ( $this->is_enabled() && $this->get_recipient() ) {
  80. $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
  81. }
  82. $this->restore_locale();
  83. }
  84. /**
  85. * Get content html.
  86. *
  87. * @return string
  88. */
  89. public function get_content_html() {
  90. return wc_get_template_html(
  91. $this->template_html,
  92. array(
  93. 'order' => $this->object,
  94. 'email_heading' => $this->get_heading(),
  95. 'additional_content' => $this->get_additional_content(),
  96. 'sent_to_admin' => true,
  97. 'plain_text' => false,
  98. 'email' => $this,
  99. )
  100. );
  101. }
  102. /**
  103. * Get content plain.
  104. *
  105. * @return string
  106. */
  107. public function get_content_plain() {
  108. return wc_get_template_html(
  109. $this->template_plain,
  110. array(
  111. 'order' => $this->object,
  112. 'email_heading' => $this->get_heading(),
  113. 'additional_content' => $this->get_additional_content(),
  114. 'sent_to_admin' => true,
  115. 'plain_text' => true,
  116. 'email' => $this,
  117. )
  118. );
  119. }
  120. /**
  121. * Default content to show below main email content.
  122. *
  123. * @since 3.7.0
  124. * @return string
  125. */
  126. public function get_default_additional_content() {
  127. return __( 'Thanks for reading.', 'woocommerce' );
  128. }
  129. /**
  130. * Initialise settings form fields.
  131. */
  132. public function init_form_fields() {
  133. /* translators: %s: list of placeholders */
  134. $placeholder_text = sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>' . esc_html( implode( '</code>, <code>', array_keys( $this->placeholders ) ) ) . '</code>' );
  135. $this->form_fields = array(
  136. 'enabled' => array(
  137. 'title' => __( 'Enable/Disable', 'woocommerce' ),
  138. 'type' => 'checkbox',
  139. 'label' => __( 'Enable this email notification', 'woocommerce' ),
  140. 'default' => 'yes',
  141. ),
  142. 'recipient' => array(
  143. 'title' => __( 'Recipient(s)', 'woocommerce' ),
  144. 'type' => 'text',
  145. /* translators: %s: admin email */
  146. 'description' => sprintf( __( 'Enter recipients (comma separated) for this email. Defaults to %s.', 'woocommerce' ), '<code>' . esc_attr( get_option( 'admin_email' ) ) . '</code>' ),
  147. 'placeholder' => '',
  148. 'default' => '',
  149. 'desc_tip' => true,
  150. ),
  151. 'subject' => array(
  152. 'title' => __( 'Subject', 'woocommerce' ),
  153. 'type' => 'text',
  154. 'desc_tip' => true,
  155. 'description' => $placeholder_text,
  156. 'placeholder' => $this->get_default_subject(),
  157. 'default' => '',
  158. ),
  159. 'heading' => array(
  160. 'title' => __( 'Email heading', 'woocommerce' ),
  161. 'type' => 'text',
  162. 'desc_tip' => true,
  163. 'description' => $placeholder_text,
  164. 'placeholder' => $this->get_default_heading(),
  165. 'default' => '',
  166. ),
  167. 'additional_content' => array(
  168. 'title' => __( 'Additional content', 'woocommerce' ),
  169. 'description' => __( 'Text to appear below the main email content.', 'woocommerce' ) . ' ' . $placeholder_text,
  170. 'css' => 'width:400px; height: 75px;',
  171. 'placeholder' => __( 'N/A', 'woocommerce' ),
  172. 'type' => 'textarea',
  173. 'default' => $this->get_default_additional_content(),
  174. 'desc_tip' => true,
  175. ),
  176. 'email_type' => array(
  177. 'title' => __( 'Email type', 'woocommerce' ),
  178. 'type' => 'select',
  179. 'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
  180. 'default' => 'html',
  181. 'class' => 'email_type wc-enhanced-select',
  182. 'options' => $this->get_email_type_options(),
  183. 'desc_tip' => true,
  184. ),
  185. );
  186. }
  187. }
  188. endif;
  189. return new WC_Email_Cancelled_Order();