老问题,但在谷歌排名很高。这里有一个适用于当今Woocommerce的解决方案。
将此添加到您的函数中。php或自定义插件。
function exclude_brands_from_related( $categories ){
// array of category id\'s that should be excluded
$exclude_cats = array( \'100\', \'101\', \'102\');
foreach( $categories as $index => $cat ){
if( in_array( $cat->term_id, $exclude_cats ) ){
unset($categories[$index]);
}
}
return $categories;
}
add_filter( \'woocommerce_get_related_product_cat_terms\', \'exclude_brands_from_related\' );
并对标签执行相同操作:
function exclude_tags_from_related( $tags ){
// array of tags that should be excluded
$exclude_tags = array( \'discontinued\', \'whatever\', \'even-more\');
foreach( $tags as $index => $tag ){
if( in_array( $tag->slug, $exclude_tags ) ){
unset($tags[$index]);
}
}
return $tags;
}
add_filter( \'woocommerce_get_related_product_tag_terms\', \'exclude_tags_from_related\' );