This code will check if the customer is logged in, if he/she purchased the product and if those statements are true, it will display a message.
I would like to include one more check before the message is shown and that is if the customer already left a review/ wrote a review for the product and if so, do not show the message.
In other words, if the customer did not write a review for the product, show message. If customer left a review, do not show message.
Here is the code:
add_action( 'woocommerce_before_single_product_summary', 'woo_review_discount_message');
function woo_review_discount_message() {
if ( is_user_logged_in() ) {
global $product;
$current_user = wp_get_current_user();
if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product->get_id() && $order->status->complete ) ) echo '<div class="user-bought"><span style="color:#CA364D;font-weight:bold;font-size:18px;"><i class="wishlist-icon icon-heart-o"></i></span> Hi ' . $current_user->first_name . '! Please write a review below.</a></div>';
}
}
Any help on this is very much appreciated.
To check if a customer has posted a review on the current product, you will use this custom conditional function (using a very light SQL query):
Code goes in function.php file of the active child theme (or active theme). Tested and works.
So in your code (from this answer) you will use it as following:
Code goes in function.php file of the active child theme (or active theme). Tested and works.
Related answer: Display a custom text if user has already bought the current product In Woocommerce