Patrick's Programming Blog

How to Customize the WooCommerce Sorting Dropdown

Being able to organize your store however you want is one of the best parts about using WooCommerce. You could stick with the default ordering functionality or you may want to customize it a bit for your store. Maybe you want to remove the option to sort by price, or you want to remove the sorting all together (because you only have 5 products), or you want to add a whole new way to sort. That's all possible with WooCommerce.

Removing Sorting Options

WooCommerce Default Sorting

The default sorting in WooCommerce

Maybe you want to remove the sort by price or maybe you want to remove the sort by newness option. All you have to do is add this snippet to your theme's functions.php file and choose which options you want removed.

Done! It should look something like this:

WooCommerce sorting after having some options removed

Changing the Text in the Sort

Maybe you just want to change the text of the sort by box so that it matches your brand. For example the “sort by newness” sounds a bit awkward to me. I'd like to change that to “sort by date: newest first”. You can do that with the same filter.

Adding Items to the Sort

Is it possible to add items to the sort? For example sort by oldest products.

Absolutely.

It's a bit more complex because we have to not only add an item to the menu. But we also need to add the functionality that actually does the sorting. The first part about filtering the menu items is the same we just need to add one function to sort everything.

Removing the Sort

Some store owners may want to remove the sort feature entirely. If you have very few products or the sorting just doesn't make sense for your store (ex. 20 products that are all the same price and are just different colors). In this case you may want to remove the sort feature and clear up the visual clutter.

Removing functionality is usually pretty easy. It's usually just one line:

The one thing that's hard about the above is many themes move the location of the sort. And if they move it the above code won't work because the priority (that's the parameter that the 30 is representing) is wrong. If the above code doesn't happen one thing you can try is to remove the priority entirely. Remove the number and the comma before it.

If that still doesn't remove it there's something else going on.

Putting it all Together

Now if you want to do ALL of this (well all of it but removing the sort) you can do that in one go rather than three little snippets.

Happy sorting! 🙂

 

Exit mobile version