0

I want to remove the default sort option from the category page.

I have tried the below code but is not working.

unset($options['position']);
unset($options['name']);
unset($options['price']);

Position sort option is removed but name and price is not removing.

3 Answers 3

4

You can set Used for Sorting in Product Listing to No for the attributes which you want to remove from sorting options on PLP.

Magento Admin -> stores -> Attributes -> Products -> select Attribute -> Storefront Properties -> Used for Sorting in Product Listing -> set No -> Save Attribute

enter image description here

1
  • it's working. thanks! Mar 2, 2020 at 10:10
1

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

<select id="sorter" data-role="sorter" class="sorter-options">
    <?php foreach ($block->getAvailableOrders() as $_key => $_order) :?>
      <?php if ($_key != 'price' && $_key != 'name') : // remove "price" and "name"?>
        <option value="<?= $block->escapeHtmlAttr($_key) ?>"
            <?php if ($block->isOrderCurrent($_key)) :?>
                selected="selected"
            <?php endif; ?>
            >
            <?= $block->escapeHtml(__($_order)) ?>
        </option>
        <?php endif; ?>
    <?php endforeach; ?>
</select>
0

May be also good idea to use Plugin on catalog Config and unset Position with

public function afterGetAttributeUsedForSortByArray(Config $config, $result)
{
    if (is_array($result) && isset($result[Category::KEY_POSITION])) {
        unset($result[Category::KEY_POSITION]);
    }
    
    return $result;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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