I need order the results of “$product->get_categories()” with the slug.
The template use this code:
$cat_count = sizeof( get_the_terms( $post->ID, 'product_cat' ) );
//And after...
<?php echo $product->get_categories( ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', $cat_count, 'woocommerce' ) . ' ', '</span>' ); ?>
I’ve seen in a tutorial, that I can use this code,but doesn’t work (in functions.php):
function wptt_cat_order( $args ){
$args['orderby'] = 'slug';
$args['order'] = 'ASC';
return $args;
} // wptt_cat_order
add_filter( 'woocommerce_product_subcategories_args', 'wptt_cat_order' );
Other question I have is(but not is so important than the other question), why he uses the $cat_count in “_n()” function and not “get_the_terms( $post->ID, ‘product_cat’ )”? first is only a number O_O.
Simple answer: you can’t use that method to order the categories.
You’re going to need to write your own loop using
wp_get_post_terms()
, which allows you to pass arguments (such asorderby
). Something like the following should work (but I haven’t tested it):