【发布时间】:2020-08-21 21:52:38
【问题描述】:
我一直在尝试使用this StackOverFlow answer code 并按照this other forum thread 上的说明隐藏特定类别(从商店页面和单个页面)中的所有产品
在 “Exclude specific product categories on Woocommerce single product pages” 回答代码上,我已将我的产品类别之一定义如下 (此处为术语 Id 43):
$category_ids = array( 43 );
我只需要将此类别 (ID 43) 的所有产品添加到购物车并购买。
类别 ID 43“计划”的产品之一:https://mamasmateas.atac.cl/product/plan-personalizado-sin-seguimiento/
我测试过的其他代码是:
add_filter( 'get_terms', 'ts_get_subcategory_terms', 10, 3 );
function ts_get_subcategory_terms( $terms, $taxonomies, $args ) {
$new_terms = array();
// if it is a product category and on the shop page
if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && is_shop() ) {
foreach ( $terms as $key => $term ) {
if ( ! in_array( $term->slug, array( 'plan' ) ) ) { //pass the slug name here
$new_terms[] = $term;
}
}
$terms = $new_terms;
}
return $terms;
}
任何帮助将不胜感激。
【问题讨论】:
-
嗨!代码运行良好。是我激活的插件有问题。我的解决方案有两个问题:1)类别过滤器仍然显示隐藏类别。 2)我一直在使用 WP Bakery 中用于 woocommerce 的添加到购物车预设按钮,并且使用此代码,该按钮未显示。是否有额外的代码来启用它?或以其他方式获取此特定类别产品的“添加到购物车”按钮?非常感谢提前
-
大家好,我仍然遇到这个问题。首先,我不能将 WP Bakery 的添加到购物车按钮用于 woocommerce,似乎隐藏类别禁用了此选项。其次,我也无法在商店选项中隐藏类别。是否可以使用上面的代码启用此添加到购物车选项?之后有可能隐藏特定类别吗?非常感谢,并希望在此问题上获得最后的帮助。
标签: php wordpress woocommerce product taxonomy-terms