WooCommerce: Remove, Rename, Add “Sorting” Options @ Shop

We’ve seen in the past how to completely remove the “Default Sorting” dropdown that shows in the WooCommerce Shop, Category and Product Archive pages.

Sometimes, however, you might just need to remove one of the default options, rename a sorting option accordingly to your needs or even add a brand new sorting method. As usual, a few lines of PHP are sufficient to achieve anything, thanks to WooCommerce hooks and filters.

Remove, Rename or Add Options to the WooCommerce “Default Sorting” Dropdown

PHP Snippet #1: Remove a Sorting Option @ WooCommerce Shop

/**
* @snippet       Remove Sorting Option @ WooCommerce Shop
* @how-to        Get CustomizeWoo.com FREE
* @author        Rodolfo Melogli
* @testedwith    WooCommerce 3.8
* @donate $9     https://businessbloomer.com/bloomer-armada/
*/
 
add_filter( 'woocommerce_catalog_orderby', 'bbloomer_remove_sorting_option_woocommerce_shop' );
 
function bbloomer_remove_sorting_option_woocommerce_shop( $options ) {
   unset( $options['rating'] );   
   return $options;
}
 
// Note: you can unset other sorting options by adding more "unset" calls... here's the list: 'menu_order', 'popularity', 'rating', 'date', 'price', 'price-desc'

PHP Snippet #2: Rename a Sorting Option @ WooCommerce Shop

/**
* @snippet       Rename a Sorting Option @ WooCommerce Shop
* @how-to        Get CustomizeWoo.com FREE
* @author        Rodolfo Melogli
* @testedwith    WooCommerce 3.8
* @donate $9     https://businessbloomer.com/bloomer-armada/
*/
 
add_filter( 'woocommerce_catalog_orderby', 'bbloomer_rename_sorting_option_woocommerce_shop' );
 
function bbloomer_rename_sorting_option_woocommerce_shop( $options ) {
   $options['price'] = 'Sort by price (asc)';   
   return $options;
}

PHP Snippet #3: Add a Custom Sorting Option @ WooCommerce Shop

In this example, we will create a new sorting option called “Sort by name (desc)” that will indeed sort products by title (descending order).

/**
* @snippet       Add a Custom Sorting Option @ WooCommerce Shop
* @how-to        Get CustomizeWoo.com FREE
* @author        Rodolfo Melogli
* @testedwith    WooCommerce 4.0
* @donate $9     https://businessbloomer.com/bloomer-armada/
*/
 
// 1. Create new product sorting rule
 
add_filter( 'woocommerce_get_catalog_ordering_args', 'bbloomer_sort_by_name_woocommerce_shop' );
 
function bbloomer_sort_by_name_woocommerce_shop( $args ) { 
   $orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
   if ( 'name' == $orderby_value ) {
      $args['orderby'] = 'title';
      $args['order'] = 'DESC';
   } 
   return $args;
}
 
// 2. Add new product sorting option to Sorting dropdown
 
add_filter( 'woocommerce_catalog_orderby', 'bbloomer_load_custom_woocommerce_catalog_sorting' );
 
function bbloomer_load_custom_woocommerce_catalog_sorting( $options ) {
   $options['name'] = 'Sort by name (desc)';
   return $options;
}

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.3.

If you think this code saved you time & money, feel free to join 14,000+ WooCommerce Weekly subscribers for blog post updates or 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

52 thoughts on “WooCommerce: Remove, Rename, Add “Sorting” Options @ Shop

  1. Question. I have followed the guide, and it works for the default wordpress shop page, but I used woocommcerce’s all products block and made a new store page. It was necessary to use a custom page as my client wanted to change the slug for the page… The function does not change the drop down list for the new page. Do you know of a fix for this?

    1. Hi Ryan, have you tried with the WooCommerce products shortcode instead?

  2. This is great! I’d like to combine two of your tutorials but I can’t figure out how.

    I want to sort by default sorting order, but also move all out of stock items to the end of the list. Is this possible?

    1. Hi Tom thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  3. Simple and useful, thank you.

  4. Hello! I have Rife Free theme. Product sorting options do not show on the shop page. How can I fix this?

    1. Hey Adrian, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  5. Hi and thanks for your code!
    But it doesn’t work for me.
    Any idea of how to hide some “sort by” entries on the drop down menu?

    1. Hi Aline, please share your code

  6. Hi thank you for this. but can you tell me how to add categories in this? thank

      1. Thanks for reply. I think i am mistaken. I like to include categories in the default sorting in shop page. Can i do this?

        1. Ah ok, yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  7. Dear,
    is it possible to insert image, icon etc… instead Default Sorting .woocommerce .woocommerce-ordering .ordering-selector-wrapper
    Idea is to have image to represent this wrapper and on click to open drop down .

    Best regards

    1. Anything is possible πŸ™‚

  8. For the third snippet you didn’t actually set $orderby_value and that value isn’t passed into the function so it doesn’t ever fire.

    You can set it like this though:

    $orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
    1. Thank you!

  9. Hi Rodolfo,
    I used the 3rd snippet to order products by random and works fine, but also this list need to be with available products in the beggining. Is it possible to do this?

    1. Hello there, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  10. How can I remove, not hide, but actually remove the Default Sorting drop down box. It leaves too much white space at the top of the page above the product listings. I found some CSS to hide it but the white space remains. Im looking for CSS to actually remove it to adjust the padding and not leave so much whitespace.

    (Would also like to remove the empty space at the top above my logo too, it’s about a half inch to an inch of whitespace at the top when scrolling)

    Thanks in advance and have a good one!

  11. Can I sort by an equation? price*total_sales desc for best selling by total $ sold?

    1. Hi Aaron, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  12. works great!

    But…. i got an sorting option called “biggest saving” which i want to remove, what’s the unset option for that one? Can’t find it anywhere.

    Thanks in advance

    1. Not sure, that’s not default WooCommerce

  13. Hi, I used one of the custom sorting methods where menu order value is set to negative starting from -1. When I tried this code , It did not took into consideration the Custom sorting while using ‘Sort by Name’. Please help me find a fix to it. Thanks you so much blogs like this help us new developers & designers to learn and grow and also get our work done. Hoping for a quick reply.

    1. Hi there, not sure about negative values, sorry

  14. Hi how to sort by recent comment in woocommerce?

    1. Hi Drew, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  15. This article helped me a lot.
    Rodolfo, when it comes to web development, your blog/website is the most efficient blog/website I ever come across.
    THANK YOU for this amazing piece of work!

    1. Thank you!

  16. Rodolfo, another great tutorial that saved my life! Thank you very much for sharing your knowledge. I’m a new developer and your tutorials have provided great help to me!

    1. Fantastic!

  17. Nice tutorial! I just need to fix the ordering. Thanks.

    1. Cool!

  18. Hello!!
    Is it possible to add a sort by “_featured” products? I couldn’t do achieve it with your code.
    Thanks!

    1. Hello Walter, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  19. Hi,
    I wanted to replace the default sorting option by the category shop list.
    Like with a portfolio listing.
    Do you have an idea of how I can do it ?
    Regards

    1. Hello Cine, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  20. legend just what I neeed

    1. Cool!

  21. Looking at this allows for the removal of items within the sort function…. is the a way to remove the entire thing?

    The sorting div, row, container … whatever?

  22. Hello Rodolfo.

    I need to set my woocommerce default product sorting by Product Tittle.

    I will remove the filter sorting, caus will not used in my project.

    But it still in sort default by another order, and not for Product Name.

    how can i do this?

    tks!

    1. Hello Carlos, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  23. Is there a way to change the order of the sorting options?
    That would be awesome!

    1. Hello Miriam – thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  24. The same that lottie but for my bookmarks. Thanks!! πŸ™‚

    1. Ahah πŸ™‚

  25. just what I was looking for

    your website is now my home page!!!

    1. Nice πŸ™‚

Questions? Feedback? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)

Your email address will not be published. Required fields are marked *