WC_Order_Item_Tax_Data_Store

WC Order Item Tax Data Store.

Defined (1)

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

/includes/data-stores/class-wc-order-item-tax-data-store.php  
  1. class WC_Order_Item_Tax_Data_Store extends Abstract_WC_Order_Item_Type_Data_Store implements WC_Object_Data_Store_Interface, WC_Order_Item_Type_Data_Store_Interface { 
  2.  
  3. /** 
  4. * Data stored in meta keys. 
  5. * @since 3.0.0 
  6. * @var array 
  7. */ 
  8. protected $internal_meta_keys = array( 'rate_id', 'label', 'compound', 'tax_amount', 'shipping_tax_amount' ); 
  9.  
  10. /** 
  11. * Read/populate data properties specific to this order item. 
  12. * @since 3.0.0 
  13. * @param WC_Order_Item_Tax $item 
  14. */ 
  15. public function read( &$item ) { 
  16. parent::read( $item ); 
  17. $id = $item->get_id(); 
  18. $item->set_props( array( 
  19. 'rate_id' => get_metadata( 'order_item', $id, 'rate_id', true ),  
  20. 'label' => get_metadata( 'order_item', $id, 'label', true ),  
  21. 'compound' => get_metadata( 'order_item', $id, 'compound', true ),  
  22. 'tax_total' => get_metadata( 'order_item', $id, 'tax_amount', true ),  
  23. 'shipping_tax_total' => get_metadata( 'order_item', $id, 'shipping_tax_amount', true ),  
  24. ) ); 
  25. $item->set_object_read( true ); 
  26.  
  27. /** 
  28. * Saves an item's data to the database / item meta. 
  29. * Ran after both create and update, so $id will be set. 
  30. * @since 3.0.0 
  31. * @param WC_Order_Item_Tax $item 
  32. */ 
  33. public function save_item_data( &$item ) { 
  34. $id = $item->get_id(); 
  35. $save_values = array( 
  36. 'rate_id' => $item->get_rate_id( 'edit' ),  
  37. 'label' => $item->get_label( 'edit' ),  
  38. 'compound' => $item->get_compound( 'edit' ),  
  39. 'tax_amount' => $item->get_tax_total( 'edit' ),  
  40. 'shipping_tax_amount' => $item->get_shipping_tax_total( 'edit' ),  
  41. ); 
  42. foreach ( $save_values as $key => $value ) { 
  43. update_metadata( 'order_item', $id, $key, $value );