0
votes

I am trying to redirect users to a thank you page after leaving a product review in woocommerce. I know the code

  add_filter('comment_post_redirect', 'redirect_after_comment');
    function redirect_after_comment($location)
    {
    return $_SERVER["HTTP_REFERER"];
    }

will redirect all comments to a location, but I can't seem to find a filter or hook to specify only woocommerce product reviews. Has anyone done this before? Ideally I would just like to redirect to a standard wordpress page so I can add options and features to that pages template file in the future.

1

1 Answers

2
votes

The comment_post_redirect filter has a second parameter. This parameter is the $comment object from which we can grab the post's ID. With the post's ID you can test for post_type and adjust the returned variable accordingly.

add_filter( 'comment_post_redirect', 'redirect_after_comment', 10, 2 );

function redirect_after_comment( $location, $comment ){
    $post_id = $comment->comment_post_ID;

    // product-only comment redirects
    if( 'product' == get_post_type( $post_id ) ){
        $location = 'http://www.woothemes.com';
    }
    return $location;
}