Different sorting per category in WooCommerce

by | 6 April 2019 | WooCommerce, WordPress | 0 comments

By default in WooCommerce you can only set how you want to see the sorting of products in the shop. The sorting then applies to all products regardless of the category.

Now it may happen that you want a different sorting for a certain category. With the code below you can set for which categories you want your own sorting.

//custom function to override default sort by category
function custom_default_catalog_orderby() {

//choose categories where default sorting will be changed
if (is_product_category( array( ‘category1’, ‘category2’, ‘category3’ ))) {
return ‘date’; // sort by latest

}else{

return ‘popularity’; // sort by popularity as the default

} // end if statement
} //end function

add_filter( ‘woocommerce_default_catalog_orderby’, ‘custom_default_catalog_orderby’ ); //add the filter

0 Comments

Submit a Comment

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