get_qty_refunded_for_item() public method

Get the refunded amount for a line item.
public get_qty_refunded_for_item ( integer $item_id, string $item_type = 'line_item' ) : integer
$item_id integer ID of the item we're checking
$item_type string type of the item we're checking, if not a line_item
return integer
Beispiel #1
0
 /**
  * Test: get_qty_refunded_for_item
  */
 function test_get_qty_refunded_for_item()
 {
     $object = new WC_Order();
     $this->assertEquals(0, $object->get_qty_refunded_for_item(2));
 }
 public function easy_booking_get_booked_items_from_orders()
 {
     $args = array('post_type' => 'shop_order', 'post_status' => apply_filters('easy_booking_get_order_statuses', array('wc-pending', 'wc-processing', 'wc-on-hold', 'wc-completed', 'wc-refunded')), 'posts_per_page' => -1);
     $query_orders = new WP_Query($args);
     $products = array();
     foreach ($query_orders->posts as $post) {
         $order_id = $post->ID;
         $order = new WC_Order($order_id);
         $items = $order->get_items();
         if ($items) {
             foreach ($items as $item_id => $item) {
                 $product_id = $item['product_id'];
                 $variation_id = $item['variation_id'];
                 $product = $order->get_product_from_item($item);
                 $is_bookable = WCEB()->easy_booking_is_bookable($product_id, $variation_id);
                 if (isset($is_bookable) && $is_bookable === 'yes' && !empty($product->id)) {
                     if (isset($item['ebs_start_format']) && isset($item['ebs_end_format'])) {
                         $id = empty($variation_id) || $variation_id === '0' ? $product_id : $variation_id;
                         $start = $item['ebs_start_format'];
                         $end = $item['ebs_end_format'];
                         $quantity = intval($item['qty']);
                         $refunded_qty = $order->get_qty_refunded_for_item($item_id);
                         if ($refunded_qty > 0) {
                             $quantity = $quantity - $refunded_qty;
                         }
                         if ($quantity <= 0) {
                             continue;
                         }
                         $products[] = apply_filters('easy_booking_booked_reports', array('product_id' => $id, 'order_id' => $order_id, 'start' => $start, 'end' => $end, 'qty' => $quantity));
                     }
                 }
             }
         }
     }
     $booked = array();
     if ($products) {
         foreach ($products as $booked_product) {
             $product_id = $booked_product['product_id'];
             $start = $booked_product['start'];
             $end = $booked_product['end'];
             $quantity = intval($booked_product['qty']);
             unset($booked_product['product_id']);
             $booked[$product_id][] = $booked_product;
         }
     }
     return array_filter($booked);
 }