NextGen IT

Related Product from Product Category – Woocommecre

Go to your Theme > Woocommerce > Single-Product > related.php

write this code

$cats_array = array(0);

// Get categories
$terms = wp_get_post_terms($product – > id, ‘product_cat’);

//Select only the category which doesn’t have any children
foreach($terms as $term) {
$children = get_term_children($term – > term_id, ‘product_cat’);
if (!sizeof($children))
$cats_array[] = $term – > term_id;
}

and changed the $args with this

$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,
‘tax_query’ => array(
array(
‘taxonomy’ => ‘product_cat’,
‘field’ => ‘id’,
‘terms’ => $cats_array
),
)
));

November 30, 2015

0 Responses on Related Product from Product Category - Woocommecre"

Leave a Message

Nextgen BD © 2017 . All rights reserved. Designed & Developed by SKILL TOUCH IT.