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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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 2.4.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. '{site_title}' => $this->get_blogname(),
  46. '{order_date}' => '',
  47. '{order_number}' => '',
  48. );
  49. // Triggers for this email.
  50. add_action( 'woocommerce_order_fully_refunded_notification', array( $this, 'trigger_full' ), 10, 2 );
  51. add_action( 'woocommerce_order_partially_refunded_notification', array( $this, 'trigger_partial' ), 10, 2 );
  52. // Call parent constructor.
  53. parent::__construct();
  54. }
  55. /**
  56. * Get email subject.
  57. *
  58. * @param bool $partial Whether it is a partial refund or a full refund.
  59. * @since 3.1.0
  60. * @return string
  61. */
  62. public function get_default_subject( $partial = false ) {
  63. if ( $partial ) {
  64. return __( 'Your {site_title} order from {order_date} has been partially refunded', 'woocommerce' );
  65. } else {
  66. return __( 'Your {site_title} order from {order_date} has been refunded', 'woocommerce' );
  67. }
  68. }
  69. /**
  70. * Get email heading.
  71. *
  72. * @param bool $partial Whether it is a partial refund or a full refund.
  73. * @since 3.1.0
  74. * @return string
  75. */
  76. public function get_default_heading( $partial = false ) {
  77. if ( $partial ) {
  78. return __( 'Your order has been partially refunded', 'woocommerce' );
  79. } else {
  80. return __( 'Order {order_number} details', 'woocommerce' );
  81. }
  82. }
  83. /**
  84. * Get email subject.
  85. *
  86. * @access public
  87. * @return string
  88. */
  89. public function get_subject() {
  90. if ( $this->partial_refund ) {
  91. $subject = $this->get_option( 'subject_partial', $this->get_default_subject( true ) );
  92. } else {
  93. $subject = $this->get_option( 'subject_full', $this->get_default_subject() );
  94. }
  95. return apply_filters( 'woocommerce_email_subject_customer_refunded_order', $this->format_string( $subject ), $this->object );
  96. }
  97. /**
  98. * Get email heading.
  99. *
  100. * @access public
  101. * @return string
  102. */
  103. public function get_heading() {
  104. if ( $this->partial_refund ) {
  105. $heading = $this->get_option( 'heading_partial', $this->get_default_heading( true ) );
  106. } else {
  107. $heading = $this->get_option( 'heading_full', $this->get_default_heading() );
  108. }
  109. return apply_filters( 'woocommerce_email_heading_customer_refunded_order', $this->format_string( $heading ), $this->object );
  110. }
  111. /**
  112. * Set email strings.
  113. *
  114. * @param bool $partial_refund Whether it is a partial refund or a full refund.
  115. * @deprecated 3.1.0 Unused.
  116. */
  117. public function set_email_strings( $partial_refund = false ) {}
  118. /**
  119. * Full refund notification.
  120. *
  121. * @param int $order_id Order ID.
  122. * @param int $refund_id Refund ID.
  123. */
  124. public function trigger_full( $order_id, $refund_id = null ) {
  125. $this->trigger( $order_id, false, $refund_id );
  126. }
  127. /**
  128. * Partial refund notification.
  129. *
  130. * @param int $order_id Order ID.
  131. * @param int $refund_id Refund ID.
  132. */
  133. public function trigger_partial( $order_id, $refund_id = null ) {
  134. $this->trigger( $order_id, true, $refund_id );
  135. }
  136. /**
  137. * Trigger.
  138. *
  139. * @param int $order_id Order ID.
  140. * @param bool $partial_refund Whether it is a partial refund or a full refund.
  141. * @param int $refund_id Refund ID.
  142. */
  143. public function trigger( $order_id, $partial_refund = false, $refund_id = null ) {
  144. $this->setup_locale();
  145. $this->partial_refund = $partial_refund;
  146. $this->id = $this->partial_refund ? 'customer_partially_refunded_order' : 'customer_refunded_order';
  147. if ( $order_id ) {
  148. $this->object = wc_get_order( $order_id );
  149. $this->recipient = $this->object->get_billing_email();
  150. $this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
  151. $this->placeholders['{order_number}'] = $this->object->get_order_number();
  152. }
  153. if ( ! empty( $refund_id ) ) {
  154. $this->refund = wc_get_order( $refund_id );
  155. } else {
  156. $this->refund = false;
  157. }
  158. if ( $this->is_enabled() && $this->get_recipient() ) {
  159. $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
  160. }
  161. $this->restore_locale();
  162. }
  163. /**
  164. * Get content html.
  165. *
  166. * @access public
  167. * @return string
  168. */
  169. public function get_content_html() {
  170. return wc_get_template_html(
  171. $this->template_html, array(
  172. 'order' => $this->object,
  173. 'refund' => $this->refund,
  174. 'partial_refund' => $this->partial_refund,
  175. 'email_heading' => $this->get_heading(),
  176. 'sent_to_admin' => false,
  177. 'plain_text' => false,
  178. 'email' => $this,
  179. )
  180. );
  181. }
  182. /**
  183. * Get content plain.
  184. *
  185. * @return string
  186. */
  187. public function get_content_plain() {
  188. return wc_get_template_html(
  189. $this->template_plain, array(
  190. 'order' => $this->object,
  191. 'refund' => $this->refund,
  192. 'partial_refund' => $this->partial_refund,
  193. 'email_heading' => $this->get_heading(),
  194. 'sent_to_admin' => false,
  195. 'plain_text' => true,
  196. 'email' => $this,
  197. )
  198. );
  199. }
  200. /**
  201. * Initialise settings form fields.
  202. */
  203. public function init_form_fields() {
  204. $this->form_fields = array(
  205. 'enabled' => array(
  206. 'title' => __( 'Enable/Disable', 'woocommerce' ),
  207. 'type' => 'checkbox',
  208. 'label' => __( 'Enable this email notification', 'woocommerce' ),
  209. 'default' => 'yes',
  210. ),
  211. 'subject_full' => array(
  212. 'title' => __( 'Full refund subject', 'woocommerce' ),
  213. 'type' => 'text',
  214. 'desc_tip' => true,
  215. /* translators: %s: list of placeholders */
  216. 'description' => sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>{site_title}, {order_date}, {order_number}</code>' ),
  217. 'placeholder' => $this->get_default_subject(),
  218. 'default' => '',
  219. ),
  220. 'subject_partial' => array(
  221. 'title' => __( 'Partial refund subject', 'woocommerce' ),
  222. 'type' => 'text',
  223. 'desc_tip' => true,
  224. /* translators: %s: list of placeholders */
  225. 'description' => sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>{site_title}, {order_date}, {order_number}</code>' ),
  226. 'placeholder' => $this->get_default_subject( true ),
  227. 'default' => '',
  228. ),
  229. 'heading_full' => array(
  230. 'title' => __( 'Full refund email heading', 'woocommerce' ),
  231. 'type' => 'text',
  232. 'desc_tip' => true,
  233. /* translators: %s: list of placeholders */
  234. 'description' => sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>{site_title}, {order_date}, {order_number}</code>' ),
  235. 'placeholder' => $this->get_default_heading(),
  236. 'default' => '',
  237. ),
  238. 'heading_partial' => array(
  239. 'title' => __( 'Partial refund email heading', 'woocommerce' ),
  240. 'type' => 'text',
  241. 'desc_tip' => true,
  242. /* translators: %s: list of placeholders */
  243. 'description' => sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>{site_title}, {order_date}, {order_number}</code>' ),
  244. 'placeholder' => $this->get_default_heading( true ),
  245. 'default' => '',
  246. ),
  247. 'email_type' => array(
  248. 'title' => __( 'Email type', 'woocommerce' ),
  249. 'type' => 'select',
  250. 'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
  251. 'default' => 'html',
  252. 'class' => 'email_type wc-enhanced-select',
  253. 'options' => $this->get_email_type_options(),
  254. 'desc_tip' => true,
  255. ),
  256. );
  257. }
  258. }
  259. endif;
  260. return new WC_Email_Customer_Refunded_Order();