WC_Widget_Recent_Reviews

Recent Reviews Widget.

Defined (1)

The class is defined in the following location(s).

/includes/widgets/class-wc-widget-recent-reviews.php  
  1. class WC_Widget_Recent_Reviews extends WC_Widget { 
  2.  
  3. /** 
  4. * Constructor. 
  5. */ 
  6. public function __construct() { 
  7. $this->widget_cssclass = 'woocommerce widget_recent_reviews'; 
  8. $this->widget_description = __( 'Display a list of your most recent reviews on your site.', 'woocommerce' ); 
  9. $this->widget_id = 'woocommerce_recent_reviews'; 
  10. $this->widget_name = __( 'WooCommerce recent reviews', 'woocommerce' ); 
  11. $this->settings = array( 
  12. 'title' => array( 
  13. 'type' => 'text',  
  14. 'std' => __( 'Recent reviews', 'woocommerce' ),  
  15. 'label' => __( 'Title', 'woocommerce' ),  
  16. ),  
  17. 'number' => array( 
  18. 'type' => 'number',  
  19. 'step' => 1,  
  20. 'min' => 1,  
  21. 'max' => '',  
  22. 'std' => 10,  
  23. 'label' => __( 'Number of reviews to show', 'woocommerce' ),  
  24. ),  
  25. ); 
  26.  
  27. parent::__construct(); 
  28.  
  29. /** 
  30. * Output widget. 
  31. * @see WP_Widget 
  32. * @param array $args 
  33. * @param array $instance 
  34. */ 
  35. public function widget( $args, $instance ) { 
  36. global $comments, $comment; 
  37.  
  38. if ( $this->get_cached_widget( $args ) ) { 
  39. return; 
  40.  
  41. ob_start(); 
  42.  
  43. $number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std']; 
  44. $comments = get_comments( array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish', 'post_type' => 'product' ) ); 
  45.  
  46. if ( $comments ) { 
  47. $this->widget_start( $args, $instance ); 
  48.  
  49. echo '<ul class="product_list_widget">'; 
  50.  
  51. foreach ( (array) $comments as $comment ) { 
  52.  
  53. $_product = wc_get_product( $comment->comment_post_ID ); 
  54.  
  55. $rating = intval( get_comment_meta( $comment->comment_ID, 'rating', true ) ); 
  56.  
  57. $rating_html = wc_get_rating_html( $rating ); 
  58.  
  59. echo '<li><a href="' . esc_url( get_comment_link( $comment->comment_ID ) ) . '">'; 
  60.  
  61. echo $_product->get_image() . wp_kses_post( $_product->get_name() ) . '</a>'; 
  62.  
  63. echo $rating_html; 
  64.  
  65. /** translators: %s: review author */ 
  66. echo '<span class="reviewer">' . sprintf( esc_html__( 'by %s', 'woocommerce' ), get_comment_author() ) . '</span>'; 
  67.  
  68. echo '</li>'; 
  69.  
  70. echo '</ul>'; 
  71.  
  72. $this->widget_end( $args ); 
  73.  
  74. $content = ob_get_clean(); 
  75.  
  76. echo $content; 
  77.  
  78. $this->cache_widget( $args, $content );