-1

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.

1 Answers1

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;
}
Omar Faruque
  • 508
  • 5
  • 19