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3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / widgets / class-wc-widget-products.php
woocommerce / includes / widgets Last commit date
class-wc-widget-brand-description.php 1 year ago class-wc-widget-brand-nav.php 1 year ago class-wc-widget-brand-thumbnails.php 1 year ago class-wc-widget-cart.php 3 years ago class-wc-widget-layered-nav-filters.php 2 years ago class-wc-widget-layered-nav.php 4 years ago class-wc-widget-price-filter.php 5 years ago class-wc-widget-product-categories.php 5 years ago class-wc-widget-product-search.php 5 years ago class-wc-widget-product-tag-cloud.php 5 years ago class-wc-widget-products.php 3 years ago class-wc-widget-rating-filter.php 5 years ago class-wc-widget-recent-reviews.php 5 years ago class-wc-widget-recently-viewed.php 4 years ago class-wc-widget-top-rated-products.php 4 years ago
class-wc-widget-products.php
221 lines
1 <?php
2 /**
3 * List products. One widget to rule them all.
4 *
5 * @package WooCommerce\Widgets
6 * @version 3.3.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * Widget products.
13 */
14 class WC_Widget_Products extends WC_Widget {
15
16 /**
17 * Constructor.
18 */
19 public function __construct() {
20 $this->widget_cssclass = 'woocommerce widget_products';
21 $this->widget_description = __( "A list of your store's products.", 'woocommerce' );
22 $this->widget_id = 'woocommerce_products';
23 $this->widget_name = __( 'Products list', 'woocommerce' );
24 $this->settings = array(
25 'title' => array(
26 'type' => 'text',
27 'std' => __( 'Products', 'woocommerce' ),
28 'label' => __( 'Title', 'woocommerce' ),
29 ),
30 'number' => array(
31 'type' => 'number',
32 'step' => 1,
33 'min' => 1,
34 'max' => '',
35 'std' => 5,
36 'label' => __( 'Number of products to show', 'woocommerce' ),
37 ),
38 'show' => array(
39 'type' => 'select',
40 'std' => '',
41 'label' => __( 'Show', 'woocommerce' ),
42 'options' => array(
43 '' => __( 'All products', 'woocommerce' ),
44 'featured' => __( 'Featured products', 'woocommerce' ),
45 'onsale' => __( 'On-sale products', 'woocommerce' ),
46 ),
47 ),
48 'orderby' => array(
49 'type' => 'select',
50 'std' => 'date',
51 'label' => __( 'Order by', 'woocommerce' ),
52 'options' => array(
53 'menu_order' => __( 'Menu order', 'woocommerce' ),
54 'date' => __( 'Date', 'woocommerce' ),
55 'price' => __( 'Price', 'woocommerce' ),
56 'rand' => __( 'Random', 'woocommerce' ),
57 'sales' => __( 'Sales', 'woocommerce' ),
58 ),
59 ),
60 'order' => array(
61 'type' => 'select',
62 'std' => 'desc',
63 'label' => _x( 'Order', 'Sorting order', 'woocommerce' ),
64 'options' => array(
65 'asc' => __( 'ASC', 'woocommerce' ),
66 'desc' => __( 'DESC', 'woocommerce' ),
67 ),
68 ),
69 'hide_free' => array(
70 'type' => 'checkbox',
71 'std' => 0,
72 'label' => __( 'Hide free products', 'woocommerce' ),
73 ),
74 'show_hidden' => array(
75 'type' => 'checkbox',
76 'std' => 0,
77 'label' => __( 'Show hidden products', 'woocommerce' ),
78 ),
79 );
80
81 parent::__construct();
82 }
83
84 /**
85 * Query the products and return them.
86 *
87 * @param array $args Arguments.
88 * @param array $instance Widget instance.
89 *
90 * @return WP_Query
91 */
92 public function get_products( $args, $instance ) {
93 $number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std'];
94 $show = ! empty( $instance['show'] ) ? sanitize_title( $instance['show'] ) : $this->settings['show']['std'];
95 $orderby = ! empty( $instance['orderby'] ) ? sanitize_title( $instance['orderby'] ) : $this->settings['orderby']['std'];
96 $order = ! empty( $instance['order'] ) ? sanitize_title( $instance['order'] ) : $this->settings['order']['std'];
97 $product_visibility_term_ids = wc_get_product_visibility_term_ids();
98
99 $query_args = array(
100 'posts_per_page' => $number,
101 'post_status' => 'publish',
102 'post_type' => 'product',
103 'no_found_rows' => 1,
104 'order' => $order,
105 'meta_query' => array(),
106 'tax_query' => array(
107 'relation' => 'AND',
108 ),
109 ); // WPCS: slow query ok.
110
111 if ( empty( $instance['show_hidden'] ) ) {
112 $query_args['tax_query'][] = array(
113 'taxonomy' => 'product_visibility',
114 'field' => 'term_taxonomy_id',
115 'terms' => is_search() ? $product_visibility_term_ids['exclude-from-search'] : $product_visibility_term_ids['exclude-from-catalog'],
116 'operator' => 'NOT IN',
117 );
118 $query_args['post_parent'] = 0;
119 }
120
121 if ( ! empty( $instance['hide_free'] ) ) {
122 $query_args['meta_query'][] = array(
123 'key' => '_price',
124 'value' => 0,
125 'compare' => '>',
126 'type' => 'DECIMAL',
127 );
128 }
129
130 if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ) {
131 $query_args['tax_query'][] = array(
132 array(
133 'taxonomy' => 'product_visibility',
134 'field' => 'term_taxonomy_id',
135 'terms' => $product_visibility_term_ids['outofstock'],
136 'operator' => 'NOT IN',
137 ),
138 ); // WPCS: slow query ok.
139 }
140
141 switch ( $show ) {
142 case 'featured':
143 $query_args['tax_query'][] = array(
144 'taxonomy' => 'product_visibility',
145 'field' => 'term_taxonomy_id',
146 'terms' => $product_visibility_term_ids['featured'],
147 );
148 break;
149 case 'onsale':
150 $product_ids_on_sale = wc_get_product_ids_on_sale();
151 $product_ids_on_sale[] = 0;
152 $query_args['post__in'] = $product_ids_on_sale;
153 break;
154 }
155
156 switch ( $orderby ) {
157 case 'menu_order':
158 $query_args['orderby'] = 'menu_order';
159 break;
160 case 'price':
161 $query_args['meta_key'] = '_price'; // WPCS: slow query ok.
162 $query_args['orderby'] = 'meta_value_num';
163 break;
164 case 'rand':
165 $query_args['orderby'] = 'rand';
166 break;
167 case 'sales':
168 $query_args['meta_key'] = 'total_sales'; // WPCS: slow query ok.
169 $query_args['orderby'] = 'meta_value_num';
170 break;
171 default:
172 $query_args['orderby'] = 'date';
173 }
174
175 return new WP_Query( apply_filters( 'woocommerce_products_widget_query_args', $query_args ) );
176 }
177
178 /**
179 * Output widget.
180 *
181 * @param array $args Arguments.
182 * @param array $instance Widget instance.
183 *
184 * @see WP_Widget
185 */
186 public function widget( $args, $instance ) {
187 if ( $this->get_cached_widget( $args ) ) {
188 return;
189 }
190
191 ob_start();
192
193 wc_set_loop_prop( 'name', 'widget' );
194
195 $products = $this->get_products( $args, $instance );
196 if ( $products && $products->have_posts() ) {
197 $this->widget_start( $args, $instance );
198
199 echo wp_kses_post( apply_filters( 'woocommerce_before_widget_product_list', '<ul class="product_list_widget">' ) );
200
201 $template_args = array(
202 'widget_id' => isset( $args['widget_id'] ) ? $args['widget_id'] : $this->widget_id,
203 'show_rating' => true,
204 );
205
206 while ( $products->have_posts() ) {
207 $products->the_post();
208 wc_get_template( 'content-widget-product.php', $template_args );
209 }
210
211 echo wp_kses_post( apply_filters( 'woocommerce_after_widget_product_list', '</ul>' ) );
212
213 $this->widget_end( $args );
214 }
215
216 wp_reset_postdata();
217
218 echo $this->cache_widget( $args, ob_get_clean() ); // WPCS: XSS ok.
219 }
220 }
221