Brak opisu

class-wc-email-customer-refunded-order.php 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <?php
  2. /**
  3. * Class WC_Email_Customer_Refunded_Order 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_Refunded_Order', false ) ) :
  11. /**
  12. * Customer Refunded Order Email.
  13. *
  14. * Order refunded emails are sent to the customer when the order is marked refunded.
  15. *
  16. * @class WC_Email_Customer_Refunded_Order
  17. * @version 3.5.0
  18. * @package WooCommerce\Classes\Emails
  19. * @extends WC_Email
  20. */
  21. class WC_Email_Customer_Refunded_Order extends WC_Email {
  22. /**
  23. * Refund order.
  24. *
  25. * @var WC_Order|bool
  26. */
  27. public $refund;
  28. /**
  29. * Is the order partial refunded?
  30. *
  31. * @var bool
  32. */
  33. public $partial_refund;
  34. /**
  35. * Constructor.
  36. */
  37. public function __construct() {
  38. $this->customer_email = true;
  39. $this->id = 'customer_refunded_order';
  40. $this->title = __( 'Refunded order', 'woocommerce' );
  41. $this->description = __( 'Order refunded emails are sent to customers when their orders are refunded.', 'woocommerce' );
  42. $this->template_html = 'emails/customer-refunded-order.php';
  43. $this->template_plain = 'emails/plain/customer-refunded-order.php';
  44. $this->placeholders = array(
  45. '{order_date}' => '',
  46. '{order_number}' => '',
  47. );
  48. // Triggers for this email.
  49. add_action( 'woocommerce_order_fully_refunded_notification', array( $this, 'trigger_full' ), 10, 2 );
  50. add_action( 'woocommerce_order_partially_refunded_notification', array( $this, 'trigger_partial' ), 10, 2 );
  51. // Call parent constructor.
  52. parent::__construct();
  53. }
  54. /**
  55. * Get email subject.
  56. *
  57. * @param bool $partial Whether it is a partial refund or a full refund.
  58. * @since 3.1.0
  59. * @return string
  60. */
  61. public function get_default_subject( $partial = false ) {
  62. if ( $partial ) {
  63. return __( 'Your {site_title} order #{order_number} has been partially refunded', 'woocommerce' );
  64. } else {
  65. return __( 'Your {site_title} order #{order_number} has been refunded', 'woocommerce' );
  66. }
  67. }
  68. /**
  69. * Get email heading.
  70. *
  71. * @param bool $partial Whether it is a partial refund or a full refund.
  72. * @since 3.1.0
  73. * @return string
  74. */
  75. public function get_default_heading( $partial = false ) {
  76. if ( $partial ) {
  77. return __( 'Partial Refund: Order {order_number}', 'woocommerce' );
  78. } else {
  79. return __( 'Order Refunded: {order_number}', 'woocommerce' );
  80. }
  81. }
  82. /**
  83. * Get email subject.
  84. *
  85. * @return string
  86. */
  87. public function get_subject() {
  88. if ( $this->partial_refund ) {
  89. $subject = $this->get_option( 'subject_partial', $this->get_default_subject( true ) );
  90. } else {
  91. $subject = $this->get_option( 'subject_full', $this->get_default_subject() );
  92. }
  93. return apply_filters( 'woocommerce_email_subject_customer_refunded_order', $this->format_string( $subject ), $this->object, $this );
  94. }
  95. /**
  96. * Get email heading.
  97. *
  98. * @return string
  99. */
  100. public function get_heading() {
  101. if ( $this->partial_refund ) {
  102. $heading = $this->get_option( 'heading_partial', $this->get_default_heading( true ) );
  103. } else {
  104. $heading = $this->get_option( 'heading_full', $this->get_default_heading() );
  105. }
  106. return apply_filters( 'woocommerce_email_heading_customer_refunded_order', $this->format_string( $heading ), $this->object, $this );
  107. }
  108. /**
  109. * Set email strings.
  110. *
  111. * @param bool $partial_refund Whether it is a partial refund or a full refund.
  112. * @deprecated 3.1.0 Unused.
  113. */
  114. public function set_email_strings( $partial_refund = false ) {}
  115. /**
  116. * Full refund notification.
  117. *
  118. * @param int $order_id Order ID.
  119. * @param int $refund_id Refund ID.
  120. */
  121. public function trigger_full( $order_id, $refund_id = null ) {
  122. $this->trigger( $order_id, false, $refund_id );
  123. }
  124. /**
  125. * Partial refund notification.
  126. *
  127. * @param int $order_id Order ID.
  128. * @param int $refund_id Refund ID.
  129. */
  130. public function trigger_partial( $order_id, $refund_id = null ) {
  131. $this->trigger( $order_id, true, $refund_id );
  132. }
  133. /**
  134. * Trigger.
  135. *
  136. * @param int $order_id Order ID.
  137. * @param bool $partial_refund Whether it is a partial refund or a full refund.
  138. * @param int $refund_id Refund ID.
  139. */
  140. public function trigger( $order_id, $partial_refund = false, $refund_id = null ) {
  141. $this->setup_locale();
  142. $this->partial_refund = $partial_refund;
  143. $this->id = $this->partial_refund ? 'customer_partially_refunded_order' : 'customer_refunded_order';
  144. if ( $order_id ) {
  145. $this->object = wc_get_order( $order_id );
  146. $this->recipient = $this->object->get_billing_email();
  147. $this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
  148. $this->placeholders['{order_number}'] = $this->object->get_order_number();
  149. }
  150. if ( ! empty( $refund_id ) ) {
  151. $this->refund = wc_get_order( $refund_id );
  152. } else {
  153. $this->refund = false;
  154. }
  155. if ( $this->is_enabled() && $this->get_recipient() ) {
  156. $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
  157. }
  158. $this->restore_locale();
  159. }
  160. /**
  161. * Get content html.
  162. *
  163. * @return string
  164. */
  165. public function get_content_html() {
  166. return wc_get_template_html(
  167. $this->template_html,
  168. array(
  169. 'order' => $this->object,
  170. 'refund' => $this->refund,
  171. 'partial_refund' => $this->partial_refund,
  172. 'email_heading' => $this->get_heading(),
  173. 'additional_content' => $this->get_additional_content(),
  174. 'sent_to_admin' => false,
  175. 'plain_text' => false,
  176. 'email' => $this,
  177. )
  178. );
  179. }
  180. /**
  181. * Get content plain.
  182. *
  183. * @return string
  184. */
  185. public function get_content_plain() {
  186. return wc_get_template_html(
  187. $this->template_plain,
  188. array(
  189. 'order' => $this->object,
  190. 'refund' => $this->refund,
  191. 'partial_refund' => $this->partial_refund,
  192. 'email_heading' => $this->get_heading(),
  193. 'additional_content' => $this->get_additional_content(),
  194. 'sent_to_admin' => false,
  195. 'plain_text' => true,
  196. 'email' => $this,
  197. )
  198. );
  199. }
  200. /**
  201. * Default content to show below main email content.
  202. *
  203. * @since 3.7.0
  204. * @return string
  205. */
  206. public function get_default_additional_content() {
  207. return __( 'We hope to see you again soon.', 'woocommerce' );
  208. }
  209. /**
  210. * Initialise settings form fields.
  211. */
  212. public function init_form_fields() {
  213. /* translators: %s: list of placeholders */
  214. $placeholder_text = sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>' . esc_html( implode( '</code>, <code>', array_keys( $this->placeholders ) ) ) . '</code>' );
  215. $this->form_fields = array(
  216. 'enabled' => array(
  217. 'title' => __( 'Enable/Disable', 'woocommerce' ),
  218. 'type' => 'checkbox',
  219. 'label' => __( 'Enable this email notification', 'woocommerce' ),
  220. 'default' => 'yes',
  221. ),
  222. 'subject_full' => array(
  223. 'title' => __( 'Full refund subject', 'woocommerce' ),
  224. 'type' => 'text',
  225. 'desc_tip' => true,
  226. 'description' => $placeholder_text,
  227. 'placeholder' => $this->get_default_subject(),
  228. 'default' => '',
  229. ),
  230. 'subject_partial' => array(
  231. 'title' => __( 'Partial refund subject', 'woocommerce' ),
  232. 'type' => 'text',
  233. 'desc_tip' => true,
  234. 'description' => $placeholder_text,
  235. 'placeholder' => $this->get_default_subject( true ),
  236. 'default' => '',
  237. ),
  238. 'heading_full' => array(
  239. 'title' => __( 'Full refund email heading', 'woocommerce' ),
  240. 'type' => 'text',
  241. 'desc_tip' => true,
  242. 'description' => $placeholder_text,
  243. 'placeholder' => $this->get_default_heading(),
  244. 'default' => '',
  245. ),
  246. 'heading_partial' => array(
  247. 'title' => __( 'Partial refund email heading', 'woocommerce' ),
  248. 'type' => 'text',
  249. 'desc_tip' => true,
  250. 'description' => $placeholder_text,
  251. 'placeholder' => $this->get_default_heading( true ),
  252. 'default' => '',
  253. ),
  254. 'additional_content' => array(
  255. 'title' => __( 'Additional content', 'woocommerce' ),
  256. 'description' => __( 'Text to appear below the main email content.', 'woocommerce' ) . ' ' . $placeholder_text,
  257. 'css' => 'width:400px; height: 75px;',
  258. 'placeholder' => __( 'N/A', 'woocommerce' ),
  259. 'type' => 'textarea',
  260. 'default' => $this->get_default_additional_content(),
  261. 'desc_tip' => true,
  262. ),
  263. 'email_type' => array(
  264. 'title' => __( 'Email type', 'woocommerce' ),
  265. 'type' => 'select',
  266. 'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
  267. 'default' => 'html',
  268. 'class' => 'email_type wc-enhanced-select',
  269. 'options' => $this->get_email_type_options(),
  270. 'desc_tip' => true,
  271. ),
  272. );
  273. }
  274. }
  275. endif;
  276. return new WC_Email_Customer_Refunded_Order();