Product review error in Google structure data analyzer when using X6.0.4

Yes, it added an auther name field but the author is the site admin, I assume because the site admin is the author of the product page???

Also now looked at the front end and having replaced the <cite…> element, the reviewer name no longer shows on the front and and also the formatting is broken for all but the first review.

I’m not skilled enough in programming to be able to piece the separate code snippets/modifications together into something that actually works both on the front end as well as produces the correct meta info for the structured data.

Hi there,

Your code has an extra </div> which breaks the structure, I went ahead and fixed it. About the author, does it display different author name? I went ahead and fixed it as well, the new code is this

function x_renew_comment( $comment, $args, $depth ) {

    $GLOBALS['comment'] = $comment;
    switch ( $comment->comment_type ) :
      case 'pingback' :  // 1
      case 'trackback' : // 1
    ?>
    <li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
      <p><?php _e( 'Pingback:', '__x__' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', '__x__' ), '<span class="edit-link">', '</span>' ); ?></p>
    <?php
        break;
      default : // 2
      GLOBAL $post;
      if ( X_WOOCOMMERCE_IS_ACTIVE ) :
        $rating = esc_attr( get_comment_meta( $GLOBALS['comment']->comment_ID, 'rating', true ) );
      endif;
      if ( x_is_product() ) {
        $comment_avatar = get_avatar( $comment, 240 );
      } else {
        $comment_avatar = get_avatar( $comment, 120 );
      }
    ?>
    <li id="li-comment-<?php comment_ID(); ?>" itemprop="review" itemscope itemtype="http://schema.org/Review" <?php comment_class(); ?>>
      <article id="comment-<?php comment_ID(); ?>" class="comment">
        <div class="visually-hidden" itemprop="itemReviewed" itemscope itemtype="http://schema.org/Product">
          <span itemprop="name"><?php the_title(); ?></span>
        </div>
        <?php
        printf( '<div class="x-comment-img">%s</div>',
          '<span class="avatar-wrap cf">' . $comment_avatar . '</span>'
        );
        ?>
        <?php if ( ! x_is_product() ) : ?>
        <div class="x-reply">
          <?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply <span class="comment-reply-link-after"><i class="x-icon-reply" data-x-icon="&#xf112;"></i></span>', '__x__' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
        </div>
        <?php endif; ?>
  		<header class="x-comment-header">
<div class="visually-hidden" itemprop="author" itemscope itemtype="http://schema.org/Person">
		<span itemprop="name"><?php echo get_comment_author(); ?></span>
	</div>
            <?php if ( x_is_product() && get_option('woocommerce_enable_review_rating') == 'yes' &&  get_comment_meta( $GLOBALS['comment']->comment_ID, 'rating', true ) > 0 ) : ?>
              <div class="star-rating-container">
                <div itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating" class="star-rating" title="<?php echo sprintf( __( 'Rated %d out of 5', '__x__' ), $rating ) ?>">
                  <span style="width:<?php echo ( intval( get_comment_meta( $GLOBALS['comment']->comment_ID, 'rating', true ) ) / 5 ) * 100; ?>%"><strong itemprop="ratingValue"><?php echo intval( get_comment_meta( $GLOBALS['comment']->comment_ID, 'rating', true ) ); ?></strong> <?php _e( 'out of 5', '__x__' ); ?></span>
                </div>
              </div>
            <?php endif;
            printf( '<div><a href="%1$s" class="x-comment-time"><time itemprop="datePublished" datetime="%2$s">%3$s</time></a></div>',
              esc_url( get_comment_link( $comment->comment_ID ) ),
              get_comment_time( 'c' ),
              sprintf( __( '%1$s at %2$s', '__x__' ),
                get_comment_date( 'm.d.Y' ),
                get_comment_time()
              )
            );
            edit_comment_link( __( '<i class="x-icon-edit" data-x-icon="&#xf044;"></i> Edit', '__x__' ) );
            ?>
          </header>
          <?php if ( '0' == $comment->comment_approved ) : ?>
            <p class="x-comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', '__x__' ); ?></p>
          <?php endif; ?>
          <section class="x-comment-content" itemprop="description">
            <?php comment_text(); ?>
          </section>
      </article>
    <?php
        break;
    endswitch;

  }

And there is no more review error in google structured data testing tool.

Thanks!

Hi, your code still results in an error for the reviewItem, I fixed that. The updated code can be found here: Pastebin

However, there is still three issues even with the code that I pasted.

  1. Author type is still “Thing” and not “Person”
  2. If there is a reply (by admin) to a comment, the reply is appended to the comment to which it is a reply
  3. If there is no rating (rating = 0), the structured data is in error

All issues can be seen in this image:

Hi there,

I don’t see that error when I tested the page, perhaps it appears on other pages. Glad it works now.

Thanks!

Glad it works? Sorry, but it does not!

Hi there,

You said you fixed it, just glad it’s fixed now. Plus, I don’t see any error, but glad you provided the URL you are testing as that solves the confusion and I don’t have any idea what page to test as I’m only limited to the provided URL in our existing discussion.

And let 's clear this up, the author is a Thing is because you removed the code that I added.

<div class="visually-hidden" itemprop="author" itemscope itemtype="http://schema.org/Person">
		<span itemprop="name"><?php echo get_comment_author(); ?></span>
	</div>

Please compare your PasteBin code to the code that I provided above. It’s the second time my added code is removed :slight_smile:

About the rating issue on that new page, I’ll see what I can find as this is a bit confusing. I’ll need some second opinion about it.

Thanks!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.