WC_REST_Products_V2_Controller::prepare_object_for_response()
Prepare a single product output for response.
Метод класса: WC_REST_Products_V2_Controller{}
Хуки из метода
Возвращает
WP_REST_Response
.
Использование
$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) (обязательный)
- Object data.
- $request(WP_REST_Request) (обязательный)
- Request object.
Список изменений
С версии 3.0.0 | Введена. |
Код WC_REST_Products_V2_Controller::prepare_object_for_response() WC REST Products V2 Controller::prepare object for response WC 9.3.3
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 ); }