Skip to content


Related Products ordered by category #428

Valdimarsson opened this Issue · 4 comments

4 participants


How do I get the Related Products to order by category that the current product is located in?
What I want to do is; have the Related Products under product summary to show products from the same category that the current product is at?

I found a function in woocommerce_template_functions.php on line 640 where it calls for function woocommerce_related_products. But I have no clue whatsoever to where I should change the code.

If somebody out there has a tweak for this I would be greatful. Thanks


Isn't it at all possible?

WooThemes member

Related posts already have that:

'tax_query' => array(
'relation' => 'OR',
'taxonomy' => 'product_cat',
'field' => 'id',
'terms' => $cats_array
'taxonomy' => 'product_tag',
'field' => 'id',
'terms' => $tags_array

They find products with the same product category or product tag, and them randomise the result. In the next version the above query will be filterable via a hook ('woocommerce_product_related_posts').

@mikejolley mikejolley closed this

great post, mike, where does this go in the code? sorry, cant seem to get it to work in the template


I also need this information, but I need to figure out how to refine the product category down to it's "smallest" category. Currently I am getting randomized results from my entire shopping cart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.