Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从商业中的相关产品中排除特定产品类别_Php_Wordpress_Woocommerce - Fatal编程技术网

Php 从商业中的相关产品中排除特定产品类别

Php 从商业中的相关产品中排除特定产品类别,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我们对类型和品牌使用WooCommerce产品类别,但是我们希望从相关产品中删除类型类别,只展示相同品牌的产品 我们找到了这个解决方案: 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 =

我们对类型和品牌使用WooCommerce产品类别,但是我们希望从相关产品中删除类型类别,只展示相同品牌的产品

我们找到了这个解决方案:

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' );
但是,它不适用于WooCommerce 3.2

任何帮助都将不胜感激