oh, wait… that snippet up there only orders by date – if you actually want to order products by category (or any other taxonomy, for that matter) you need to do a little sql like so:
function order_by_multiple() {
if(function_exists('is_woocommerce')){
if(is_woocommerce()||is_search()||is_product_category()) return ' tm.meta_value, post_title';
}
}
function product_order_join($join){
global $wpdb;
if(function_exists('is_woocommerce')){
if(is_woocommerce()||is_search()||is_product_category()){
$join.= " JOIN " . $wpdb->term_relationships ." tr ON " . $wpdb->posts . ".id = tr.object_id JOIN " . $wpdb->term_taxonomy ." tt ON tt.term_taxonomy_id = tr.term_taxonomy_id AND tt.taxonomy = 'product_cat' JOIN " . $wpdb->terms ." t ON tt.term_id = t.term_id
join " . $wpdb->woocommerce_termmeta ." tm on tm.woocommerce_term_id = t.term_id and tm.meta_key = 'order' ";}
}
return $join;
}
add_filter("posts_join","product_order_join");
IF(!is_admin())add_filter("posts_orderby", "order_by_multiple");
Replace ‘product_cat’ with whatever the taxonomy/attribute is.
For attributes, woocommerce ads a ‘pa_’ in front for the taxonomy name.
So, for if the name of your attribut was genre, then you would replace product_cat with pa_genre.
also, you can probably replace
add_filter(“posts_orderby”, “order_by_multiple”);`
with
add_filter(‘woocommerce_get_catalog_ordering_args’,”order_by_multiple”);`
I just haven’t had the chance to test it yet.
Is that what you’re looking for Marce? or are you want to override the order that attributes are displayed on the single product page?