I want to display related products based on Custom taxonomy. Does someone knows is there a way to force related products to be displayed based on Custom taxonomy.
Asked
Active
Viewed 18 times
1 Answers
0
add_filter( 'woocommerce_output_related_products_args', 'prfx_change_related_products_count' );
function prfx_change_related_products_count( $args ) {
// Current post as global
global $post;
$term_obj_list = get_the_terms( $post->ID, 'your_custom_taxonomy' );
// Empty array
$ids = array();
foreach ( $terms as $term ) {
array_push($ids, $term->term_id);
}
$args['tax_query'] = array(
array(
'taxonomy' => 'your_custom_taxonomy',
'terms' => $ids,
'field' => 'term_id',
'include_children' => true,
'operator' => 'IN'
)
)
return $args;
}
![](../../users/profiles/3374352.webp)
Omar Faruque
- 508
- 5
- 19
-
Hi Brother, after adding this code to function.php it's getting " There has been a critical error on this website. " error. – Ijaz Ahamed May 09 '21 at 11:13
-
Please show us some logs. – Mr. Jo May 09 '21 at 15:28
-
@liaz Ahmed can you share a screenshot or error code for understand ? – Omar Faruque May 10 '21 at 05:46