A class which represents an item within an order and handles CRUD. Uses ArrayAccess to be BW compatible with WC_Orders::get_items().
Since: 2.7.0
Author: WooThemes
Inheritance: extends WC_Data, implements ArrayAccess
 /**
  * Saves an item's data to the database / item meta.
  * Ran after both create and update, so $item->get_id() will be set.
  *
  * @since 2.7.0
  * @param WC_Order_Item $item
  */
 public function save_item_data(&$item)
 {
     wc_update_order_item_meta($item->get_id(), 'method_id', $item->get_method_id('edit'));
     wc_update_order_item_meta($item->get_id(), 'cost', $item->get_total('edit'));
     wc_update_order_item_meta($item->get_id(), 'total_tax', $item->get_total_tax('edit'));
     wc_update_order_item_meta($item->get_id(), 'taxes', $item->get_taxes('edit'));
 }
 /**
  * Read a order item from the database.
  *
  * @since 2.7.0
  * @param WC_Order_Item $item
  */
 public function read(&$item)
 {
     global $wpdb;
     $item->set_defaults();
     $data = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_id = %d LIMIT 1;", $item->get_id()));
     if (!$data) {
         throw new Exception(__('Invalid order item.', 'woocommerce'));
     }
     $item->set_props(array('order_id' => $data->order_id, 'name' => $data->order_item_name, 'type' => $data->order_item_type));
     $item->read_meta_data();
     $item->set_object_read(true);
 }
 /**
  * Save properties specific to this order item.
  * @return int Item ID
  */
 public function save()
 {
     parent::save();
     if ($this->get_id()) {
         wc_update_order_item_meta($this->get_id(), 'discount_amount', $this->get_discount());
         wc_update_order_item_meta($this->get_id(), 'discount_amount_tax', $this->get_discount_tax());
     }
     return $this->get_id();
 }
 /**
  * Save properties specific to this order item.
  * @return int Item ID
  */
 public function save()
 {
     parent::save();
     if ($this->get_id()) {
         wc_update_order_item_meta($this->get_id(), 'method_id', $this->get_method_id());
         wc_update_order_item_meta($this->get_id(), 'cost', $this->get_total());
         wc_update_order_item_meta($this->get_id(), 'total_tax', $this->get_total_tax());
         wc_update_order_item_meta($this->get_id(), 'taxes', $this->get_taxes());
     }
     return $this->get_id();
 }
 /**
  * Save properties specific to this order item.
  * @return int Item ID
  */
 public function save()
 {
     parent::save();
     if ($this->get_id()) {
         wc_update_order_item_meta($this->get_id(), 'rate_id', $this->get_rate_id());
         wc_update_order_item_meta($this->get_id(), 'label', $this->get_label());
         wc_update_order_item_meta($this->get_id(), 'compound', $this->get_compound());
         wc_update_order_item_meta($this->get_id(), 'tax_amount', $this->get_tax_total());
         wc_update_order_item_meta($this->get_id(), 'shipping_tax_amount', $this->get_shipping_tax_total());
     }
     return $this->get_id();
 }
 /**
  * Save properties specific to this order item.
  * @return int Item ID
  */
 public function save()
 {
     parent::save();
     if ($this->get_id()) {
         wc_update_order_item_meta($this->get_id(), '_tax_class', $this->get_tax_class());
         wc_update_order_item_meta($this->get_id(), '_tax_status', $this->get_tax_status());
         wc_update_order_item_meta($this->get_id(), '_line_total', $this->get_total());
         wc_update_order_item_meta($this->get_id(), '_line_tax', $this->get_total_tax());
         wc_update_order_item_meta($this->get_id(), '_line_tax_data', $this->get_taxes());
     }
     return $this->get_id();
 }
 /**
  * offsetExists for ArrayAccess
  * @param string $offset
  * @return bool
  */
 public function offsetExists($offset)
 {
     if (in_array($offset, array('cost'))) {
         return true;
     }
     return parent::offsetExists($offset);
 }
 /**
  * Saves an item's data to the database / item meta.
  * Ran after both create and update, so $item->get_id() will be set.
  *
  * @since 2.7.0
  * @param WC_Order_Item $item
  */
 public function save_item_data(&$item)
 {
     wc_update_order_item_meta($item->get_id(), '_tax_class', $item->get_tax_class('edit'));
     wc_update_order_item_meta($item->get_id(), '_tax_status', $item->get_tax_status('edit'));
     wc_update_order_item_meta($item->get_id(), '_line_total', $item->get_total('edit'));
     wc_update_order_item_meta($item->get_id(), '_line_tax', $item->get_total_tax('edit'));
     wc_update_order_item_meta($item->get_id(), '_line_tax_data', $item->get_taxes('edit'));
 }
 /**
  * Save properties specific to this order item.
  * @return int Item ID
  */
 public function save()
 {
     parent::save();
     if ($this->get_id()) {
         wc_update_order_item_meta($this->get_id(), '_product_id', $this->get_product_id());
         wc_update_order_item_meta($this->get_id(), '_variation_id', $this->get_variation_id());
         wc_update_order_item_meta($this->get_id(), '_qty', $this->get_quantity());
         wc_update_order_item_meta($this->get_id(), '_tax_class', $this->get_tax_class());
         wc_update_order_item_meta($this->get_id(), '_line_subtotal', $this->get_subtotal());
         wc_update_order_item_meta($this->get_id(), '_line_subtotal_tax', $this->get_subtotal_tax());
         wc_update_order_item_meta($this->get_id(), '_line_total', $this->get_total());
         wc_update_order_item_meta($this->get_id(), '_line_tax', $this->get_total_tax());
         wc_update_order_item_meta($this->get_id(), '_line_tax_data', $this->get_taxes());
     }
     return $this->get_id();
 }
 /**
  * Saves an item's data to the database / item meta.
  * Ran after both create and update, so $item->get_id() will be set.
  *
  * @since 2.7.0
  * @param WC_Order_Item $item
  */
 public function save_item_data(&$item)
 {
     wc_update_order_item_meta($item->get_id(), 'discount_amount', $item->get_discount('edit'));
     wc_update_order_item_meta($item->get_id(), 'discount_amount_tax', $item->get_discount_tax('edit'));
 }
 /**
  * offsetExists for ArrayAccess
  * @param string $offset
  * @return bool
  */
 public function offsetExists($offset)
 {
     if (in_array($offset, array('discount_amount', 'discount_amount_tax'))) {
         return true;
     }
     return parent::offsetExists($offset);
 }
 /**
  * Get a list of download IDs for a specific item from an order.
  *
  * @since 2.7.0
  * @param WC_Order_Item $item
  * @param WC_Order $order
  * @return array
  */
 public function get_download_ids($item, $order)
 {
     global $wpdb;
     return $wpdb->get_col($wpdb->prepare("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", $order->get_billing_email(), $order->get_order_key(), $item->get_variation_id() ? $item->get_variation_id() : $item->get_product_id()));
 }
 /**
  * offsetExists for ArrayAccess
  * @param string $offset
  * @return bool
  */
 public function offsetExists($offset)
 {
     if (in_array($offset, array('line_total', 'line_tax', 'line_tax_data'))) {
         return true;
     }
     return parent::offsetExists($offset);
 }
 /**
  * Saves an item's data to the database / item meta.
  * Ran after both create and update, so $item->get_id() will be set.
  *
  * @since 2.7.0
  * @param WC_Order_Item $item
  */
 public function save_item_data(&$item)
 {
     wc_update_order_item_meta($item->get_id(), 'rate_id', $item->get_rate_id('edit'));
     wc_update_order_item_meta($item->get_id(), 'label', $item->get_label('edit'));
     wc_update_order_item_meta($item->get_id(), 'compound', $item->get_compound('edit'));
     wc_update_order_item_meta($item->get_id(), 'tax_amount', $item->get_tax_total('edit'));
     wc_update_order_item_meta($item->get_id(), 'shipping_tax_amount', $item->get_shipping_tax_total('edit'));
 }