WordPress at Your Fingertips
function is not described

WC_API_Orders::delete_order_refund() public WC 2.2

Delete order refund

{} It's a method of the class: WC_API_Orders{}

Hooks from the method
Return

WP_Error|Array. error or deleted message

Usage

$WC_API_Orders = new WC_API_Orders();
$WC_API_Orders->delete_order_refund( $order_id, $id );
$order_id(string) (required)
order ID
$id(string) (required)
refund ID

Changelog

Since 2.2 Introduced.

Code of WC_API_Orders::delete_order_refund() WC 5.7.1

public function delete_order_refund( $order_id, $id ) {
	try {
		$order_id = $this->validate_request( $order_id, $this->post_type, 'delete' );

		if ( is_wp_error( $order_id ) ) {
			return $order_id;
		}

		// Validate refund ID
		$id = absint( $id );

		if ( empty( $id ) ) {
			throw new WC_API_Exception( 'woocommerce_api_invalid_order_refund_id', __( 'Invalid order refund ID.', 'woocommerce' ), 400 );
		}

		// Ensure refund ID is valid
		$refund = get_post( $id );

		if ( ! $refund ) {
			throw new WC_API_Exception( 'woocommerce_api_invalid_order_refund_id', __( 'An order refund with the provided ID could not be found.', 'woocommerce' ), 404 );
		}

		// Ensure refund ID is associated with given order
		if ( $refund->post_parent != $order_id ) {
			throw new WC_API_Exception( 'woocommerce_api_invalid_order_refund_id', __( 'The order refund ID provided is not associated with the order.', 'woocommerce' ), 400 );
		}

		wc_delete_shop_order_transients( $order_id );

		do_action( 'woocommerce_api_delete_order_refund', $refund->ID, $order_id, $this );

		return $this->delete( $refund->ID, 'refund', true );
	} catch ( WC_API_Exception $e ) {
		return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
	}
}