Corrected the "Show Siblings and Children Only" queries Closes #5028
This commit is contained in:
parent
48ebfae145
commit
e0b11c8c2e
|
@ -123,20 +123,30 @@ class WC_Widget_Product_Categories extends WC_Widget {
|
|||
// Show Siblings and Children Only
|
||||
if ( $s && $this->current_cat ) {
|
||||
|
||||
if ( $this->current_cat->parent == 0 ) {
|
||||
$category_children = $this->current_cat->term_id;
|
||||
} else {
|
||||
$category_children = $this->current_cat->parent;
|
||||
// Top level is needed
|
||||
$top_level = get_terms( 'product_cat', array( 'fields' => 'ids', 'parent' => 0, 'hierarchical' => false, 'hide_empty' => false ) );
|
||||
|
||||
// Direct children are wanted
|
||||
$direct_children = get_terms( 'product_cat', array( 'fields' => 'ids', 'parent' => $this->current_cat->term_id, 'hierarchical' => true, 'hide_empty' => false ) );
|
||||
|
||||
// Gather siblings of ancestors
|
||||
$siblings = array();
|
||||
if ( $this->cat_ancestors ) {
|
||||
foreach ( $this->cat_ancestors as $ancestor ) {
|
||||
$siblings = array_merge( $siblings, get_terms( 'product_cat', array( 'fields' => 'ids', 'parent' => $ancestor, 'hierarchical' => false, 'hide_empty' => false ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
$current_category_children = get_term_children( $category_children, 'product_cat' );
|
||||
$include = array_merge( $top_level, $this->cat_ancestors, $siblings, $direct_children, array( $this->current_cat->term_id ) );
|
||||
|
||||
if ( $current_category_children ) {
|
||||
$current_category_children = implode ( ", ", $current_category_children );
|
||||
$dropdown_args['include'] = $current_category_children;
|
||||
$cat_args['include'] = $current_category_children;
|
||||
}
|
||||
$dropdown_args['include'] = implode( ',', $include );
|
||||
$cat_args['include'] = implode( ',', $include );
|
||||
|
||||
} elseif ( $s ) {
|
||||
$dropdown_args['depth'] = 1;
|
||||
$dropdown_args['child_of'] = 0;
|
||||
$cat_args['depth'] = 1;
|
||||
$cat_args['child_of'] = 0;
|
||||
}
|
||||
|
||||
// Dropdown
|
||||
|
@ -146,7 +156,8 @@ class WC_Widget_Product_Categories extends WC_Widget {
|
|||
'show_counts' => $c,
|
||||
'hierarchical' => $h,
|
||||
'show_uncategorized' => 0,
|
||||
'orderby' => $o
|
||||
'orderby' => $o,
|
||||
'selected' => $this->current_cat ? $this->current_cat->slug : ''
|
||||
);
|
||||
$dropdown_args = wp_parse_args( $dropdown_args, $dropdown_defaults );
|
||||
|
||||
|
|
Loading…
Reference in New Issue