【发布时间】:2022-08-14 19:36:29
【问题描述】:
我想创建一个条件来手动隐藏商店内的类别。我已经从代码库开始,但我试图理解为什么如果我输入is_product_category() 条件,错误就会出现,因为我在 PHP 版本 8.0 的问题中指定
这是代码:
add_filter( \'get_terms\', \'sct_hide_cat\', 10, 3 );
function sct_hide_cat( $terms, $taxonomies, $args ) {
global $product;
$exclude = [50, 22, 20, 31, 35, 45, 40, 65, 37, 40, 3434];
$new_terms = [];
if ( in_array( \'product_cat\', $taxonomies ) && ! is_admin() && is_shop() || is_product_category() ) {
foreach ( $terms as $key => $term ) {
if ( ! in_array( $term->term_id, $exclude ) ) {
$new_terms[] = $term;
}
}
$terms = $new_terms;
}
return $terms;
}
标签: php wordpress woocommerce