WordPress at Your Fingertips
function is not described

WC_REST_Products_V2_Controller::prepare_object_for_response() public WC 3.0.0

Prepare a single product output for response.

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

Return

WP_REST_Response.

Usage

$WC_REST_Products_V2_Controller = new WC_REST_Products_V2_Controller();
$WC_REST_Products_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_Products_V2_Controller::prepare_object_for_response() WC 5.9.0

public function prepare_object_for_response( $object, $request ) {
	$context       = ! empty( $request['context'] ) ? $request['context'] : 'view';
	$this->request = $request;
	$data          = $this->get_product_data( $object, $context, $request );

	// Add variations to variable products.
	if ( $object->is_type( 'variable' ) && $object->has_child() ) {
		$data['variations'] = $object->get_children();
	}

	// Add grouped products data.
	if ( $object->is_type( 'grouped' ) && $object->has_child() ) {
		$data['grouped_products'] = $object->get_children();
	}

	$data     = $this->add_additional_fields_to_object( $data, $request );
	$data     = $this->filter_response_by_context( $data, $context );
	$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 );
}