/**
  * Gets the item quantity
  *
  * @since 3.1
  * @param array $item the cart item
  * @return int the item quantity
  */
 public function get_item_quantity($item)
 {
     // special case for calculated inventory products: the actual quantity (ie *1* item 10 feet long)
     //  is held in _quantity while $item['quantity'] would be '10' in this example
     if (WC_Price_Calculator_Product::pricing_calculator_inventory_enabled($item['data']) && isset($item['pricing_item_meta_data']['_quantity'])) {
         return $item['pricing_item_meta_data']['_quantity'];
     }
     // return the regular item quantity
     return $item['quantity'];
 }
 /**
  * Manage the order stock (whether restore or reduce) from the order admin
  * returning the true product stock change if this is for a pricing calculator
  * product/item with inventory enabled.  Ie 2 pieces of cloth at 3 ft each
  * we'd want to return 6
  *
  * @since 3.0
  * @param numeric $quantity the new quantity
  * @param string $item_id the order item identifier
  * @return numeric $quantity the measurement quantity
  */
 public function admin_manage_order_stock($quantity, $item_id)
 {
     $order_id = absint($_POST['order_id']);
     $order = wc_get_order($order_id);
     $order_items = $order->get_items();
     $product = wc_get_product($order_items[$item_id]['product_id']);
     if (WC_Price_Calculator_Product::pricing_calculator_inventory_enabled($product) && isset($order_items[$item_id]['measurement_data'])) {
         $settings = new WC_Price_Calculator_Settings($product);
         $measurement_data = maybe_unserialize($order_items[$item_id]['measurement_data']);
         $total_amount = new WC_Price_Calculator_Measurement($measurement_data['_measurement_needed_unit'], $measurement_data['_measurement_needed']);
         // this is a pricing calculator product so we want to return the
         //  quantity in terms of units, ie 2 pieces of cloth at 3 ft each = 6
         $quantity *= $total_amount->get_value($settings->get_pricing_unit());
     }
     return $quantity;
 }