WC_REST_Product_Reviews_V1_Controller::get_item()
Get a single product review.
Метод класса: WC_REST_Product_Reviews_V1_Controller{}
Хуков нет.
Возвращает
WP_Error|WP_REST_Response
.
Использование
$WC_REST_Product_Reviews_V1_Controller = new WC_REST_Product_Reviews_V1_Controller(); $WC_REST_Product_Reviews_V1_Controller->get_item( $request );
- $request(WP_REST_Request) (обязательный)
- Full details about the request.
Код WC_REST_Product_Reviews_V1_Controller::get_item() WC REST Product Reviews V1 Controller::get item WC 8.1.1
public function get_item( $request ) { $id = (int) $request['id']; $product_id = (int) $request['product_id']; if ( 'product' !== get_post_type( $product_id ) ) { return new WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) ); } $review = get_comment( $id ); if ( empty( $id ) || empty( $review ) || intval( $review->comment_post_ID ) !== $product_id ) { return new WP_Error( 'woocommerce_rest_invalid_id', __( 'Invalid resource ID.', 'woocommerce' ), array( 'status' => 404 ) ); } $delivery = $this->prepare_item_for_response( $review, $request ); $response = rest_ensure_response( $delivery ); return $response; }