How to set up the output and sorting of categories by hierarchy in wordpress
Good evening, I use a website on WordPress. The site uses WooCommerce and All in one SEO plugins. The site works as an online store with a catalog of products. There are categories and subcategories of products on the site.
In title and in description (file meta.php in single-product, in the templates of the WooCommerce plugin), a list of categories of a specific product is displayed.
Unfortunately, the list of categories is displayed in alphabetical order. Please tell me what to prescribe in functions.php, to sort by slug or by category Id.
*P. S In the source code meta.php the output of the categories looks like this:
$cat_count = sizeof( get_the_terms( $post->ID, 'product_cat' ) );
<?php echo $product->get_categories( ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', $cat_count, 'woocommerce' ) . ' ', '</span>' ); ?>
1 answers
Here it is rather necessary to change not functions.php, and output a list of categories in the template.
For example,
wp_list_categories ('orderby=slug')
Read more about all the parameters here - https://wp-kama.ru/function/wp_list_categories
Or take the plugin https://wordpress.org/plugins/taxonomy-terms-order/