Reply 189237 to: Show related products by same category

Avatar: Rose Tyler
Rose Tyler
Support staff
March 26, 2018 at 12:06

Hello,

You can copy related.php (xstore/woocommerce/single-product) to xstore-child/woocommerce/single-product and make such changes https://prnt.sc/iwgubc:

$cats_array = wp_get_post_terms($product->get_id(),'product_cat',array('fields'=>'ids'));
$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'             => $related,
	'post__not_in'         => array( $product->get_id() ),
	'tax_query' => array(
		array(
			'taxonomy' => 'product_cat',
            'field' => 'id',
            'terms' => $cats_array
		)
	)
) );

Regards

Go To The Whole Conversation In Topic
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.