Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 25a32e4

Browse files
authored
Hide categories with 0 products from the Product Categories block (#3765)
1 parent 3b71c89 commit 25a32e4

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/BlockTypes/ProductCategories.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ protected function get_categories( $attributes ) {
133133
return [];
134134
}
135135

136+
// This ensures that no categories with a product count of 0 is rendered.
137+
if ( ! $attributes['hasEmpty'] ) {
138+
$categories = array_filter(
139+
$categories,
140+
function( $category ) {
141+
return 0 !== $category->count;
142+
}
143+
);
144+
}
145+
136146
return $hierarchical ? $this->build_category_tree( $categories ) : $categories;
137147
}
138148

0 commit comments

Comments
 (0)