WC_Order_Refund

Order refund.

Defined (1)

The class is defined in the following location(s).

/includes/class-wc-order-refund.php  
  1. class WC_Order_Refund extends WC_Abstract_Order { 
  2.  
  3. /** 
  4. * Which data store to load. 
  5. * @var string 
  6. */ 
  7. protected $data_store_name = 'order-refund'; 
  8.  
  9. /** 
  10. * This is the name of this object type. 
  11. * @var string 
  12. */ 
  13. protected $object_type = 'order_refund'; 
  14.  
  15. /** 
  16. * Stores product data. 
  17. * @var array 
  18. */ 
  19. protected $extra_data = array( 
  20. 'amount' => '',  
  21. 'reason' => '',  
  22. 'refunded_by' => 0,  
  23. ); 
  24.  
  25. /** 
  26. * Get internal type (post type.) 
  27. * @return string 
  28. */ 
  29. public function get_type() { 
  30. return 'shop_order_refund'; 
  31.  
  32. /** 
  33. * Get status - always completed for refunds. 
  34. * @param string $context 
  35. * @return string 
  36. */ 
  37. public function get_status( $context = 'view' ) { 
  38. return 'completed'; 
  39.  
  40. /** 
  41. * Get a title for the new post type. 
  42. */ 
  43. public function get_post_title() { 
  44. // @codingStandardsIgnoreStart 
  45. return sprintf( __( 'Refund – %s', 'woocommerce' ), strftime( _x( '%b %d, %Y @ %I:%M %p', 'Order date parsed by strftime', 'woocommerce' ) ) ); 
  46. // @codingStandardsIgnoreEnd 
  47.  
  48. /** 
  49. * Get refunded amount. 
  50. * @param string $context 
  51. * @return int|float 
  52. */ 
  53. public function get_amount( $context = 'view' ) { 
  54. return $this->get_prop( 'amount', $context ); 
  55.  
  56. /** 
  57. * Get refund reason. 
  58. * @since 2.2 
  59. * @param string $context 
  60. * @return int|float 
  61. */ 
  62. public function get_reason( $context = 'view' ) { 
  63. return $this->get_prop( 'reason', $context ); 
  64.  
  65. /** 
  66. * Get ID of user who did the refund. 
  67. * @since 3.0 
  68. * @param string $context 
  69. * @return int 
  70. */ 
  71. public function get_refunded_by( $context = 'view' ) { 
  72. return $this->get_prop( 'refunded_by', $context ); 
  73.  
  74.  
  75. /** 
  76. * Get formatted refunded amount. 
  77. * @since 2.4 
  78. * @return string 
  79. */ 
  80. public function get_formatted_refund_amount() { 
  81. return apply_filters( 'woocommerce_formatted_refund_amount', wc_price( $this->get_amount(), array( 'currency' => $this->get_currency() ) ), $this ); 
  82.  
  83. /** 
  84. * Set refunded amount. 
  85. * @param string $value 
  86. * @throws WC_Data_Exception 
  87. */ 
  88. public function set_amount( $value ) { 
  89. $this->set_prop( 'amount', wc_format_decimal( $value ) ); 
  90.  
  91. /** 
  92. * Set refund reason. 
  93. * @param string $value 
  94. * @throws WC_Data_Exception 
  95. */ 
  96. public function set_reason( $value ) { 
  97. $this->set_prop( 'reason', $value ); 
  98.  
  99. /** 
  100. * Set refunded by. 
  101. * @param int $value 
  102. * @throws WC_Data_Exception 
  103. */ 
  104. public function set_refunded_by( $value ) { 
  105. $this->set_prop( 'refunded_by', absint( $value ) ); 
  106.  
  107. /** 
  108. * Magic __get method for backwards compatibility. 
  109. * @param string $key 
  110. * @return mixed 
  111. */ 
  112. public function __get( $key ) { 
  113. wc_doing_it_wrong( $key, 'Refund properties should not be accessed directly.', '3.0' ); 
  114. /** 
  115. * Maps legacy vars to new getters. 
  116. */ 
  117. if ( 'reason' === $key ) { 
  118. return $this->get_reason(); 
  119. } elseif ( 'refund_amount' === $key ) { 
  120. return $this->get_amount(); 
  121. return parent::__get( $key ); 
  122.  
  123. /** 
  124. * Gets an refund from the database. 
  125. * @deprecated 3.0 
  126. * @param int $id (default: 0). 
  127. * @return bool 
  128. */ 
  129. public function get_refund( $id = 0 ) { 
  130. wc_deprecated_function( 'get_refund', '3.0', 'read' ); 
  131. if ( ! $id ) { 
  132. return false; 
  133. if ( $result = get_post( $id ) ) { 
  134. $this->populate( $result ); 
  135. return true; 
  136. return false; 
  137.  
  138. /** 
  139. * Get refund amount. 
  140. * @deprecated 3.0 
  141. * @return int|float 
  142. */ 
  143. public function get_refund_amount() { 
  144. wc_deprecated_function( 'get_refund_amount', '3.0', 'get_amount' ); 
  145. return $this->get_amount(); 
  146.  
  147. /** 
  148. * Get refund reason. 
  149. * @deprecated 3.0 
  150. * @return int|float 
  151. */ 
  152. public function get_refund_reason() { 
  153. wc_deprecated_function( 'get_refund_reason', '3.0', 'get_reason' ); 
  154. return $this->get_reason();