wordpress - 在 wordpress/woosommerce 中隐藏某些产品类别
问题描述
我试图从商店页面和其他页面上的类别小部件中隐藏某个子类别,有一个类别小部件。我发现下面的代码适用于除商店页面之外的所有页面。如果我更改is_product_category()
,is_shop()
那么它适用于商店页面,但不适用于其他页面。
我怎样才能使它适用于所有页面(商店和所有其他页面)?
add_filter( 'get_terms', 'get_subcategory_terms', 10, 3 );
function get_subcategory_terms( $terms, $taxonomies, $args ) {
$new_terms = array();
// if a product category and on the shop page
if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && is_product_category() ) {
foreach ( $terms as $key => $term ) {
if ( ! in_array( $term->slug, array( 'seinakellad','nastennye-chasy','wall-clock' ) ) ) {
$new_terms[] = $term;
}
}
$terms = $new_terms;
}
return $terms;
}
解决方案
只需删除您的if
条件中的附加检查:
add_filter( 'get_terms', 'filter_get_terms', 10, 3 );
function filter_get_terms( $terms, $taxonomies, $args ) {
$new_terms = [];
// if a product category and on the shop page
if ( ! is_admin() ) {
foreach ( $terms as $term ) {
if ( ! in_array( $term->slug, [ 'seinakellad', 'nastennye-chasy', 'wall-clock' ] ) ) {
$new_terms[] = $term;
}
}
$terms = $new_terms;
}
return $terms;
}
推荐阅读
- fusionauth - 创建用户时,FusionAuth sendSetPasswordEmail 不发送设置密码电子邮件
- r - 特定正则表达式的正则表达式强制长度
- ios - 我收到 npm run ios 命令错误
- swift - 使用 TKSmardCard 在 iOS13 上向 SIM 卡发送 APDU 命令
- reactjs - 确保 prop 是来自常量的值 - TS
- c++ - 如何过滤双向链表?
- c# - C# - 为什么 this.Close(); 不适合我吗?
- java - 回收站视图不显示任何数据
- pandas - 如何在数据框中添加变量而不是数字?
- amazon-product-api - 503 RequestThrottled : 亚马逊产品广告 API CartCreate