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;
}
Share:

Leave a Reply