WooCommerce review modifications

Before updating to Pro V. 5 I was able to customize WooCommerce review content with following function :

// Individual Comment
// =============================================================================

//
// 1. Pingbacks and trackbacks.
// 2. Normal Comments.
//

if ( ! function_exists( 'x_icon_comment' ) ) :
  function x_icon_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_time = sprintf( __( '%1$s', '__x__' ), get_comment_date() );
      else :
        $comment_time = sprintf( __( '%1$s at %2$s', '__x__' ), get_comment_date(), get_comment_time() );
      endif;
    ?>
    <li id="li-comment-<?php comment_ID(); ?>" <?php echo apply_filters ('x_woocommerce_review_schema_attributes', ''); ?> <?php comment_class(); ?>>
      <?php $comment_reply = ( ! x_is_product() ) ? '<div class="x-reply">' . get_comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply<span class="comment-reply-link-after"><i class="x-icon-reply" data-x-icon-s="&#xf3e5;"></i></span>', '__x__' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ) . '</div>' : ''; ?>

      <article id="comment-<?php comment_ID(); ?>" class="comment">
        <header class="x-comment-header">
          <?php echo apply_filters ('x_woocommerce_review_schema_item', ''); ?>
          <?php
          $user_id = $comment->user_id;
          if ( $user_id ) {
	       $last_name = get_user_meta( $user_id, 'last_name', true );
          }
          printf( '<cite class="x-comment-author" itemprop="author">%1$s</cite>',
            $last_name
          );
          if ( x_is_product() && get_option( 'woocommerce_enable_review_rating' ) == 'yes' && !empty( $rating ) ) : ?>
            <div class="star-rating-container">
              <div <?php echo apply_filters ('x_woocommerce_review_schema_rating_attributes', ''); ?> 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;
          
          $timestamp = strtotime(get_comment_time( 'c' ));
          
          if (ICL_LANGUAGE_CODE == "en")
          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 ) ),
            $comment_time, date( 'j F Y', $timestamp )
            );
          
          elseif (ICL_LANGUAGE_CODE == "ar")
          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 ) ),
            $comment_time, jdate( 'j F Y', $timestamp )
            );

          edit_comment_link( sprintf( __( '%s Edit', '__x__' ), '<i class="x-icon-edit" data-x-icon-s="&#xf044;"></i>' ) );
          ?>
        </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;

  }
endif;

It seems above functions does not work anymore and I would know how can I manipulate review counter, profile picture and review date. Also I found review tab doesn’t switch to RTL mode on RTL languages but I could solve it before with CSS.

Thanks in advance.
Omid

Hello Omid,

Thanks for writing in! In the latest release, there is already a WooCoomerce template override for the single reviews. You can find it in wp-content/themes/pro/framework/legacy/templates/woocommerce/single-product-reviews.php. Please copy this file and add it to your child theme in the wp-content/themes/pro-child/framework/legacy/templates/woocommerce/single-product-reviews.php folder.

Hope this helps. Kindly let us know how it goes.

Hi @ruenel,

Thanks for reply; It seems moving file to child theme does not work for single-product-reviews.php , moreover let’s assume child theme will work, still I’m not able to find any code related to review date or customer picture in single-product-reviews.php.

Hello @omid020,

Please remove the following lines in your code:

if ( ! function_exists( 'x_icon_comment' ) ) : 
endif;

I have tested your code and it works on my end using the icon stack.

Best Regards.

Hi @ruenel,
I am also using ICON stack and I removed below lines but still it doesn’t work:

if ( ! function_exists( 'x_icon_comment' ) ) : 
endif;

I don’t have any PHP error, also I removed all other functions and deactivated other plugins but still comment function doesn’t work on my site.

Could you please kindly check it?

Thanks in advance.

Hi @omid020,

I have checked that code, and t worked in my local environment too. It might be something else is the reason behind your issue, I would suggest you please copy your live site to a staging server so we could troubleshoot freely without breaking your live site.
And give us access in the secure note including:

– WordPress Site URL & Login URL
– WordPress Admin username/password
– FTP/CPanel credentials to access the files.

To create a secure note, click the key icon underneath any of your posts.

Thanks

Hello @tristup; Currently I can make changes on WooCommerce review section only by manipulating this file:

/wp-content/plugins/woocommerce/templates/single-product-reviews.php

You may access to site with following secure note.

Hi @omid020,

The referred file is already overridden through the Theme File which has been mentioned by my colleague in his comment. I would suggest you please copy your live site to a staging server and give us the access to check why the theme files are not working at your website.
Modifying the plugin file directly is not suggested as it might be overridden by the upcoming plugin updates.

Thanks

Hello @tristup, feel free to check and even manipulate files with following credentials:

Hi @omid020,

After consulting with my colleague Rad, it has been found that the file single-product-reviews.php has to be in the WooCommerce folder directly in the case of Child Theme. After moving the file it starts working again.

Thanks

Yup, it works :+1:
Thank you so much!

Hi @omid020,

Glad that it works.

Thanks

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