Hello magento friends todays in this blog post im share with you to How to Remove SORT BY “Price” Option in Magento 2.
In Magento 2, the "SORT BY Price" option is a default feature in the product listing pages. If you want to remove this option, you can do so by creating a custom module or by using an existing module that allows you to modify the sorting options. Here, I'll provide a step-by-step guide to achieve this by creating a custom module:
Please note that this guide assumes you have basic knowledge of Magento 2 and have a development environment set up.
➤ Step 1: Create the module directory structure
In your Magento 2 project, navigate to the app/code directory and create the following folder structure:
MyVendor/
└── MyModule/
├── registration.php
└── etc/
└── di.xml
➤ Step 2: Define the module in registration.php
Create the registration.php file with the following content:
➤ Step 3: Create di.xml file
In the etc folder, create a file named di.xml with the following content:
➤ Step 4: Create the plugin class
Create the plugin class RemovePriceSortOption.php in the following location:
MyVendor/
└── MyModule/
└── Plugin/
└── RemovePriceSortOption.php
The content of the plugin class should be:
➤ Step 5: Enable the module
Run the following commands to enable your custom module:
php bin/magento module:enable MyVendor_MyModule
php bin/magento setup:upgrade
➤ Step 6: Clear cache
Finally, clear the cache for the changes to take effect:
php bin/magento cache:clean
➔ Now, when you visit your Magento store, the "SORT BY Price" option should be removed from the product listing pages.
➔ Remember that modifying the core functionality of Magento is generally not recommended, and it's better to create a custom theme or extension for such modifications to ensure better maintainability and upgrades in the future.