1 <?php
  2 /**
  3  * Recent Reviews Widget
  4  *
  5  * @author      WooThemes
  6  * @category    Widgets
  7  * @package     WooCommerce/Widgets
  8  * @version     2.1.0
  9  * @extends     WC_Widget
 10  */
 11 
 12 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
 13 
 14 class WC_Widget_Recent_Reviews extends WC_Widget {
 15 
 16     /**
 17      * Constructor
 18      */
 19     public function __construct() {
 20         $this->widget_cssclass    = 'woocommerce widget_recent_reviews';
 21         $this->widget_description = __( 'Display a list of your most recent reviews on your site.', 'woocommerce' );
 22         $this->widget_id          = 'woocommerce_recent_reviews';
 23         $this->widget_name        = __( 'WooCommerce Recent Reviews', 'woocommerce' );
 24         $this->settings           = array(
 25             'title'  => array(
 26                 'type'  => 'text',
 27                 'std'   => __( 'Recent Reviews', 'woocommerce' ),
 28                 'label' => __( 'Title', 'woocommerce' )
 29             ),
 30             'number' => array(
 31                 'type'  => 'number',
 32                 'step'  => 1,
 33                 'min'   => 1,
 34                 'max'   => '',
 35                 'std'   => 10,
 36                 'label' => __( 'Number of reviews to show', 'woocommerce' )
 37             )
 38         );
 39         parent::__construct();
 40     }
 41 
 42     /**
 43      * widget function.
 44      *
 45      * @see WP_Widget
 46      * @access public
 47      * @param array $args
 48      * @param array $instance
 49      * @return void
 50      */
 51      public function widget( $args, $instance ) {
 52         global $comments, $comment, $woocommerce;
 53 
 54         if ( $this->get_cached_widget( $args ) )
 55             return;
 56 
 57         ob_start();
 58         extract( $args );
 59 
 60         $title    = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
 61         $number   = absint( $instance['number'] );
 62         $comments = get_comments( array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish', 'post_type' => 'product' ) );
 63 
 64         if ( $comments ) {
 65             echo $before_widget;
 66             if ( $title ) echo $before_title . $title . $after_title;
 67             echo '<ul class="product_list_widget">';
 68 
 69             foreach ( (array) $comments as $comment ) {
 70 
 71                 $_product = get_product( $comment->comment_post_ID );
 72 
 73                 $rating = intval( get_comment_meta( $comment->comment_ID, 'rating', true ) );
 74 
 75                 $rating_html = $_product->get_rating_html( $rating );
 76 
 77                 echo '<li><a href="' . esc_url( get_comment_link( $comment->comment_ID ) ) . '">';
 78 
 79                 echo $_product->get_image();
 80 
 81                 echo $_product->get_title().'</a>';
 82 
 83                 echo $rating_html;
 84 
 85                 printf( '<span class="reviewer">' . _x( 'by %1$s', 'by comment author', 'woocommerce' ) . '</span>', get_comment_author() );
 86 
 87                 echo '</li>';
 88             }
 89 
 90             echo '</ul>';
 91             echo $after_widget;
 92         }
 93 
 94         $content = ob_get_clean();
 95 
 96         echo $content;
 97 
 98         $this->cache_widget( $args, $content );
 99     }
100 }
101 
102 register_widget( 'WC_Widget_Recent_Reviews' );
WooCommerce API documentation generated by ApiGen 2.8.0