We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

    Step 1) Override the Magento_LayeredNavigation/templates/layer/filter.phtml to your theme design directory

    Step 2) Add and Change in filter.phtml

    <?php 
        $offsets = array();
        $offsets1 = array();
        $offsets2 = array();
        $offsets3 = array();
        foreach ($filterItems as $filters) {
            $checklable = $filters->getLabel();
            if(preg_match("/[a-z]/i", $checklable)){
                array_push($offsets1, $filters);
            }
            elseif(preg_match("/,/i", $checklable)){
                array_push($offsets2, $filters);
            }
            elseif(preg_match("/-/i", $checklable)){
                array_push($offsets2, $filters);
            }
            elseif(strstr($checklable, '/')){
                array_push($offsets2, $filters);
            }
            else{
                array_push($offsets3, $filters);
            }
        }
        asort($offsets1);
        asort($offsets2);
        sort($offsets3);
    
        $offsets = array_merge($offsets3,$offsets2,$offsets1);
    ?>
    <ol class="items">
        <?php foreach ($offsets as $filterItem): ?>
            <li class="item">
                <?php //echo '===>'; ?>
                <?php if ($filterItem->getCount() > 0): ?>
                    <a href="<?= $block->escapeUrl($filterItem->getUrl()) ?>">
                        <?= /* @escapeNotVerified */ $filterItem->getLabel() ?>
                        <?php if ($this->helper('MagentoCatalogHelperData')->shouldDisplayProductCountOnLayer()): ?>
                            <span class="count"><?= /* @escapeNotVerified */ $filterItem->getCount() ?><span class="filter-count-label">
                                <?php if ($filterItem->getCount() == 1):?> <?= /* @escapeNotVerified */ __('item') ?><?php else:?> <?= /* @escapeNotVerified */ __('items') ?><?php endif;?></span></span>
                        <?php endif; ?>
                    </a>
                <?php else:?>
                    <?= /* @escapeNotVerified */ $filterItem->getLabel() ?>
                    <?php if ($this->helper('MagentoCatalogHelperData')->shouldDisplayProductCountOnLayer()): ?>
                        <span class="count"><?= /* @escapeNotVerified */ $filterItem->getCount() ?><span class="filter-count-label">
                            <?php if ($filterItem->getCount() == 1):?><?= /* @escapeNotVerified */ __('item') ?><?php else:?><?= /* @escapeNotVerified */ __('items') ?><?php endif;?></span></span>
                    <?php endif; ?>
                <?php endif; ?>
            </li>
        <?php endforeach ?>
    </ol>
    

     

    field_5bfb909c5ccae

      Get a Free Quote