I want to show the product count on layer navigation for text swatches.

By default Magento providing this feature for normal attributes(Text, Dropdown, and multi-select) in layer navigation but is not available for swatches.

Please see the below-attached screenshot for more clarity.

I Want like below

enter image description here

Magento by default providing for another attribute like text, dropdown

enter image description here

Please help on above issue.Any references or suggestions highly appreciated



Look at \Magento\Swatches\Block\LayeredNavigation\RenderLayered::getOptionViewData

You can modify option returning option data to

return [
    'label' => $swatchOption->getLabel(),
    'link' => $linkToOption,
    'custom_style' => $customStyle,
    'count' => $filterItem->getCount()

and render product count in Magento/Swatches/view/frontend/templates/product/layered/renderer.phtml

<?php foreach ($swatchData['options'] as $option => $label): ?>
    <?= $label['count']; ?>

Note, that you must not modify core module code. Instead that, you can use base ways to customizing module behavior (plugins, layouts, etc)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.