skip to Main Content

I am using Woocommerce and I have to show a message after submitting the review on the product.

wc_add_notice(‘Thank you for submitting the review. Your review is awaiting approval.’);

Any idea how to display messages after submitting review?

2

Answers


  1. You can use comment_post_redirect filter hook and inside that hook you can use wc_add_notice function. check below code. code will go in your active theme functions.php file.

    add_filter( 'comment_post_redirect', 'show_notice_after_review_submit', 99 );
    function show_notice_after_review_submit( $location ) {
        wc_add_notice( __( 'Thank you for submitting the review. Your review is awaiting approval.', 'woocommerce' ), 'success' );
        return $location;
    }
    

    Tested and works.

    enter image description here

    Login or Signup to reply.
  2. You can use comment_post action hook. you need to check the comment belongs to a product and the comment type is review or it will be applied to all comments in all post types.

    add_action( 'comment_post', 'review_submit_notice', 100, 3 );
    
    function review_submit_notice( $comment_id, $is_approved, $commentdata ) {
        if ( ! is_admin() && ( 'product' === get_post_type( absint( $commentdata['comment_post_ID'] ) ) ) && ( 'review' === $commentdata['comment_type'] ) ) {
            wc_add_notice('Thank you for submitting the review. Your review is awaiting approval.');
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search