Magento 2: How to Get Count of Active Category Children

categorymagento2

Now I receive children number using this code:

$currentCategory = $this->getCurrentCategory();
$childrenCount = $currentCategory->getChildrenCount();

But it counts both enabled and disabled children.

Do you know method that counts only enabled children, or I have to filter them in block?

Best Answer

You can use like,

$currentCategory = $this->getCurrentCategory();
$childCategory=$currentCategory->getChildrenCategories()->addIsActiveFilter();
echo count($childCategory);