PageRenderTime 26ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/woocommerce/includes/widgets/class-wc-widget-top-rated-products.php

https://gitlab.com/webkod3r/tripolis
PHP | 99 lines | 54 code | 23 blank | 22 comment | 4 complexity | a8ed9bb2dddd3cf50f90a2aa52d8243c MD5 | raw file
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit;
  4. }
  5. /**
  6. * Top Rated Products Widget.
  7. *
  8. * Gets and displays top rated products in an unordered list.
  9. *
  10. * @author WooThemes
  11. * @category Widgets
  12. * @package WooCommerce/Widgets
  13. * @version 2.3.0
  14. * @extends WC_Widget
  15. */
  16. class WC_Widget_Top_Rated_Products extends WC_Widget {
  17. /**
  18. * Constructor.
  19. */
  20. public function __construct() {
  21. $this->widget_cssclass = 'woocommerce widget_top_rated_products';
  22. $this->widget_description = __( 'Display a list of your top rated products on your site.', 'woocommerce' );
  23. $this->widget_id = 'woocommerce_top_rated_products';
  24. $this->widget_name = __( 'WooCommerce Top Rated Products', 'woocommerce' );
  25. $this->settings = array(
  26. 'title' => array(
  27. 'type' => 'text',
  28. 'std' => __( 'Top Rated Products', 'woocommerce' ),
  29. 'label' => __( 'Title', 'woocommerce' )
  30. ),
  31. 'number' => array(
  32. 'type' => 'number',
  33. 'step' => 1,
  34. 'min' => 1,
  35. 'max' => '',
  36. 'std' => 5,
  37. 'label' => __( 'Number of products to show', 'woocommerce' )
  38. )
  39. );
  40. parent::__construct();
  41. }
  42. /**
  43. * Output widget.
  44. *
  45. * @see WP_Widget
  46. *
  47. * @param array $args
  48. * @param array $instance
  49. */
  50. public function widget( $args, $instance ) {
  51. if ( $this->get_cached_widget( $args ) ) {
  52. return;
  53. }
  54. ob_start();
  55. $number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std'];
  56. add_filter( 'posts_clauses', array( WC()->query, 'order_by_rating_post_clauses' ) );
  57. $query_args = array( 'posts_per_page' => $number, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product' );
  58. $query_args['meta_query'] = WC()->query->get_meta_query();
  59. $r = new WP_Query( $query_args );
  60. if ( $r->have_posts() ) {
  61. $this->widget_start( $args, $instance );
  62. echo '<ul class="product_list_widget">';
  63. while ( $r->have_posts() ) {
  64. $r->the_post();
  65. wc_get_template( 'content-widget-product.php', array( 'show_rating' => true ) );
  66. }
  67. echo '</ul>';
  68. $this->widget_end( $args );
  69. }
  70. remove_filter( 'posts_clauses', array( WC()->query, 'order_by_rating_post_clauses' ) );
  71. wp_reset_postdata();
  72. $content = ob_get_clean();
  73. echo $content;
  74. $this->cache_widget( $args, $content );
  75. }
  76. }