How to Remove Sort by “Price” Option in Magento 2
Every Magento 2 stores have a variety of products under different categories. Sometimes, it becomes tedious for customers to choose the product they exactly want. To boost sales and help the customer to find out specific items, one can sort category products in Magento 2.
Easy sorting allows visitors to check the products quickly with less scrolling. It enhances the onsite user experience.
Position, product name, and price are the default sorting options available in Magento 2.
Contradictory to adding sort by options, you may want to remove them. For example, you may want to remove sort by price option in Magento 2 for the below reasons:
- When quality matters the most, comparing to the price.
- When the store owner wants to highlight other unique factors than price.
- When you sell premium products like gold jewelry, diamonds, etc.
- When your sell service and allow users to call for price in Magento 2
- When you want to extend the price sorting by adding Magento 2 sort by price for low to high and high to low options to save some clicks for budget friendly buyers.
Here, I’m explaining the steps to remove sort by price option in Magento 2, follow it to remove price sorting option and target non-budget focused buyers.
Steps to Remove Sort by “Price” Option in Magento 2
1 2 3 4 5 6 7 |
<?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="Magento\Catalog\Model\Config"> <plugin name="Vendor_ModuleName::addCustomOptions" type="Vendor\Module\Plugin\Model\Config"/> </type> </config> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?php use Magento\Store\Model\StoreManagerInterface; class Config { protected $_storeManager; public function __construct( StoreManagerInterface $storeManager ) { $this->_storeManager = $storeManager; } public function afterGetAttributeUsedForSortByArray(\Magento\Catalog\Model\Config $catalogConfig, $options) { unset($options['price']); return $options; } } |
As easy as ABC, right?!
Feel free to ask your queries in the Comment section below and I would be happy to help.
Do consider sharing the post with Magento Community via social media.
Thank you.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
Prev
How to Filter Order Grid by Multiple Order IDs in Magento 2
How to Update Product Price Programmatically in Magento 2
Next