WC_REST_Refunds_Controller::prepare_object_for_response
Prepare a single order output for response.
Method of the class: WC_REST_Refunds_Controller{}
Hooks from the method
Returns
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() WC REST Refunds Controller::prepare object for response code WC 10.5.0
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
}