WC_REST_Report_Top_Sellers_V1_Controller::prepare_item_for_response()
Prepare a report sales object for serialization.
Метод класса: WC_REST_Report_Top_Sellers_V1_Controller{}
Хуки из метода
Возвращает
WP_REST_Response
. $response Response data.
Использование
$WC_REST_Report_Top_Sellers_V1_Controller = new WC_REST_Report_Top_Sellers_V1_Controller(); $WC_REST_Report_Top_Sellers_V1_Controller->prepare_item_for_response( $top_seller, $request );
- $top_seller(stdClass) (обязательный)
- -
- $request(WP_REST_Request) (обязательный)
- Request object.
Код WC_REST_Report_Top_Sellers_V1_Controller::prepare_item_for_response() WC REST Report Top Sellers V1 Controller::prepare item for response WC 9.2.3
public function prepare_item_for_response( $top_seller, $request ) { $data = array( 'name' => $top_seller->name, 'product_id' => $top_seller->product_id, 'quantity' => $top_seller->quantity, ); $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( array( 'about' => array( 'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ), ), 'product' => array( 'href' => rest_url( sprintf( '/%s/products/%s', $this->namespace, $top_seller->product_id ) ), ), ) ); /** * Filter a report top sellers returned from the API. * * Allows modification of the report top sellers data right before it is returned. * * @param WP_REST_Response $response The response object. * @param stdClass $top_seller The original report object. * @param WP_REST_Request $request Request used to generate the response. */ return apply_filters( 'woocommerce_rest_prepare_report_top_sellers', $response, $top_seller, $request ); }