WC_Order::get_total_refunded_for_item PHP Method

get_total_refunded_for_item() public method

Get the refunded amount for a line item.
public get_total_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
    public function get_total_refunded_for_item($item_id, $item_type = 'line_item')
    {
        $total = 0;
        foreach ($this->get_refunds() as $refund) {
            foreach ($refund->get_items($item_type) as $refunded_item) {
                if (absint($refunded_item->get_meta('_refunded_item_id')) === $item_id) {
                    $total += $refunded_item->get_total();
                }
            }
        }
        return $total * -1;
    }

Usage Example

示例#1
0
 /**
  * Test: test_get_total_refunded_for_item
  */
 function test_get_total_refunded_for_item()
 {
     $object = new WC_Order();
     $this->assertEquals(0, $object->get_total_refunded_for_item(2));
 }
All Usage Examples Of WC_Order::get_total_refunded_for_item
WC_Order