/includes/emails/class-wc-email-customer-refunded-order.php

  1. <?php 
  2.  
  3. if ( ! defined( 'ABSPATH' ) ) { 
  4. exit; // Exit if accessed directly 
  5.  
  6. if ( ! class_exists( 'WC_Email_Customer_Refunded_Order', false ) ) : 
  7.  
  8. /** 
  9. * Customer Refunded Order Email. 
  10. * 
  11. * Order refunded emails are sent to the customer when the order is marked refunded. 
  12. * 
  13. * @class WC_Email_Customer_Refunded_Order 
  14. * @version 2.4.0 
  15. * @package WooCommerce/Classes/Emails 
  16. * @author WooThemes 
  17. * @extends WC_Email 
  18. */ 
  19. class WC_Email_Customer_Refunded_Order extends WC_Email { 
  20.  
  21. /** 
  22. * Refund order. 
  23. * 
  24. * @var WC_Order|bool 
  25. */ 
  26. public $refund; 
  27.  
  28. /** 
  29. * Is the order partial refunded? 
  30. * 
  31. * @var bool 
  32. */ 
  33. public $partial_refund; 
  34.  
  35. /** 
  36. * Constructor. 
  37. */ 
  38. public function __construct() { 
  39. $this->set_email_strings(); 
  40. $this->customer_email = true; 
  41.  
  42. // Triggers for this email 
  43. add_action( 'woocommerce_order_fully_refunded_notification', array( $this, 'trigger_full' ), 10, 2 ); 
  44. add_action( 'woocommerce_order_partially_refunded_notification', array( $this, 'trigger_partial' ), 10, 2 ); 
  45.  
  46. // Call parent constuctor 
  47. parent::__construct(); 
  48.  
  49. /** 
  50. * Set email strings. 
  51. * 
  52. * @param bool $partial_refund 
  53. */ 
  54. public function set_email_strings( $partial_refund = false ) { 
  55. $this->subject_partial = $this->get_option( 'subject_partial', __( 'Your {site_title} order from {order_date} has been partially refunded', 'woocommerce' ) ); 
  56. $this->subject_full = $this->get_option( 'subject_full', __( 'Your {site_title} order from {order_date} has been refunded', 'woocommerce' ) ); 
  57.  
  58. $this->heading_full = $this->get_option( 'heading_full', __( 'Your order has been fully refunded', 'woocommerce' ) ); 
  59. $this->heading_partial = $this->get_option( 'heading_partial', __( 'Your order has been partially refunded', 'woocommerce' ) ); 
  60.  
  61. $this->template_html = 'emails/customer-refunded-order.php'; 
  62. $this->template_plain = 'emails/plain/customer-refunded-order.php'; 
  63.  
  64. if ( $partial_refund ) { 
  65. $this->id = 'customer_partially_refunded_order'; 
  66. $this->title = __( 'Partially refunded order', 'woocommerce' ); 
  67. $this->description = __( 'Order partially refunded emails are sent to customers when their orders are partially refunded.', 'woocommerce' ); 
  68. $this->heading = $this->heading_partial; 
  69. $this->subject = $this->subject_partial; 
  70. } else { 
  71. $this->id = 'customer_refunded_order'; 
  72. $this->title = __( 'Refunded order', 'woocommerce' ); 
  73. $this->description = __( 'Order refunded emails are sent to customers when their orders are marked refunded.', 'woocommerce' ); 
  74. $this->heading = $this->heading_full; 
  75. $this->subject = $this->subject_full; 
  76.  
  77. /** 
  78. * Full refund notification. 
  79. * 
  80. * @param int $order_id 
  81. * @param int $refund_id 
  82. */ 
  83. public function trigger_full( $order_id, $refund_id = null ) { 
  84. $this->trigger( $order_id, false, $refund_id ); 
  85.  
  86. /** 
  87. * Partial refund notification. 
  88. * 
  89. * @param int $order_id 
  90. * @param int $refund_id 
  91. */ 
  92. public function trigger_partial( $order_id, $refund_id = null ) { 
  93. $this->trigger( $order_id, true, $refund_id ); 
  94.  
  95. /** 
  96. * Trigger. 
  97. * 
  98. * @param int $order_id 
  99. * @param bool $partial_refund 
  100. * @param int $refund_id 
  101. */ 
  102. public function trigger( $order_id, $partial_refund = false, $refund_id = null ) { 
  103. $this->partial_refund = $partial_refund; 
  104. $this->set_email_strings( $partial_refund ); 
  105.  
  106. if ( $order_id ) { 
  107. $this->object = wc_get_order( $order_id ); 
  108. $this->recipient = $this->object->get_billing_email(); 
  109.  
  110. $this->find['order-date'] = '{order_date}'; 
  111. $this->find['order-number'] = '{order_number}'; 
  112.  
  113. $this->replace['order-date'] = wc_format_datetime( $this->object->get_date_created() ); 
  114. $this->replace['order-number'] = $this->object->get_order_number(); 
  115.  
  116. if ( ! empty( $refund_id ) ) { 
  117. $this->refund = wc_get_order( $refund_id ); 
  118. } else { 
  119. $this->refund = false; 
  120.  
  121. if ( ! $this->is_enabled() || ! $this->get_recipient() ) { 
  122. return; 
  123.  
  124. $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() ); 
  125.  
  126. /** 
  127. * Get email subject. 
  128. * 
  129. * @access public 
  130. * @return string 
  131. */ 
  132. public function get_subject() { 
  133. return apply_filters( 'woocommerce_email_subject_customer_refunded_order', $this->format_string( $this->subject ), $this->object ); 
  134.  
  135. /** 
  136. * Get email heading. 
  137. * 
  138. * @access public 
  139. * @return string 
  140. */ 
  141. public function get_heading() { 
  142. return apply_filters( 'woocommerce_email_heading_customer_refunded_order', $this->format_string( $this->heading ), $this->object ); 
  143.  
  144. /** 
  145. * Get content html. 
  146. * 
  147. * @access public 
  148. * @return string 
  149. */ 
  150. public function get_content_html() { 
  151. return wc_get_template_html( $this->template_html, array( 
  152. 'order' => $this->object,  
  153. 'refund' => $this->refund,  
  154. 'partial_refund' => $this->partial_refund,  
  155. 'email_heading' => $this->get_heading(),  
  156. 'sent_to_admin' => false,  
  157. 'plain_text' => false,  
  158. 'email' => $this,  
  159. ) ); 
  160.  
  161. /** 
  162. * Get content plain. 
  163. * 
  164. * @return string 
  165. */ 
  166. public function get_content_plain() { 
  167. return wc_get_template_html( $this->template_plain, array( 
  168. 'order' => $this->object,  
  169. 'refund' => $this->refund,  
  170. 'partial_refund' => $this->partial_refund,  
  171. 'email_heading' => $this->get_heading(),  
  172. 'sent_to_admin' => false,  
  173. 'plain_text' => true,  
  174. 'email' => $this,  
  175. ) ); 
  176.  
  177. /** 
  178. * Initialise settings form fields. 
  179. */ 
  180. public function init_form_fields() { 
  181. $this->form_fields = array( 
  182. 'enabled' => array( 
  183. 'title' => __( 'Enable/Disable', 'woocommerce' ),  
  184. 'type' => 'checkbox',  
  185. 'label' => __( 'Enable this email notification', 'woocommerce' ),  
  186. 'default' => 'yes',  
  187. ),  
  188. 'subject_full' => array( 
  189. 'title' => __( 'Full refund subject', 'woocommerce' ),  
  190. 'type' => 'text',  
  191. /** translators: %s: default subject */ 
  192. 'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->subject_full . '</code>' ),  
  193. 'placeholder' => '',  
  194. 'default' => $this->subject_full,  
  195. 'desc_tip' => true,  
  196. ),  
  197. 'subject_partial' => array( 
  198. 'title' => __( 'Partial refund subject', 'woocommerce' ),  
  199. 'type' => 'text',  
  200. /** translators: %s: default subject */ 
  201. 'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->subject_partial . '</code>' ),  
  202. 'placeholder' => '',  
  203. 'default' => $this->subject_partial,  
  204. 'desc_tip' => true,  
  205. ),  
  206. 'heading_full' => array( 
  207. 'title' => __( 'Full refund email heading', 'woocommerce' ),  
  208. 'type' => 'text',  
  209. /** translators: %s: default heading */ 
  210. 'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->heading_full . '</code>' ),  
  211. 'placeholder' => '',  
  212. 'default' => $this->heading_full,  
  213. 'desc_tip' => true,  
  214. ),  
  215. 'heading_partial' => array( 
  216. 'title' => __( 'Partial refund email heading', 'woocommerce' ),  
  217. 'type' => 'text',  
  218. /** translators: %s: default heading */ 
  219. 'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->heading_partial . '</code>' ),  
  220. 'placeholder' => '',  
  221. 'default' => $this->heading_partial,  
  222. 'desc_tip' => true,  
  223. ),  
  224. 'email_type' => array( 
  225. 'title' => __( 'Email type', 'woocommerce' ),  
  226. 'type' => 'select',  
  227. 'description' => __( 'Choose which format of email to send.', 'woocommerce' ),  
  228. 'default' => 'html',  
  229. 'class' => 'email_type wc-enhanced-select',  
  230. 'options' => $this->get_email_type_options(),  
  231. 'desc_tip' => true,  
  232. ),  
  233. ); 
  234.  
  235. endif; 
  236.  
  237. return new WC_Email_Customer_Refunded_Order(); 
.