WooCommerce: How Do I Sort by Product Category?
-
I would really like my shop page to be sorted by product category, rather than alphabetically. It’s fine for alphabet sorting to be an option, but I would prefer the default to be sorting by product category.
Has anyone had any success doing this? I found this little snippet for adding sort options, but I don’t know if there’s a way to tweak this, or if there’s something totally different I should try.
add_filter('woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args'); function custom_woocommerce_get_catalog_ordering_args( $args ) { if (isset($_SESSION['orderby'])) { switch ($_SESSION['orderby']) : case 'date_asc' : $args['orderby'] = 'date'; $args['order'] = 'asc'; $args['meta_key'] = ''; break; case 'price_desc' : $args['orderby'] = 'meta_value_num'; $args['order'] = 'desc'; $args['meta_key'] = '_price'; break; case 'title_desc' : $args['orderby'] = 'title'; $args['order'] = 'desc'; $args['meta_key'] = ''; break; endswitch; } return $args; } add_filter('woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby'); function custom_woocommerce_catalog_orderby( $sortby ) { $sortby['title_desc'] = 'Reverse-Alphabetically'; $sortby['price_desc'] = 'Price (highest to lowest)'; $sortby['date_asc'] = 'Oldest to newest'; return $sortby; }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘WooCommerce: How Do I Sort by Product Category?’ is closed to new replies.