Created
October 28, 2021 08:46
-
-
Save encoderit-arman/c7fba80bf1344611dc19fab872ec9422 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function display_product_review($product_id) { | |
$product = wc_get_product( $product_id ); | |
$comments = get_approved_comments( $product->id ); | |
$product_link = '/product/' . $product->post->post_name . "/#tab-reviews/"; | |
if ( !empty ($comments) ) { | |
echo $comments[0]->comment_content . '<br><a href="'. $product_link . '">Read more reviews...</a>'; | |
} else { | |
echo "There are no reviews for this product yet. Would you like to <a href='" . $product_link ."'>add your own review</a>?"; | |
} | |
} | |
add_action('get_latest_review','display_product_review'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment