WC_Order_Refund_Data_Store_CPT

WC Order Refund Data Store: Stored in CPT.

Defined (1)

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

/includes/data-stores/class-wc-order-refund-data-store-cpt.php  
  1. class WC_Order_Refund_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implements WC_Object_Data_Store_Interface, WC_Order_Refund_Data_Store_Interface { 
  2.  
  3. /** 
  4. * Data stored in meta keys, but not considered "meta" for an order. 
  5. * @since 3.0.0 
  6. * @var array 
  7. */ 
  8. protected $internal_meta_keys = array( 
  9. '_order_currency',  
  10. '_cart_discount',  
  11. '_refund_amount',  
  12. '_refunded_by',  
  13. '_refund_reason',  
  14. '_cart_discount_tax',  
  15. '_order_shipping',  
  16. '_order_shipping_tax',  
  17. '_order_tax',  
  18. '_order_total',  
  19. '_order_version',  
  20. '_prices_include_tax',  
  21. '_payment_tokens',  
  22. ); 
  23.  
  24. /** 
  25. * Delete a refund - no trash is supported. 
  26. * @param WC_Order $order 
  27. * @param array $args Array of args to pass to the delete method. 
  28. */ 
  29. public function delete( &$order, $args = array() ) { 
  30. $id = $order->get_id(); 
  31.  
  32. wp_delete_post( $id ); 
  33. $order->set_id( 0 ); 
  34. do_action( 'woocommerce_delete_order_refund', $id ); 
  35.  
  36. /** 
  37. * Read refund data. Can be overridden by child classes to load other props. 
  38. * @param WC_Order $refund 
  39. * @param object $post_object 
  40. * @since 3.0.0 
  41. */ 
  42. protected function read_order_data( &$refund, $post_object ) { 
  43. parent::read_order_data( $refund, $post_object ); 
  44. $id = $refund->get_id(); 
  45. $refund->set_props( array( 
  46. 'amount' => get_post_meta( $id, '_refund_amount', true ),  
  47. 'refunded_by' => metadata_exists( 'post', $id, '_refunded_by' ) ? get_post_meta( $id, '_refunded_by', true ) : absint( $post_object->post_author ),  
  48. 'reason' => metadata_exists( 'post', $id, '_refund_reason' ) ? get_post_meta( $id, '_refund_reason', true ) : $post_object->post_excerpt,  
  49. ) ); 
  50.  
  51. /** 
  52. * Helper method that updates all the post meta for an order based on it's settings in the WC_Order class. 
  53. * @param WC_Order 
  54. * @param WC_Order $refund 
  55. * @since 3.0.0 
  56. */ 
  57. protected function update_post_meta( &$refund ) { 
  58. parent::update_post_meta( $refund ); 
  59.  
  60. $updated_props = array(); 
  61. $meta_key_to_props = array( 
  62. '_refund_amount' => 'amount',  
  63. '_refunded_by' => 'refunded_by',  
  64. '_refund_reason' => 'reason',  
  65. ); 
  66.  
  67. $props_to_update = $this->get_props_to_update( $refund, $meta_key_to_props ); 
  68. foreach ( $props_to_update as $meta_key => $prop ) { 
  69. $value = $refund->{"get_$prop"}( 'edit' ); 
  70. update_post_meta( $refund->get_id(), $meta_key, $value ); 
  71. $updated_props[] = $prop; 
  72.  
  73. do_action( 'woocommerce_order_refund_object_updated_props', $refund, $updated_props ); 
  74.  
  75. /** 
  76. * Get a title for the new post type. 
  77. * @return string 
  78. */ 
  79. protected function get_post_title() { 
  80. // @codingStandardsIgnoreStart 
  81. /** translators: %s: Order date */ 
  82. return sprintf( __( 'Refund – %s', 'woocommerce' ), strftime( _x( '%b %d, %Y @ %I:%M %p', 'Order date parsed by strftime', 'woocommerce' ) ) ); 
  83. // @codingStandardsIgnoreEnd