2011-08-27 11:53:46 +00:00
|
|
|
<?php
|
2014-11-19 17:12:56 +00:00
|
|
|
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2011-08-27 11:53:46 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Top Rated Products Widget.
|
|
|
|
* Gets and displays top rated products in an unordered list.
|
2012-08-14 17:37:50 +00:00
|
|
|
*
|
2014-11-15 01:12:59 +00:00
|
|
|
* @author WooThemes
|
|
|
|
* @category Widgets
|
|
|
|
* @package WooCommerce/Widgets
|
2017-10-04 15:54:00 +00:00
|
|
|
* @version 3.3.0
|
2014-11-15 01:12:59 +00:00
|
|
|
* @extends WC_Widget
|
2011-08-27 11:53:46 +00:00
|
|
|
*/
|
2013-05-24 15:51:58 +00:00
|
|
|
class WC_Widget_Top_Rated_Products extends WC_Widget {
|
2012-08-14 17:37:50 +00:00
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +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_top_rated_products';
|
2017-08-25 11:07:17 +00:00
|
|
|
$this->widget_description = __( "A list of your store's top-rated products.", 'woocommerce' );
|
2013-05-24 15:51:58 +00:00
|
|
|
$this->widget_id = 'woocommerce_top_rated_products';
|
2017-08-25 11:07:17 +00:00
|
|
|
$this->widget_name = __( 'Products by Rating', 'woocommerce' );
|
2013-05-24 15:51:58 +00:00
|
|
|
$this->settings = array(
|
|
|
|
'title' => array(
|
|
|
|
'type' => 'text',
|
2016-10-12 10:16:30 +00:00
|
|
|
'std' => __( 'Top rated products', 'woocommerce' ),
|
2016-08-27 01:46:45 +00:00
|
|
|
'label' => __( 'Title', 'woocommerce' ),
|
2013-05-24 15:51:58 +00:00
|
|
|
),
|
|
|
|
'number' => array(
|
|
|
|
'type' => 'number',
|
|
|
|
'step' => 1,
|
|
|
|
'min' => 1,
|
|
|
|
'max' => '',
|
|
|
|
'std' => 5,
|
2016-08-27 01:46:45 +00:00
|
|
|
'label' => __( 'Number of products to show', 'woocommerce' ),
|
|
|
|
),
|
2013-05-24 15:51:58 +00:00
|
|
|
);
|
2014-11-15 01:12:59 +00:00
|
|
|
|
2013-05-24 15:51:58 +00:00
|
|
|
parent::__construct();
|
2011-08-27 11:53:46 +00:00
|
|
|
}
|
|
|
|
|
2012-08-14 17:37:50 +00:00
|
|
|
/**
|
2016-01-06 18:58:38 +00:00
|
|
|
* Output widget.
|
2012-08-14 17:37:50 +00:00
|
|
|
*
|
|
|
|
* @see WP_Widget
|
2014-11-15 01:12:59 +00:00
|
|
|
*
|
2012-08-14 17:37:50 +00:00
|
|
|
* @param array $args
|
|
|
|
* @param array $instance
|
|
|
|
*/
|
2014-11-15 01:12:59 +00:00
|
|
|
public function widget( $args, $instance ) {
|
2012-08-14 17:37:50 +00:00
|
|
|
|
2014-11-15 01:12:59 +00:00
|
|
|
if ( $this->get_cached_widget( $args ) ) {
|
2011-08-27 11:53:46 +00:00
|
|
|
return;
|
2014-11-15 01:12:59 +00:00
|
|
|
}
|
2011-08-27 11:53:46 +00:00
|
|
|
|
|
|
|
ob_start();
|
|
|
|
|
2014-11-15 01:12:59 +00:00
|
|
|
$number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std'];
|
2012-08-14 17:37:50 +00:00
|
|
|
|
2016-08-19 22:57:42 +00:00
|
|
|
$query_args = array(
|
|
|
|
'posts_per_page' => $number,
|
|
|
|
'no_found_rows' => 1,
|
|
|
|
'post_status' => 'publish',
|
|
|
|
'post_type' => 'product',
|
|
|
|
'meta_key' => '_wc_average_rating',
|
|
|
|
'orderby' => 'meta_value_num',
|
|
|
|
'order' => 'DESC',
|
2016-12-08 10:56:45 +00:00
|
|
|
'meta_query' => WC()->query->get_meta_query(),
|
|
|
|
'tax_query' => WC()->query->get_tax_query(),
|
2016-08-19 22:57:42 +00:00
|
|
|
);
|
2012-08-14 17:37:50 +00:00
|
|
|
|
2013-05-13 14:12:12 +00:00
|
|
|
$r = new WP_Query( $query_args );
|
2012-08-14 17:37:50 +00:00
|
|
|
|
2013-05-13 14:12:12 +00:00
|
|
|
if ( $r->have_posts() ) {
|
2011-08-27 11:53:46 +00:00
|
|
|
|
2014-11-15 01:12:59 +00:00
|
|
|
$this->widget_start( $args, $instance );
|
2013-05-13 14:12:12 +00:00
|
|
|
|
2017-10-27 14:35:34 +00:00
|
|
|
echo wp_kses_post( apply_filters( 'woocommerce_before_widget_product_list', '<ul class="product_list_widget">' ) );
|
2013-05-13 14:12:12 +00:00
|
|
|
|
2017-10-03 20:52:36 +00:00
|
|
|
$template_args = array(
|
2017-10-27 14:35:34 +00:00
|
|
|
'widget_id' => $args['widget_id'],
|
|
|
|
'show_rating' => true,
|
2017-10-03 20:52:36 +00:00
|
|
|
);
|
|
|
|
|
2013-05-13 14:12:12 +00:00
|
|
|
while ( $r->have_posts() ) {
|
|
|
|
$r->the_post();
|
2017-10-03 20:52:36 +00:00
|
|
|
wc_get_template( 'content-widget-product.php', $template_args );
|
2013-05-13 14:12:12 +00:00
|
|
|
}
|
|
|
|
|
2017-10-27 14:35:34 +00:00
|
|
|
echo wp_kses_post( apply_filters( 'woocommerce_after_widget_product_list', '</ul>' ) );
|
2013-05-13 14:12:12 +00:00
|
|
|
|
2014-11-15 01:12:59 +00:00
|
|
|
$this->widget_end( $args );
|
2013-05-13 14:12:12 +00:00
|
|
|
}
|
2012-08-14 17:37:50 +00:00
|
|
|
|
2013-05-24 15:51:58 +00:00
|
|
|
wp_reset_postdata();
|
2012-05-13 21:39:21 +00:00
|
|
|
|
2013-05-24 15:51:58 +00:00
|
|
|
$content = ob_get_clean();
|
2012-08-14 17:37:50 +00:00
|
|
|
|
2012-05-13 21:39:21 +00:00
|
|
|
echo $content;
|
2012-08-14 17:37:50 +00:00
|
|
|
|
2013-05-24 15:51:58 +00:00
|
|
|
$this->cache_widget( $args, $content );
|
2011-08-27 11:53:46 +00:00
|
|
|
}
|
2013-05-24 15:51:58 +00:00
|
|
|
}
|