Php 商业上相同子类别的4个相关产品
我想在页面底部展示4种产品,展示相关产品。只是同一子类别上的产品。为了实现这一点,我在related.php上做了如下更改Php 商业上相同子类别的4个相关产品,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我想在页面底部展示4种产品,展示相关产品。只是同一子类别上的产品。为了实现这一点,我在related.php上做了如下更改 $cats_array = array(4); // Get categories $terms = wp_get_post_terms( $product->id, 'product_cat' ); //Select only the category which doesn't have any children foreach ( $terms as $te
$cats_array = array(4);
// 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;
}
$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
),
)
) );
它只显示与子类别相关的产品。问题是它有时显示2,有时显示3。。。即使重新加载相同的产品,它也必须始终为4
我怎样才能做到这一点
谢谢