Added product name + permalink to the GET Reviews API endpoint response

This commit is contained in:
anitaamurthy 2022-03-08 13:36:09 +05:30
parent aa8b7a4a6b
commit 014d64a941
1 changed files with 18 additions and 0 deletions

View File

@ -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',