Organizing your products in WooCommerce is simple and easy to do. You can use the default sorting options, or you can create your own custom sorting options to better organize your products. Here’s a look at both methods:
Default Sorting Options
WooCommerce offers several default sorting options for products:
- Price – ascending or descending
- Date – ascending or descending
- Popularity – ascending or descending
- Rating – ascending or descending
To change the default sorting option for your products, go to WooCommerce > Settings > Products > Display. From here, you can select the default sorting option for your products. Keep in mind that these options can be overridden by users, so if you want more control over how your products are sorted, you may want to consider creating custom sorting options.
Custom Sorting Options
Creating custom sorting options requires a bit more work, but it gives you much more control over how your products are sorted. To create a custom sorting option, you’ll need to add a new function to your theme’s functions.php file.
function my_custom_sort($a, $b) {
// If product A is cheaper than product B
if ($a->get_price() < $b->get_price())
return -1;
// If product A is more expensive than product B
if ($a->get_price() > $b->get_price())
return 1;
You can change the sort order of your products by going to the WooCommerce->Settings->Products tab and selecting the desired sort order from the ‘Default product sorting’ drop-down menu.
// If products A and B have the same price
return 0;
add_filter(‘woocommerce_get_catalog_orderby’, ‘my_custom_sort’);
The above code will sort products by price, with the cheapest products being listed first. You can modify this code to sort by any product property that you want. For example, if you wanted to sort by product rating, you could use the following code:
function my_custom_sort($a, $b) {
// If product A has a higher rating than product B
if ($a->get_average_rating() > $b->get_average_rating())
return -1;
// If product A has a lower rating than product B
if ($a->get_average_rating() < $b->get_average_rating())
return 1;
// If products A and B have the same rating
return 0; }
add_filter(‘woocommerce_get_catalog_orderby’, ‘my_custom_sort’);
Once you’ve added the code to your theme’s functions.php file, you need to go to WooCommerce > Settings > Products > Display. From here, select ” Custom Product Sorting” from the Default Product Sorting dropdown menu.
And that’s it! Your products will now be sorted using your custom sorting option.