2011-08-29 10:38:01 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Recent Reviews Widget
|
2012-08-14 17:37:50 +00:00
|
|
|
*
|
|
|
|
* @author WooThemes
|
|
|
|
* @category Widgets
|
|
|
|
* @package WooCommerce/Widgets
|
2013-05-24 15:51:58 +00:00
|
|
|
* @version 2.1.0
|
|
|
|
* @extends WC_Widget
|
2011-08-29 10:38:01 +00:00
|
|
|
*/
|
2012-10-15 10:57:58 +00:00
|
|
|
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|
|
|
|
2013-05-24 15:51:58 +00:00
|
|
|
class WC_Widget_Recent_Reviews extends WC_Widget {
|
2012-08-14 17:37:50 +00:00
|
|
|
|
|
|
|
/**
|
2013-05-24 15:51:58 +00:00
|
|
|
* Constructor
|
2012-08-14 17:37:50 +00:00
|
|
|
*/
|
2013-05-24 15:51:58 +00:00
|
|
|
public function __construct() {
|
|
|
|
$this->widget_cssclass = 'woocommerce widget_recent_reviews';
|
|
|
|
$this->widget_description = __( 'Display a list of your most recent reviews on your site.', 'woocommerce' );
|
|
|
|
$this->widget_id = 'woocommerce_recent_reviews';
|
|
|
|
$this->widget_name = __( 'WooCommerce Recent Reviews', 'woocommerce' );
|
|
|
|
$this->settings = array(
|
|
|
|
'title' => array(
|
|
|
|
'type' => 'text',
|
|
|
|
'std' => __( 'Recent Reviews', 'woocommerce' ),
|
|
|
|
'label' => __( 'Title', 'woocommerce' )
|
|
|
|
),
|
|
|
|
'number' => array(
|
|
|
|
'type' => 'number',
|
|
|
|
'step' => 1,
|
|
|
|
'min' => 1,
|
|
|
|
'max' => '',
|
|
|
|
'std' => 10,
|
|
|
|
'label' => __( 'Number of reviews to show', 'woocommerce' )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
parent::__construct();
|
2011-08-29 10:38:01 +00:00
|
|
|
}
|
2012-08-14 17:37:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* widget function.
|
|
|
|
*
|
|
|
|
* @see WP_Widget
|
|
|
|
* @access public
|
|
|
|
* @param array $args
|
|
|
|
* @param array $instance
|
|
|
|
* @return void
|
|
|
|
*/
|
2013-05-24 15:51:58 +00:00
|
|
|
public function widget( $args, $instance ) {
|
2014-06-08 20:33:11 +00:00
|
|
|
global $comments, $comment;
|
2012-08-14 17:37:50 +00:00
|
|
|
|
2013-05-24 15:51:58 +00:00
|
|
|
if ( $this->get_cached_widget( $args ) )
|
2011-08-29 10:38:01 +00:00
|
|
|
return;
|
|
|
|
|
2013-05-24 15:51:58 +00:00
|
|
|
ob_start();
|
|
|
|
extract( $args );
|
2012-08-14 17:37:50 +00:00
|
|
|
|
2013-05-24 15:51:58 +00:00
|
|
|
$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
|
|
|
|
$number = absint( $instance['number'] );
|
2011-08-29 12:48:50 +00:00
|
|
|
$comments = get_comments( array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish', 'post_type' => 'product' ) );
|
2012-08-14 17:37:50 +00:00
|
|
|
|
2012-10-18 10:33:47 +00:00
|
|
|
if ( $comments ) {
|
2011-08-29 10:38:01 +00:00
|
|
|
echo $before_widget;
|
|
|
|
if ( $title ) echo $before_title . $title . $after_title;
|
|
|
|
echo '<ul class="product_list_widget">';
|
2012-08-14 17:37:50 +00:00
|
|
|
|
2013-05-13 14:12:12 +00:00
|
|
|
foreach ( (array) $comments as $comment ) {
|
2012-08-14 17:37:50 +00:00
|
|
|
|
2012-11-21 18:07:45 +00:00
|
|
|
$_product = get_product( $comment->comment_post_ID );
|
2012-08-14 17:37:50 +00:00
|
|
|
|
2012-10-16 13:06:06 +00:00
|
|
|
$rating = intval( get_comment_meta( $comment->comment_ID, 'rating', true ) );
|
2012-08-14 17:37:50 +00:00
|
|
|
|
2013-03-28 13:58:01 +00:00
|
|
|
$rating_html = $_product->get_rating_html( $rating );
|
2012-08-14 17:37:50 +00:00
|
|
|
|
2012-10-18 10:33:47 +00:00
|
|
|
echo '<li><a href="' . esc_url( get_comment_link( $comment->comment_ID ) ) . '">';
|
2012-08-14 17:37:50 +00:00
|
|
|
|
2011-11-09 15:39:14 +00:00
|
|
|
echo $_product->get_image();
|
2012-08-14 17:37:50 +00:00
|
|
|
|
2011-11-14 01:20:07 +00:00
|
|
|
echo $_product->get_title().'</a>';
|
2012-08-14 17:37:50 +00:00
|
|
|
|
2011-08-29 10:38:01 +00:00
|
|
|
echo $rating_html;
|
2012-08-14 17:37:50 +00:00
|
|
|
|
2013-09-04 13:32:16 +00:00
|
|
|
printf( '<span class="reviewer">' . _x( 'by %1$s', 'by comment author', 'woocommerce' ) . '</span>', get_comment_author() );
|
|
|
|
|
|
|
|
echo '</li>';
|
2012-10-18 10:33:47 +00:00
|
|
|
}
|
2011-08-29 10:38:01 +00:00
|
|
|
|
|
|
|
echo '</ul>';
|
|
|
|
echo $after_widget;
|
2012-10-18 10:33:47 +00:00
|
|
|
}
|
2011-08-29 10:38:01 +00:00
|
|
|
|
2012-05-13 21:39:21 +00:00
|
|
|
$content = ob_get_clean();
|
|
|
|
|
|
|
|
echo $content;
|
|
|
|
|
2013-05-24 15:51:58 +00:00
|
|
|
$this->cache_widget( $args, $content );
|
2011-08-29 10:38:01 +00:00
|
|
|
}
|
2013-05-24 15:51:58 +00:00
|
|
|
}
|
2011-08-29 10:38:01 +00:00
|
|
|
|
2013-05-24 15:51:58 +00:00
|
|
|
register_widget( 'WC_Widget_Recent_Reviews' );
|