Support » Plugin: WooCommerce » How to validate review form?

  • Resolved Jola70

    (@jola70)


    I want to validate custom fields in standard comment form and in review form.
    I try to use:

    function verification_test( $commentdata ) {
        
        // for test
        if ( is_product() ) {
            $test = "This is product page";
        } else {
            $test = "This is NOT product page";
        }
        
        if( is_product() ) {
            if( ! isset( $_POST['chb_review_test'] ) ) {
                wp_die( '<strong>ERROR: </strong>you must accept required fields.' . $test . '<p><a href="javascript:history.back()">' . __( '&laquo; Back' ) . '</a></p>');
            }       
        } else {
            if( ! isset( $_POST['chb_comment_test'] ) ) {
                wp_die( '<strong>ERROR: </strong>you must accept required fields.' . $test . '<p><a href="javascript:history.back()">' . __( '&laquo; Back' ) . '</a></p>');
            }      
        }
        return $commentdata;
    }
    
    add_filter( 'preprocess_comment', 'verification_test' );

    Function is_product() not working – always returns “This is not product page”. And I can not validate my custom fields.
    Is any filter like preprocess_comment dedicated for review form?

    The same problem is probably with:
    add_action( 'comment_post', 'my_function' );

    Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • comment_post acts on a comment, and comment of course is not a product. You need to use get_comment to retrieve comment object, then identify the post which was commented (comment_post_ID), then test whether it is a product or not (is_product will not work here, you’ll need get_post_type).

    Plugin Support EtienneP

    (@etiennep)

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.