WC_REST_Order_Notes_Controller::prepare_item_for_response()
Prepare a single order note output for response.
Метод класса: WC_REST_Order_Notes_Controller{}
Хуки из метода
Возвращает
WP_REST_Response
. $response Response data.
Использование
$WC_REST_Order_Notes_Controller = new WC_REST_Order_Notes_Controller(); $WC_REST_Order_Notes_Controller->prepare_item_for_response( $note, $request );
- $note(WP_Comment) (обязательный)
- Order note object.
- $request(WP_REST_Request) (обязательный)
- Request object.
Код WC_REST_Order_Notes_Controller::prepare_item_for_response() WC REST Order Notes Controller::prepare item for response WC 9.2.3
public function prepare_item_for_response( $note, $request ) { $data = array( 'id' => (int) $note->comment_ID, 'author' => __( 'woocommerce', 'woocommerce' ) === $note->comment_author ? 'system' : $note->comment_author, 'date_created' => wc_rest_prepare_date_response( $note->comment_date ), 'date_created_gmt' => wc_rest_prepare_date_response( $note->comment_date_gmt ), 'note' => $note->comment_content, 'customer_note' => (bool) get_comment_meta( $note->comment_ID, 'is_customer_note', true ), ); $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( $note ) ); /** * Filter order note object returned from the REST API. * * @param WP_REST_Response $response The response object. * @param WP_Comment $note Order note object used to create response. * @param WP_REST_Request $request Request object. */ return apply_filters( 'woocommerce_rest_prepare_order_note', $response, $note, $request ); }