I am trying to change the name of the default order by, add a new order by for name, and remove several of the default options that are not relevant:
// Remove the other sort order options and add and rename 1
add_filter('woocommerce_catalog_orderby', 'change_default_sorting_options');
function change_default_sorting_options($options)
{
unset($options['popularity']);
unset($options['rating']);
unset($options['date']);
unset($options['price']);
unset($options['price-desc']);
$options['name'] = 'Sort by Name';
$options['menu_order'] = 'Catalog Sort Order';
return $options;
}
this works fine. The default is the menu_order option.
Then I want to have the catalog sort by "name" when the category is "20 Gauge". Adding this code results does sort by name for the "20 Gauge" category but it removes the default option (menu_order) from the sort order dropdown:
add_filter('woocommerce_default_catalog_orderby', 'custom_default_catalog_orderby');
function custom_default_catalog_orderby()
{
if (is_product_category(array('20-gauge'))) {
return 'name'; // sort by latest
} else {
return 'menu_order';
}
}