Recent Product Reviews template

This commit is contained in:
Ernest 2018-04-13 14:20:46 +03:00
parent b6ac275713
commit 0d70b3b34e
2 changed files with 43 additions and 19 deletions

View File

@ -70,31 +70,19 @@ class WC_Widget_Recent_Reviews extends WC_Widget {
if ( $comments ) { if ( $comments ) {
$this->widget_start( $args, $instance ); $this->widget_start( $args, $instance );
echo '<ul class="product_list_widget">'; echo wp_kses_post( apply_filters( 'woocommerce_before_widget_product_review_list', '<ul class="product_list_widget">' ) );
foreach ( (array) $comments as $comment ) { foreach ( (array) $comments as $comment ) {
wc_get_template( 'content-widget-reviews.php', array(
$_product = wc_get_product( $comment->comment_post_ID ); 'comment' => $comment,
'product' => wc_get_product( $comment->comment_post_ID ),
$rating = intval( get_comment_meta( $comment->comment_ID, 'rating', true ) ); ) );
$rating_html = wc_get_rating_html( $rating );
echo '<li><a href="' . esc_url( get_comment_link( $comment->comment_ID ) ) . '">';
echo $_product->get_image() . wp_kses_post( $_product->get_name() ) . '</a>'; // WPCS: XSS ok.
echo $rating_html; // WPCS: XSS ok.
/* translators: %s: review author */
echo '<span class="reviewer">' . sprintf( esc_html__( 'by %s', 'woocommerce' ), get_comment_author() ) . '</span>'; // WPCS: XSS ok.
echo '</li>';
} }
echo '</ul>'; echo wp_kses_post( apply_filters( 'woocommerce_after_widget_product_review_list', '</ul>' ) );
$this->widget_end( $args ); $this->widget_end( $args );
} }
$content = ob_get_clean(); $content = ob_get_clean();

View File

@ -0,0 +1,36 @@
<?php
/**
* The template for displaying product widget entries.
*
* This template can be overridden by copying it to yourtheme/woocommerce/content-widget-reviews.php
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 3.3.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<li>
<?php do_action( 'woocommerce_widget_product_review_item_start', $args ); ?>
<a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
<?php echo $product->get_image(); ?>
<span class="product-title"><?php echo $product->get_name(); ?></span>
</a>
<?php echo wc_get_rating_html( intval( get_comment_meta( $comment->comment_ID, 'rating', true ) ) );?>
<span class="reviewer"><?php echo sprintf( esc_html__( 'by %s', 'woocommerce' ), get_comment_author( $comment->comment_ID ) ); ?></span>
<?php do_action( 'woocommerce_widget_product_review_item_end', $args ); ?>
</li>