wordpresswoocommercefrontendreviewhook-wordpress

How to remove the comment-author-[USER-ID] class from the WooCommerce review section?


Does anyone know how to remove the highlighted class from the woocommerce review section?

enter image description here


Solution

  • The comment-author-[USER-ID] or [USER-NICKNAME] class can be removed by using the WordPress comment_class filter hook.

    So you get:

    /**
     * Filters the returned CSS classes for the current comment.
     *
     * @since 2.7.0
     *
     * @param string[]    $classes    An array of comment classes.
     * @param string      $class      A comma-separated list of additional classes added to the list.
     * @param int         $comment_id The comment ID.
     * @param WP_Comment  $comment    The comment object.
     * @param int|WP_Post $post_id    The post ID or WP_Post object.
     */
    function filter_comment_class( $classes, $class, $comment_id, $comment, $post_id ) {
        // Loop through classes
        foreach ( $classes as $key => $class ) {
            // Check if a string contains a specific word
            if ( strpos( $class, 'comment-author') !== false ) {
                // Unset a given variable
                unset( $classes[$key] );
            }   
        }
        
        return $classes;
    }
    add_filter( 'comment_class', 'filter_comment_class', 10, 5 );