From 014d64a9418640b044a95f8c238836acd78f617a Mon Sep 17 00:00:00 2001 From: anitaamurthy Date: Tue, 8 Mar 2022 13:36:09 +0530 Subject: [PATCH] Added product name + permalink to the GET Reviews API endpoint response --- ...lass-wc-rest-product-reviews-controller.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-product-reviews-controller.php b/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-product-reviews-controller.php index a737be29c11..000bcf8fb37 100644 --- a/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-product-reviews-controller.php +++ b/plugins/woocommerce/includes/rest-api/Controllers/Version3/class-wc-rest-product-reviews-controller.php @@ -682,6 +682,12 @@ class WC_REST_Product_Reviews_Controller extends WC_REST_Controller { if ( in_array( 'product_id', $fields, true ) ) { $data['product_id'] = (int) $review->comment_post_ID; } + if ( in_array( 'product_name', $fields, true ) ) { + $data['product_name'] = get_the_title( (int) $review->comment_post_ID ); + } + if ( in_array( 'product_permalink', $fields, true ) ) { + $data['product_permalink'] = get_permalink( (int) $review->comment_post_ID ); + } if ( in_array( 'status', $fields, true ) ) { $data['status'] = $this->prepare_status_response( (string) $review->comment_approved ); } @@ -841,6 +847,18 @@ class WC_REST_Product_Reviews_Controller extends WC_REST_Controller { 'type' => 'integer', 'context' => array( 'view', 'edit' ), ), + 'product_name' => array( + 'description' => __( 'Product name.', 'woocommerce' ), + 'type' => 'string', + 'context' => array( 'view', 'edit' ), + ), + 'product_permalink' => array( + 'description' => __( 'Product URL.', 'woocommerce' ), + 'type' => 'string', + 'format' => 'uri', + 'context' => array( 'view', 'edit' ), + 'readonly' => true, + ), 'status' => array( 'description' => __( 'Status of the review.', 'woocommerce' ), 'type' => 'string',