woocommerce – custom function to override default sort by category

// woo - 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( 'seasonal' ))) {
    return 'title'; // sort by title
    
}else{
return 'date'; // sort by date as the default
    
  } // end if statement
} //end function
add_filter( 'woocommerce_default_catalog_orderby', 'custom_default_catalog_orderby' ); //add the filter