WordPress at Your Fingertips
function is not described

WC_REST_Order_Refunds_V2_Controller::prepare_object_for_response() public WC 3.0.0

Prepare a single order output for response.

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

Return

WP_Error|WP_REST_Response.

Usage

$WC_REST_Order_Refunds_V2_Controller = new WC_REST_Order_Refunds_V2_Controller();
$WC_REST_Order_Refunds_V2_Controller->prepare_object_for_response( $object, $request );
$object(WC_Data) (required)
Object data.
$request(WP_REST_Request) (required)
Request object.

Changelog

Since 3.0.0 Introduced.

Code of WC_REST_Order_Refunds_V2_Controller::prepare_object_for_response() WC 5.9.0

public function prepare_object_for_response( $object, $request ) {
	$this->request       = $request;
	$this->request['dp'] = is_null( $this->request['dp'] ) ? wc_get_price_decimals() : absint( $this->request['dp'] );
	$order               = wc_get_order( (int) $request['order_id'] );

	if ( ! $order ) {
		return new WP_Error( 'woocommerce_rest_invalid_order_id', __( 'Invalid order ID.', 'woocommerce' ), 404 );
	}

	if ( ! $object || $object->get_parent_id() !== $order->get_id() ) {
		return new WP_Error( 'woocommerce_rest_invalid_order_refund_id', __( 'Invalid order refund ID.', 'woocommerce' ), 404 );
	}

	$data    = $this->get_formatted_item_data( $object );
	$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( $object, $request ) );

	/**
	 * Filter the data for a response.
	 *
	 * The dynamic portion of the hook name, $this->post_type,
	 * refers to object type being prepared for the response.
	 *
	 * @param WP_REST_Response $response The response object.
	 * @param WC_Data          $object   Object data.
	 * @param WP_REST_Request  $request  Request object.
	 */
	return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request );
}