Change Defaut Product Sorting

By default WooCommerce displays products by a custom order and then by a product name. In this tutorial I will show you how to change it in settings and with a code snippet.

As I said, the default WooCommerce sorting is by menu_order, which means manual and if a manual order is not set, the products are going to be displayed alphabetically.

Before we continue, let me show you how to sort WooCommerce products manually, maybe it is just what you need.

One of the way is to click “Sorting” tab and then drag and drop.

Reorder WooCommerce products manually in wp-admin

The second way – to set menu order manually in the product data metabox.

How to change product ordering position in WooCommerce
If you set -1, most likely this product will be displayed first.

Now let me show you how to change this default product sorting “menu_order + title” to something else.

Method 1. Change the Product Sorting in WooCommerce Settings

WooCommerce 3.2.6 and below

This settings screen is deprecated since WooCommerce 3.3.0, so if you are using the latest WooCommerce version, just jump to this part.

Change default product sorting in WooCommerce 3.2.6 and below
The whole Display tab is not available anymore since WooCommerce 3.3.0

Display Options are Missing in WooCommerce 3.3+, where to Find the Default Sorting then?

Well, you can find it in Customizer 😈

I am not sure why the Display tab is completely removed from WooCommerce. Maybe they want us to configure such things with the help of code snippets, or maybe they really have plans for customizer (hopefully no).

So, go to Appearance > Customize > WooCommerce > Product Catalog. And here we are.

Since WooCommerce 3.3 you can find product Display settings and the default sorting option in customizer
Product Display settings are available only in Customizer since WooCommerce 3.3

Method 2. Using Filter Hook to Change the Default Product Ordering in the Code

As simple as to insert the below code into your current theme functions.php file.

add_filter('woocommerce_default_catalog_orderby', 'misha_default_catalog_orderby');
 
function misha_default_catalog_orderby( $sort_by ) {
	return 'date';
}

Possible values are:

It is also possible to create a custom product ordering, for example to display the products in stock first.

Change the Default Ordering only for a Certain Category

Sometimes you may need it too. Actually you can use the same code, but just add a condition like is_product_category( 'category-slug' ). Example:

add_filter('woocommerce_default_catalog_orderby', 'misha_catalog_orderby_for_category');
 
function misha_catalog_orderby_for_category( $sort_by ) {
	if( !is_product_category('uncategorized') ) { 
		return $sort_by; // no changes for any page except Uncategorized
	}
	return 'date';
}

More about Product Sorting

Misha Rudrastyh

Misha Rudrastyh

I love WordPress, WooCommerce and Gutenberg so much. 10 yrs of experience.

Need some custom developer help? Let me know

Follow Misha

Need some help with WooCommerce?

If you need some professional developer help, I will be happy to assist you.

Contact me Who I am?

Leave a comment

php js HTML CSS Code