Warning: This method has been deprecated.
WC_REST_Legacy_Products_Controller::prepare_item_for_response( WP_Post $post, WP_REST_Request $request )
Prepare a single product output for response.
Description Description
Parameters Parameters
- $post
-
(Required) Post object.
- $request
-
(Required) Request object.
Return Return
(WP_REST_Response)
Source Source
File: includes/legacy/api/class-wc-rest-legacy-products-controller.php
public function prepare_item_for_response( $post, $request ) { $product = wc_get_product( $post ); $data = $this->get_product_data( $product ); // Add variations to variable products. if ( $product->is_type( 'variable' ) && $product->has_child() ) { $data['variations'] = $product->get_children(); } // Add grouped products data. if ( $product->is_type( 'grouped' ) && $product->has_child() ) { $data['grouped_products'] = $product->get_children(); } $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( $product, $request ) ); /** * Filter the data for a response. * * The dynamic portion of the hook name, $this->post_type, refers to post_type of the post being * prepared for the response. * * @param WP_REST_Response $response The response object. * @param WP_Post $post Post object. * @param WP_REST_Request $request Request object. */ return apply_filters( "woocommerce_rest_prepare_{$this->post_type}", $response, $post, $request ); }
Changelog Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |