You need to override magento2\vendor\magento\module-catalog\Model\Layer\Filter\Category.php
and update _getItemsData()
function with below code:
protected function _getItemsData()
{
/** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */
$productCollection = $this->getLayer()->getProductCollection();
$optionsFacetedData = $productCollection->getFacetedData('category');
$category = $this->dataProvider->getCategory();
$categories = $category->getChildrenCategories();
$collectionSize = $productCollection->getSize();
if ($category->getIsActive()) {
foreach ($categories as $category) {
$categoryManager = $this->categorys->load($category->getId())
->getProductCollection()->addAttributeToSelect('entity_id')
->addAttributeToFilter('status', 1)->addAttributeToFilter('visibility', 4);
if ($category->getIsActive() && $categoryManager->count()>0)
{
$this->itemDataBuilder->addItemData(
$this->escaper->escapeHtml($category->getName()),
$category->getId(),
$categoryManager->count()
);
}
}
}
return $this->itemDataBuilder->build();
}
I Hope this will help you.