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.0.9 6.2.0-rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 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-product-categories.php
woocommerce / includes / widgets Last commit date
class-wc-widget-brand-description.php 1 year ago class-wc-widget-brand-nav.php 7 months 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 3 months ago class-wc-widget-price-filter.php 8 months ago class-wc-widget-product-categories.php 7 months 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 1 year ago class-wc-widget-rating-filter.php 5 years ago class-wc-widget-recent-reviews.php 2 months ago class-wc-widget-recently-viewed.php 1 year ago class-wc-widget-top-rated-products.php 5 years ago
class-wc-widget-product-categories.php
302 lines
1 <?php
2 /**
3 * Product Categories Widget
4 *
5 * @package WooCommerce\Widgets
6 * @version 2.3.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * Product categories widget class.
13 *
14 * @extends WC_Widget
15 */
16 class WC_Widget_Product_Categories extends WC_Widget {
17
18 /**
19 * Category ancestors.
20 *
21 * @var array
22 */
23 public $cat_ancestors;
24
25 /**
26 * Current Category.
27 *
28 * @var bool
29 */
30 public $current_cat;
31
32 /**
33 * Constructor.
34 */
35 public function __construct() {
36 $this->widget_cssclass = 'woocommerce widget_product_categories';
37 $this->widget_description = __( 'A list or dropdown of product categories.', 'woocommerce' );
38 $this->widget_id = 'woocommerce_product_categories';
39 $this->widget_name = __( 'Product Categories', 'woocommerce' );
40 $this->settings = array(
41 'title' => array(
42 'type' => 'text',
43 'std' => __( 'Product categories', 'woocommerce' ),
44 'label' => __( 'Title', 'woocommerce' ),
45 ),
46 'orderby' => array(
47 'type' => 'select',
48 'std' => 'name',
49 'label' => __( 'Order by', 'woocommerce' ),
50 'options' => array(
51 'order' => __( 'Category order', 'woocommerce' ),
52 'name' => __( 'Name', 'woocommerce' ),
53 ),
54 ),
55 'dropdown' => array(
56 'type' => 'checkbox',
57 'std' => 0,
58 'label' => __( 'Show as dropdown', 'woocommerce' ),
59 ),
60 'count' => array(
61 'type' => 'checkbox',
62 'std' => 0,
63 'label' => __( 'Show product counts', 'woocommerce' ),
64 ),
65 'hierarchical' => array(
66 'type' => 'checkbox',
67 'std' => 1,
68 'label' => __( 'Show hierarchy', 'woocommerce' ),
69 ),
70 'show_children_only' => array(
71 'type' => 'checkbox',
72 'std' => 0,
73 'label' => __( 'Only show children of the current category', 'woocommerce' ),
74 ),
75 'hide_empty' => array(
76 'type' => 'checkbox',
77 'std' => 0,
78 'label' => __( 'Hide empty categories', 'woocommerce' ),
79 ),
80 'max_depth' => array(
81 'type' => 'text',
82 'std' => '',
83 'label' => __( 'Maximum depth', 'woocommerce' ),
84 ),
85 );
86
87 parent::__construct();
88 }
89
90 /**
91 * Output widget.
92 *
93 * @see WP_Widget
94 * @param array $args Widget arguments.
95 * @param array $instance Widget instance.
96 */
97 public function widget( $args, $instance ) {
98 global $wp_query, $post;
99
100 $count = isset( $instance['count'] ) ? $instance['count'] : $this->settings['count']['std'];
101 $hierarchical = isset( $instance['hierarchical'] ) ? $instance['hierarchical'] : $this->settings['hierarchical']['std'];
102 $show_children_only = isset( $instance['show_children_only'] ) ? $instance['show_children_only'] : $this->settings['show_children_only']['std'];
103 $dropdown = isset( $instance['dropdown'] ) ? $instance['dropdown'] : $this->settings['dropdown']['std'];
104 $orderby = isset( $instance['orderby'] ) ? $instance['orderby'] : $this->settings['orderby']['std'];
105 $hide_empty = isset( $instance['hide_empty'] ) ? $instance['hide_empty'] : $this->settings['hide_empty']['std'];
106 $dropdown_args = array(
107 'hide_empty' => $hide_empty,
108 );
109 $list_args = array(
110 'show_count' => $count,
111 'hierarchical' => $hierarchical,
112 'taxonomy' => 'product_cat',
113 'hide_empty' => $hide_empty,
114 );
115 $max_depth = absint( isset( $instance['max_depth'] ) ? $instance['max_depth'] : $this->settings['max_depth']['std'] );
116
117 $list_args['menu_order'] = false;
118 $dropdown_args['depth'] = $max_depth;
119 $list_args['depth'] = $max_depth;
120
121 if ( 'order' === $orderby ) {
122 $list_args['orderby'] = 'meta_value_num';
123 $dropdown_args['orderby'] = 'meta_value_num';
124 $list_args['meta_key'] = 'order';
125 $dropdown_args['meta_key'] = 'order';
126 }
127
128 $this->current_cat = false;
129 $this->cat_ancestors = array();
130
131 if ( is_tax( 'product_cat' ) ) {
132 $this->current_cat = $wp_query->queried_object;
133 $this->cat_ancestors = get_ancestors( $this->current_cat->term_id, 'product_cat' );
134
135 } elseif ( is_singular( 'product' ) ) {
136 $terms = wc_get_product_terms(
137 $post->ID,
138 'product_cat',
139 apply_filters(
140 'woocommerce_product_categories_widget_product_terms_args',
141 array(
142 'orderby' => 'parent',
143 'order' => 'DESC',
144 )
145 )
146 );
147
148 if ( $terms ) {
149 $main_term = apply_filters( 'woocommerce_product_categories_widget_main_term', $terms[0], $terms );
150 $this->current_cat = $main_term;
151 $this->cat_ancestors = get_ancestors( $main_term->term_id, 'product_cat' );
152 }
153 }
154
155 // Show Siblings and Children Only.
156 if ( $show_children_only && $this->current_cat ) {
157 if ( $hierarchical ) {
158 $include = array_merge(
159 $this->cat_ancestors,
160 array( $this->current_cat->term_id ),
161 get_terms(
162 'product_cat',
163 array(
164 'fields' => 'ids',
165 'parent' => 0,
166 'hierarchical' => true,
167 'hide_empty' => false,
168 )
169 ),
170 get_terms(
171 'product_cat',
172 array(
173 'fields' => 'ids',
174 'parent' => $this->current_cat->term_id,
175 'hierarchical' => true,
176 'hide_empty' => false,
177 )
178 )
179 );
180 // Gather siblings of ancestors.
181 if ( $this->cat_ancestors ) {
182 foreach ( $this->cat_ancestors as $ancestor ) {
183 $include = array_merge(
184 $include,
185 get_terms(
186 'product_cat',
187 array(
188 'fields' => 'ids',
189 'parent' => $ancestor,
190 'hierarchical' => false,
191 'hide_empty' => false,
192 )
193 )
194 );
195 }
196 }
197 } else {
198 // Direct children.
199 $include = get_terms(
200 'product_cat',
201 array(
202 'fields' => 'ids',
203 'parent' => $this->current_cat->term_id,
204 'hierarchical' => true,
205 'hide_empty' => false,
206 )
207 );
208 }
209
210 $list_args['include'] = implode( ',', $include );
211 $dropdown_args['include'] = $list_args['include'];
212
213 if ( empty( $include ) ) {
214 return;
215 }
216 } elseif ( $show_children_only ) {
217 $dropdown_args['depth'] = 1;
218 $dropdown_args['child_of'] = 0;
219 $dropdown_args['hierarchical'] = 1;
220 $list_args['depth'] = 1;
221 $list_args['child_of'] = 0;
222 $list_args['hierarchical'] = 1;
223 }
224
225 $this->widget_start( $args, $instance );
226
227 if ( $dropdown ) {
228 wc_product_dropdown_categories(
229 apply_filters(
230 'woocommerce_product_categories_widget_dropdown_args',
231 wp_parse_args(
232 $dropdown_args,
233 array(
234 'show_count' => $count,
235 'hierarchical' => $hierarchical,
236 'show_uncategorized' => 0,
237 'selected' => $this->current_cat ? $this->current_cat->slug : '',
238 )
239 )
240 )
241 );
242
243 $handle = 'wc-product-category-dropdown-widget';
244 wp_register_script( $handle, '', array( 'jquery', 'selectWoo' ), WC_VERSION, array( 'in_footer' => true ) );
245 wp_enqueue_style( 'select2' );
246 wp_enqueue_script( $handle );
247 wp_add_inline_script(
248 $handle,
249 "
250 jQuery( '.dropdown_product_cat' ).on( 'change', function() {
251 const categoryValue = jQuery(this).val();
252
253 if ( categoryValue ) {
254 const homeUrl = '" . esc_js( home_url( '/' ) ) . "';
255 const url = new URL( homeUrl, window.location.origin );
256 url.searchParams.set( 'product_cat', categoryValue );
257 location.href = url.toString();
258 } else {
259 location.href = '" . esc_js( wc_get_page_permalink( 'shop' ) ) . "';
260 }
261 });
262
263 if ( jQuery().selectWoo ) {
264 var wc_product_cat_select = function() {
265 jQuery( '.dropdown_product_cat' ).selectWoo( {
266 placeholder: '" . esc_js( __( 'Select a category', 'woocommerce' ) ) . "',
267 minimumResultsForSearch: 5,
268 width: '100%',
269 allowClear: true,
270 language: {
271 noResults: function() {
272 return '" . esc_js( _x( 'No matches found', 'enhanced select', 'woocommerce' ) ) . "';
273 }
274 }
275 } );
276 };
277 wc_product_cat_select();
278 }
279 "
280 );
281 } else {
282 include_once WC()->plugin_path() . '/includes/walkers/class-wc-product-cat-list-walker.php';
283
284 $list_args['walker'] = new WC_Product_Cat_List_Walker();
285 $list_args['title_li'] = '';
286 $list_args['pad_counts'] = 1;
287 $list_args['show_option_none'] = __( 'No product categories exist.', 'woocommerce' );
288 $list_args['current_category'] = ( $this->current_cat ) ? $this->current_cat->term_id : '';
289 $list_args['current_category_ancestors'] = $this->cat_ancestors;
290 $list_args['max_depth'] = $max_depth;
291
292 echo '<ul class="product-categories">';
293
294 wp_list_categories( apply_filters( 'woocommerce_product_categories_widget_args', $list_args ) );
295
296 echo '</ul>';
297 }
298
299 $this->widget_end( $args );
300 }
301 }
302