5

I have sorted products in categories by:

  • price (default)
  • name
  • position

I need to remove the position from the menu leaving only price and name

I don't want to edit every single category view from the catalog-->manage categories because I have too many categories in the store.

PFA enter image description here

5

quick workaround can be add a condition in theme templates file Magento_Catalog/templates/product/list/toolbar/sorter.phtml like

if $key != 'position' then don't add in drop down options :

<select id="sorter" data-role="sorter" class="sorter-options">
    <?php foreach ($block->getAvailableOrders() as $_key => $_order): ?>

        <?php if ($_key != 'position') : // if key sort by position remove it?>
        <option value="<?= /* @escapeNotVerified */ $_key ?>"
            <?php if ($block->isOrderCurrent($_key)): ?>
                selected="selected"
            <?php endif; ?>
            >
            <?= $block->escapeHtml(__($_order)) ?>
        </option>
       <?php endif; ?>

    <?php endforeach; ?>
</select>
0

Try this:

<?php $availableOrders = $block->getAvailableOrders();
            if(isset($availableOrders['position'])){
                unset($availableOrders['position']);
            }
        ?>
        <?php foreach ($availableOrders as $_key => $_order): ?>
            <?php //if ($_key != 'position') : // if key sort by position remove it?>
                <option value="<?= /* @escapeNotVerified */ $_key ?>"
                    <?php if ($block->isOrderCurrent($_key)): ?>
                        selected="selected"
                    <?php endif; ?>
                    >
                    <?= $block->escapeHtml(__($_order)) ?>
                </option>
            <?php //endif; ?>
        <?php endforeach; ?>

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.