WC_REST_Refunds_Controller::prepare_object_for_response()publicWC 9.0.0

Prepare a single order output for response.

Метод класса: WC_REST_Refunds_Controller{}

Хуки из метода

Возвращает

WP_Error|WP_REST_Response.

Использование

$WC_REST_Refunds_Controller = new WC_REST_Refunds_Controller();
$WC_REST_Refunds_Controller->prepare_object_for_response( $refund, $request );
$refund(WC_Order_Refund) (обязательный)
Refund data.
$request(WP_REST_Request) (обязательный)
Request object.

Список изменений

С версии 9.0.0 Введена.

Код WC_REST_Refunds_Controller::prepare_object_for_response() WC 9.8.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
}