An Easy Guide On How To Remove Default Sort Option in WooCommerce
WooCommerce stores with a few products do not often need the sort dropdown menu on the shop and product pages. In fact, the sort option is considered an unwanted part of the UI. A related element is the standard notice of the number of items/results.
Fortunately, removing these elements are easy to remove. In this tutorial, I will show the simple process of removing these two UI elements. Here is how the store looks before the changes are applied:
To start, confirm that default sorting is enabled. if not, enable it from the backend. Go to Settings > Products > Display and then to Default product sorting. Select any option from the menu.
To make the changes, open up the functions.php file and add the following code snippets:
1 2 3 4 |
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 ); //This snippet will remove the notice that shows the number of results. remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering',30 ); |
This snippet will remove the default sorting dropdown from all pages
1 2 3 4 5 6 |
add_action('init','delay_remove'); function delay_remove() { remove_action( 'woocommerce_after_shop_loop', 'woocommerce_catalog_ordering', 10 ); remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 10 ); } //This snippet removes the default sorting dropdown in StoreFront Theme |
Here is how the shop page would look like after the addition of the snippets:
Create Faster WordPress Websites!
Free eBook on WordPress Performance right in your inbox.