вопрос решен - всё дело в массиве $related в файле related.php
global $product, $woocommerce_loop;
if ( empty( $product ) || ! $product->exists() ) {
return;
}
$related = $product->get_related( $posts_per_page );
if ( sizeof( $related ) == 0 ) return;
foreach (get_the_terms( $product->id, 'product_cat' ) as $cat){
if($cat->parent == 0){
$mama = $cat->term_id;
foreach (get_the_terms( $product->id, 'product_cat' ) as $cat2){
if($cat2->parent == $cat->term_id){
$child = $cat2->term_id;
break;
}
}
break;
}
}
$args = array(
'orderby'=>'rand',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'terms' => $child,
include_children => false
)
)
);
$childprod = new WP_Query( $args );
$arr = array();
foreach ($childprod->posts as $pid){
array_push($arr, $pid->ID);
}
wp_reset_postdata();
unset($arr[array_search($product->id,$arr)]);
shuffle($arr);
array_splice($arr, 3);
if(count($arr) < 3){
$arr = $related;
}
$args = apply_filters( 'woocommerce_related_products_args', array(
'post_type' => 'product',
'ignore_sticky_posts' => 1,
'no_found_rows' => 1,
'posts_per_page' => $posts_per_page,
'orderby' => $orderby,
'post__in' => $arr,
'post__not_in' => array( $product->id )
) );
$products = new WP_Query( $args );
$woocommerce_loop['columns'] = $columns;
if ( $products->have_posts() ) : ?>
</div>
</div>
<div style="clear: both;"></div>
</div>
<div class="related products">
<h2 style="display: inline; text-transform: uppercase;"><?php _e( 'Related Products', 'woocommerce' ); ?></h2>
<?php woocommerce_product_loop_start(); ?>
<?php while ( $products->have_posts() ) : $products->the_post(); ?>