WC_Order_Item_Coupon_Data_Store

WC Order Item Coupon Data Store.

Defined (1)

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

/includes/data-stores/class-wc-order-item-coupon-data-store.php  
  1. class WC_Order_Item_Coupon_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( 'discount_amount', 'discount_amount_tax' ); 
  9.  
  10. /** 
  11. * Read/populate data properties specific to this order item. 
  12. * @since 3.0.0 
  13. * @param WC_Order_Item_Coupon $item 
  14. */ 
  15. public function read( &$item ) { 
  16. parent::read( $item ); 
  17. $id = $item->get_id(); 
  18. $item->set_props( array( 
  19. 'discount' => get_metadata( 'order_item', $id, 'discount_amount', true ),  
  20. 'discount_tax' => get_metadata( 'order_item', $id, 'discount_amount_tax', true ),  
  21. ) ); 
  22. $item->set_object_read( true ); 
  23.  
  24. /** 
  25. * Saves an item's data to the database / item meta. 
  26. * Ran after both create and update, so $item->get_id() will be set. 
  27. * @since 3.0.0 
  28. * @param WC_Order_Item_Coupon $item 
  29. */ 
  30. public function save_item_data( &$item ) { 
  31. $id = $item->get_id(); 
  32. $save_values = array( 
  33. 'discount_amount' => $item->get_discount( 'edit' ),  
  34. 'discount_amount_tax' => $item->get_discount_tax( 'edit' ),  
  35. ); 
  36. foreach ( $save_values as $key => $value ) { 
  37. update_metadata( 'order_item', $id, $key, $value );