widget_cssclass = 'woocommerce widget_recent_reviews'; $this->widget_description = __( 'Display a list of recent reviews from your store.', 'woocommerce' ); $this->widget_id = 'woocommerce_recent_reviews'; $this->widget_name = __( 'Recent Product 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(); } /** * Output widget. * * @see WP_Widget * * @param array $args * @param array $instance */ public function widget( $args, $instance ) { global $comments, $comment; if ( $this->get_cached_widget( $args ) ) { return; } ob_start(); $number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std']; $comments = get_comments( array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish', 'post_type' => 'product', 'parent' => 0 ) ); if ( $comments ) { $this->widget_start( $args, $instance ); echo '
'; $this->widget_end( $args ); } $content = ob_get_clean(); echo $content; $this->cache_widget( $args, $content ); } }