WC_REST_Refunds_Controller::prepare_object_for_response()publicWC 9.0.0

Prepare a single order output for response.

Method of the class: WC_REST_Refunds_Controller{}

Return

WP_Error|WP_REST_Response.

Usage

$WC_REST_Refunds_Controller = new WC_REST_Refunds_Controller();
$WC_REST_Refunds_Controller->prepare_object_for_response( $refund, $request );
$refund(WC_Order_Refund) (required)
Refund data.
$request(WP_REST_Request) (required)
Request object.

Changelog

Since 9.0.0 Introduced.

WC_REST_Refunds_Controller::prepare_object_for_response() code WC 9.5.1

public function prepare_object_for_response( $refund, $request ) {
	$this->request       = $request;
	$this->request['dp'] = is_null( $this->request['dp'] ) ? wc_get_price_decimals() : absint( $this->request['dp'] );

	$data    = $this->get_formatted_item_data( $refund );
	$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
	$data    = $this->add_additional_fields_to_object( $data, $request );
	$data    = $this->filter_response_by_context( $data, $context );

	// Wrap the data in a response object.
	$response = rest_ensure_response( $data );

	$response->add_links( $this->prepare_links( $refund, $request ) );

	// phpcs:disable WooCommerce.Commenting.CommentHooks.MissingSinceComment
	/** This filter is documented in includes/rest-api/Controllers/Version2/class-wc-rest-order-refunds-v2-controller.php */
	return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $refund, $request );
	// phpcs:enable WooCommerce.Commenting.CommentHooks.MissingSinceComment
}