How to Add Magento 2 Sort by Price for Low to High & High to Low Options

How to Add Magento 2 Sort by Price for Low to High & High to Low Options

The store design and its navigation must be in such a way that makes it easier for the shopper to find the exact required product and make the shopping process comfortable and enjoyable.  Navigation can be made easier and hence improve the shopping experience by offering custom sorting options.

The default Magento 2 offers sorting by position, product name, and price, as shown below:

1_default Magento 2 price sorting

However, for a full-fledged Magento 2 store, these options are not enough.

Sometimes, people tend to have some specific budget for product purchase. A price-sensitive customer may save some clicks by starting with the cheapest products. On the other hand, customers who have a high standard for quality may quickly find their most desired products by sampling from high prices to low prices. To provide such feature in Magento 2 and serve both the type of price-sensitive customers, you can add Magento 2 sort by price for low to high & high to low options as shown here:

2_Custom Price Sorting Option

For doing so, follow the method given here.

But if that’s not enough for you, try implementing other custom sorting options with Magento 2 Improved Sorting module.

Method to Add Magento 2 Sort by Price for Low to High & High to Low Options:

  1. Create registration.php file in app\code\[Vendor]\[Namespace]\
  2. Create module.xml file in app\code\[Vendor]\[Namespace]\etc
  3. Create di.xml file in app\code\[Vendor]\[Namespace]\etc
  4. Create Toolbar.php file in app\code\[Vendor]\[Namespace]\Plugin\Catalog\Block
  5. Create Config.php file in app\code\[Vendor]\[Namespace]\Plugin\Catalog\Model

It is safe to say that sorting and navigation are important elements of the Magento 2 store’s design. The above method is just right to improve the sorting and offer options to sort the products by price for low to high & high to low.

Please use the Comments section below if you have any doubts on the topic, Also, do share how this technique was helpful to you in terms of improving the customer experience and store design!

Thank you.


(based on 3 Reviews)

Sanjay is a co-founder at Meetanshi. He is a certified Magento developer who loves creating Magento E-commerce solutions. When he is not engrossed with anything related to Magento, he loves to play cricket.

8 comments On How to Add Magento 2 Sort by Price for Low to High & High to Low Options

  • Hi,
    The sorting is not working with configurable product with different child prices. Which means i have selected size in layered navigation and selected sort by price low to highoption.

  • Uncaught ArgumentCountError: Too few arguments to function

  • Hi, I tried your above code for sorting. “Low to high” sort order not displaying correct results. It’s showing first product with 22.99 price second is 19.99. Incorrect results. “High to low” sort order works fine. Any help?

    • Please debug and check Toolbar.php
      It will return products collection.
      You can use debug log for $subject->getCollection()->getSelect() or $subject->getCollection()->getSelectSql() and check query

  • It says There are no commands defined in the “setup” namespace.

    • It seems that some things are missing while creating the module.
      e.g. You will need to replace [Vendor] with Your Vendor name like Meetanshi and [Namespace] with Your Namespace like CustomSort

Leave a Reply