---
title: "How to Add Magento 2 Sort by Price for Low to High & High to Low Options?"
url: "https://magecomp.com/blog/add-magento-2-sort-by-price-for-low-to-high-high-to-low-options/"
date: "2020-11-20T10:00:04+00:00"
modified: "2025-01-30T10:12:26+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "Magento Tutorials"
word_count: 563
reading_time: "3 min read"
summary: "Hello Magento Folks,"
description: "Sorting options helps the customers to search for products easily. Learn more How to Add Magento 2 Sort by Price for Low to High & High to Low Options"
keywords: "Magento Tutorials"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How can I Uninstall and Remove a Magento 2 Extension?"
    url: "https://magecomp.com/blog/uninstall-and-remove-magento-2-extension/"
  - title: "How to Install Magento 2.4 via Command Line"
    url: "https://magecomp.com/blog/install-magento-2-4-via-command-line/"
  - title: "Adding custom code in Magento 2 <head> HTML tag"
    url: "https://magecomp.com/blog/add-custom-code-in-magento-2-head-html-tag/"
---

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

_Published: November 20, 2020_  
_Author: Dhiren Vasoya_  

![How to Add Magento 2 Sort By Price- Low to High and High to Low](https://magecomp.com/blog/wp-content/uploads/2020/11/How-to-Add-Magento-2-Sort-By-Price-Low-to-High-and-High-to-Low-1024x512.webp)

Hello Magento Folks,
How are you all? Have you all took the advantage of the MageComp Diwali offers? It’s the last day for [**MageComp Big Diwali Sale 2020**](https://magecomp.com/blog/magecomp-big-diwali-sale-2020/). Shop now and get huge discounts on Magento Extensions and Services. In this article, I will guide you How to Add Magento 2 Sort by Price for Low to High & High to Low Options. Let’s get started.
[![](https://magecomp.com/blog/wp-content/uploads/2022/05/Mobile-App.png)](https://magecomp.com/magento-2-mobile-app-builder)

## Quick Intro:
Ecommerce stores must have precise and user-friendly navigation that makes the customers way easy to shop from your store. Sorting is a major component to provide for user’s ease and effortless searching for the product they are finding. By default, Magento 2 is capable of providing the below-given options such as by position, product name, and price.
![Config_2](https://magecomp.com/blog/wp-content/uploads/2020/11/Config_2-2.png)

Many times the customers are looking for the cheapest products and some of the customers need the high-priced products then for them the above sorting options are not efficient. For offering the options of sort by price for low to high & high to low in Magento 2 follow the below-given steps.
## Steps to Add Magento 2 Sort by Price for Low to High & High to Low Options:
**Step 1:** create registration.php file in app\code\Vendor\Extension
```
<?php
MagentoFrameworkComponentComponentRegistrar::register(MagentoFrameworkComponentComponentRegistrar::MODULE,
'Vendor_Extension',
_DIR_
);
```

**Step 2:** Create module.xml file in app\code\Vendor\Extension\etc
```
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Extension" setup_version="1.0.0"/>
</config>
```

**Step 3:** Create di.xml file in app\code\Vendor\Extension\etc
```
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCatalogBlockProductProductListToolbar">
<plugin name="custom_custom_block_toolbar" type="VendorExtensionPluginCatalogBlockToolbar"/>
</type>
<type name="MagentoCatalogModelConfig">
<plugin name="custom_catalog_model_config" type="VendorExtensionPluginCatalogModelConfig"/>
</type>
</config>
```

**Step 4:** Create Toolbar.php file in app\code\Vendor\Extension\\Plugin\Catalog\Block
```
<?php
namespace VendorExtensionPluginCatalogBlock;
class Toolbar
{
public function aroundSetCollection(MagentoCatalogBlockProductProductListToolbar $subject,
Closure $proceed, $collection)
{
$currentOrder = $subject->getCurrentOrder();
$result = $proceed($collection);
if($currentOrder)
{
if($currentOrder == 'high_to_low')
{
$subject->getCollection()->setOrder('price', 'desc');
}
elseif ($currentOrder == 'low_to_high')
{
$subject->getCollection()->setOrder('price', 'asc');
}
}
else
{
$subject->getCollection()->getSelect()->reset('order');
$subject->getCollection()->setOrder('price', 'asc');
}
return $result;
}
}
```

**Step 5:** Create Config.php file in app\code\Vendor\Extension\Plugin\Catalog\Model
```
<?php
namespace VendorExtensionPluginCatalogModel;
class Config
{
public function afterGetAttributeUsedForSortByArray(MagentoCatalogModelConfig $catalogConfig,
$results)
{
$results['low_to_high'] = __('Price - Low To High');
$results['high_to_low'] = __('Price - High To Low');
return $results;
}
}
```

That’s it.
**After implementing the above solution:**

![Config_1](https://magecomp.com/blog/wp-content/uploads/2020/11/Config_1-2.png)

## Conclusion:
Most probably all are successfully able to provide sort options of Low to High & High to Low with the help of the above code. In case of any troubles write it down in the comments I will help you.
Also, share the illustration with your E-commerce friends and help them to provide sorting options in their Magento 2 store.
**Happy Reading!**

[![Magento-development-services](https://magecomp.com/blog/wp-content/uploads/2020/06/Hire-Magento-4.png)](https://magecomp.com/magento-development-services?utm_source=magecomp&utm_medium=blog&utm_campaign=cta)


---

_View the original post at: [https://magecomp.com/blog/add-magento-2-sort-by-price-for-low-to-high-high-to-low-options/](https://magecomp.com/blog/add-magento-2-sort-by-price-for-low-to-high-high-to-low-options/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-09-16 06:39:37 UTC_  
