WC_Order::get_refundspublicWC 2.2

Returns an array of WC_Order_Refund objects for the order.

Utilizes object cache to store refunds to avoid extra DB calls.

Method of the class: WC_Order{}

No Hooks.

Returns

WC_Order_Refund[].

Usage

$WC_Order = new WC_Order();
$WC_Order->get_refunds();

Notes

Changelog

Since 2.2 Introduced.

WC_Order::get_refunds() code WC 10.8.1

public function get_refunds() {
	$cache_key  = WC_Cache_Helper::get_cache_prefix( 'orders' ) . 'refund_ids' . $this->get_id();
	$refund_ids = wp_cache_get( $cache_key, $this->cache_group );

	if ( false === $refund_ids ) {
		$refunds    = (array) wc_get_orders(
			array(
				'type'   => 'shop_order_refund',
				'parent' => $this->get_id(),
				'limit'  => -1,
			)
		);
		$refund_ids = array();
		foreach ( $refunds as $refund ) {
			if ( $refund instanceof WC_Order_Refund ) {
				$refund_ids[] = $refund->get_id();
			}
		}
		wp_cache_set( $cache_key, $refund_ids, $this->cache_group );
	} else {
		$refunds = ! empty( $refund_ids )
			? wc_get_orders(
				array(
					'type'          => 'shop_order_refund',
					'post__in'      => $refund_ids,
					'orderby'       => 'post__in',
					'limit'         => -1,
					'no_found_rows' => true,
				)
			)
			: array();
	}//end if

	$this->refunds = array();

	if ( ! empty( $refunds ) && is_array( $refunds ) ) {
		foreach ( $refunds as $refund ) {
			if ( $refund instanceof WC_Order_Refund ) {
				$this->refunds[] = $refund;
			}
		}
	}

	return $this->refunds;
}