【发布时间】:2019-01-06 18:45:56
【问题描述】:
我想从“我们的旅游”页面(slug 'our-tours-ru')上的 woocommerce 类别“Excursions”(slug 'excursions-ru')中排除所有产品/旅游。这里是this page
我找到了this solution here 所以我在下面使用了这段代码,但它对我不起作用。
找不到我的错误在哪里。
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
// to hide from shop page, replace is_page('YOUR_PAGE_SLUG') with is_shop()
if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && is_page('our-tours-ru') ) {
foreach ( $terms as $key => $term ) {
if ( ! in_array( $term->slug, array( 'excursions-ru' ) ) ) {
$new_terms[] = $term;
}
}
$terms = $new_terms;
}
return $terms;
}
【问题讨论】:
-
这么难的问题?
-
您好,您正在使用的功能是用于其他目的,此功能是从商店页面而不是产品中隐藏/删除类别。
标签: wordpress woocommerce categories product hook-woocommerce