WC_REST_Products_V2_Controller::prepare_object_for_response_core
Core function to prepare a single product output for response (doesn't fire hooks, ensure_response, or add links).
Method of the class: WC_REST_Products_V2_Controller{}
No Hooks.
Returns
Array. Product data to be included in the response.
Usage
// protected - for code of main (parent) or child class $result = $this->prepare_object_for_response_core( $object_data, $request, $context ): array;
- $object_data(WC_Data) (required)
- Object data.
- $request(WP_REST_Request) (required)
- Request object.
- $context(string) (required)
- Request context.
WC_REST_Products_V2_Controller::prepare_object_for_response_core() WC REST Products V2 Controller::prepare object for response core code WC 10.3.6
protected function prepare_object_for_response_core( $object_data, $request, $context ): array {
$data = $this->get_product_data( $object_data, $context, $request );
// Add variations to variable products.
if ( $object_data->is_type( ProductType::VARIABLE ) && $object_data->has_child() ) {
$data['variations'] = $object_data->get_children();
}
// Add grouped products data.
if ( $object_data->is_type( ProductType::GROUPED ) && $object_data->has_child() ) {
$data['grouped_products'] = $object_data->get_children();
}
$data = $this->add_additional_fields_to_object( $data, $request );
$data = $this->filter_response_by_context( $data, $context );
return $data;
}