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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-cart.php 7 years ago class-wc-widget-layered-nav-filters.php 7 years ago class-wc-widget-layered-nav.php 7 years ago class-wc-widget-price-filter.php 6 years ago class-wc-widget-product-categories.php 7 years ago class-wc-widget-product-search.php 8 years ago class-wc-widget-product-tag-cloud.php 8 years ago class-wc-widget-products.php 7 years ago class-wc-widget-rating-filter.php 7 years ago class-wc-widget-recent-reviews.php 8 years ago class-wc-widget-recently-viewed.php 8 years ago class-wc-widget-top-rated-products.php 8 years ago
class-wc-widget-products.php
215 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', '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 'date' => __( 'Date', 'woocommerce' ),
54 'price' => __( 'Price', 'woocommerce' ),
55 'rand' => __( 'Random', 'woocommerce' ),
56 'sales' => __( 'Sales', 'woocommerce' ),
57 ),
58 ),
59 'order' => array(
60 'type' => 'select',
61 'std' => 'desc',
62 'label' => _x( 'Order', 'Sorting order', 'woocommerce' ),
63 'options' => array(
64 'asc' => __( 'ASC', 'woocommerce' ),
65 'desc' => __( 'DESC', 'woocommerce' ),
66 ),
67 ),
68 'hide_free' => array(
69 'type' => 'checkbox',
70 'std' => 0,
71 'label' => __( 'Hide free products', 'woocommerce' ),
72 ),
73 'show_hidden' => array(
74 'type' => 'checkbox',
75 'std' => 0,
76 'label' => __( 'Show hidden products', 'woocommerce' ),
77 ),
78 );
79
80 parent::__construct();
81 }
82
83 /**
84 * Query the products and return them.
85 *
86 * @param array $args Arguments.
87 * @param array $instance Widget instance.
88 *
89 * @return WP_Query
90 */
91 public function get_products( $args, $instance ) {
92 $number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std'];
93 $show = ! empty( $instance['show'] ) ? sanitize_title( $instance['show'] ) : $this->settings['show']['std'];
94 $orderby = ! empty( $instance['orderby'] ) ? sanitize_title( $instance['orderby'] ) : $this->settings['orderby']['std'];
95 $order = ! empty( $instance['order'] ) ? sanitize_title( $instance['order'] ) : $this->settings['order']['std'];
96 $product_visibility_term_ids = wc_get_product_visibility_term_ids();
97
98 $query_args = array(
99 'posts_per_page' => $number,
100 'post_status' => 'publish',
101 'post_type' => 'product',
102 'no_found_rows' => 1,
103 'order' => $order,
104 'meta_query' => array(),
105 'tax_query' => array(
106 'relation' => 'AND',
107 ),
108 ); // WPCS: slow query ok.
109
110 if ( empty( $instance['show_hidden'] ) ) {
111 $query_args['tax_query'][] = array(
112 'taxonomy' => 'product_visibility',
113 'field' => 'term_taxonomy_id',
114 'terms' => is_search() ? $product_visibility_term_ids['exclude-from-search'] : $product_visibility_term_ids['exclude-from-catalog'],
115 'operator' => 'NOT IN',
116 );
117 $query_args['post_parent'] = 0;
118 }
119
120 if ( ! empty( $instance['hide_free'] ) ) {
121 $query_args['meta_query'][] = array(
122 'key' => '_price',
123 'value' => 0,
124 'compare' => '>',
125 'type' => 'DECIMAL',
126 );
127 }
128
129 if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ) {
130 $query_args['tax_query'][] = array(
131 array(
132 'taxonomy' => 'product_visibility',
133 'field' => 'term_taxonomy_id',
134 'terms' => $product_visibility_term_ids['outofstock'],
135 'operator' => 'NOT IN',
136 ),
137 ); // WPCS: slow query ok.
138 }
139
140 switch ( $show ) {
141 case 'featured':
142 $query_args['tax_query'][] = array(
143 'taxonomy' => 'product_visibility',
144 'field' => 'term_taxonomy_id',
145 'terms' => $product_visibility_term_ids['featured'],
146 );
147 break;
148 case 'onsale':
149 $product_ids_on_sale = wc_get_product_ids_on_sale();
150 $product_ids_on_sale[] = 0;
151 $query_args['post__in'] = $product_ids_on_sale;
152 break;
153 }
154
155 switch ( $orderby ) {
156 case 'price':
157 $query_args['meta_key'] = '_price'; // WPCS: slow query ok.
158 $query_args['orderby'] = 'meta_value_num';
159 break;
160 case 'rand':
161 $query_args['orderby'] = 'rand';
162 break;
163 case 'sales':
164 $query_args['meta_key'] = 'total_sales'; // WPCS: slow query ok.
165 $query_args['orderby'] = 'meta_value_num';
166 break;
167 default:
168 $query_args['orderby'] = 'date';
169 }
170
171 return new WP_Query( apply_filters( 'woocommerce_products_widget_query_args', $query_args ) );
172 }
173
174 /**
175 * Output widget.
176 *
177 * @param array $args Arguments.
178 * @param array $instance Widget instance.
179 *
180 * @see WP_Widget
181 */
182 public function widget( $args, $instance ) {
183 if ( $this->get_cached_widget( $args ) ) {
184 return;
185 }
186
187 ob_start();
188
189 $products = $this->get_products( $args, $instance );
190 if ( $products && $products->have_posts() ) {
191 $this->widget_start( $args, $instance );
192
193 echo wp_kses_post( apply_filters( 'woocommerce_before_widget_product_list', '<ul class="product_list_widget">' ) );
194
195 $template_args = array(
196 'widget_id' => $args['widget_id'],
197 'show_rating' => true,
198 );
199
200 while ( $products->have_posts() ) {
201 $products->the_post();
202 wc_get_template( 'content-widget-product.php', $template_args );
203 }
204
205 echo wp_kses_post( apply_filters( 'woocommerce_after_widget_product_list', '</ul>' ) );
206
207 $this->widget_end( $args );
208 }
209
210 wp_reset_postdata();
211
212 echo $this->cache_widget( $args, ob_get_clean() ); // WPCS: XSS ok.
213 }
214 }
215