WC_Order_Item_Product_Data_Store

WC Order Item Product Data Store.

Defined (1)

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

/includes/data-stores/class-wc-order-item-product-store.php  
  1. class WC_Order_Item_Product_Data_Store extends Abstract_WC_Order_Item_Type_Data_Store implements WC_Object_Data_Store_Interface, WC_Order_Item_Type_Data_Store_Interface, WC_Order_Item_Product_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( '_product_id', '_variation_id', '_qty', '_tax_class', '_line_subtotal', '_line_subtotal_tax', '_line_total', '_line_tax', '_line_tax_data' ); 
  9.  
  10. /** 
  11. * Read/populate data properties specific to this order item. 
  12. * @since 3.0.0 
  13. * @param WC_Order_Item_Product $item 
  14. */ 
  15. public function read( &$item ) { 
  16. parent::read( $item ); 
  17. $id = $item->get_id(); 
  18. $item->set_props( array( 
  19. 'product_id' => get_metadata( 'order_item', $id, '_product_id', true ),  
  20. 'variation_id' => get_metadata( 'order_item', $id, '_variation_id', true ),  
  21. 'quantity' => get_metadata( 'order_item', $id, '_qty', true ),  
  22. 'tax_class' => get_metadata( 'order_item', $id, '_tax_class', true ),  
  23. 'subtotal' => get_metadata( 'order_item', $id, '_line_subtotal', true ),  
  24. 'total' => get_metadata( 'order_item', $id, '_line_total', true ),  
  25. 'taxes' => get_metadata( 'order_item', $id, '_line_tax_data', true ),  
  26. ) ); 
  27. $item->set_object_read( true ); 
  28.  
  29. /** 
  30. * Saves an item's data to the database / item meta. 
  31. * Ran after both create and update, so $id will be set. 
  32. * @since 3.0.0 
  33. * @param WC_Order_Item_Product $item 
  34. */ 
  35. public function save_item_data( &$item ) { 
  36. $id = $item->get_id(); 
  37. $save_values = array( 
  38. '_product_id' => $item->get_product_id( 'edit' ),  
  39. '_variation_id' => $item->get_variation_id( 'edit' ),  
  40. '_qty' => $item->get_quantity( 'edit' ),  
  41. '_tax_class' => $item->get_tax_class( 'edit' ),  
  42. '_line_subtotal' => $item->get_subtotal( 'edit' ),  
  43. '_line_subtotal_tax' => $item->get_subtotal_tax( 'edit' ),  
  44. '_line_total' => $item->get_total( 'edit' ),  
  45. '_line_tax' => $item->get_total_tax( 'edit' ),  
  46. '_line_tax_data' => $item->get_taxes( 'edit' ),  
  47. ); 
  48. foreach ( $save_values as $key => $value ) { 
  49. update_metadata( 'order_item', $id, $key, $value ); 
  50.  
  51. /** 
  52. * Get a list of download IDs for a specific item from an order. 
  53. * @since 3.0.0 
  54. * @param WC_Order_Item_Product $item 
  55. * @param WC_Order $order 
  56. * @return array 
  57. */ 
  58. public function get_download_ids( $item, $order ) { 
  59. global $wpdb; 
  60. return $wpdb->get_col( 
  61. $wpdb->prepare( 
  62. "SELECT download_id FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE user_email = %s AND order_key = %s AND product_id = %d ORDER BY permission_id",  
  63. $order->get_billing_email(),  
  64. $order->get_order_key(),  
  65. $item->get_variation_id() ? $item->get_variation_id() : $item->get_product_id() 
  66. );