WC_REST_Product_Reviews_V1_Controller::get_review()
Fetch a single product review from the database.
Method of the class: WC_REST_Product_Reviews_V1_Controller{}
No Hooks.
Return
\WP_Comment
.
Usage
// protected - for code of main (parent) or child class $result = $this->get_review( $id, $product_id );
- $id(int) (required)
- Review ID.
- $product_id(int) (required)
- Product ID.
Changelog
Since 9.2.0 | Introduced. |
WC_REST_Product_Reviews_V1_Controller::get_review() WC REST Product Reviews V1 Controller::get review code WC 9.8.1
protected function get_review( int $id, int $product_id ) { if ( 0 >= $product_id || 'product' !== get_post_type( $product_id ) ) { return new WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) ); } $review = 0 <= $id ? get_comment( $id ) : null; if ( empty( $review ) || empty( $review->comment_ID ) || 'review' !== get_comment_type( $id ) || empty( $review->comment_post_ID ) || (int) $review->comment_post_ID !== $product_id ) { return new WP_Error( 'woocommerce_rest_product_review_invalid_id', __( 'Invalid product review ID.', 'woocommerce' ), array( 'status' => 404 ) ); } return $review; }