Woocommerce 排除指定分类

// 从分类列表中排除指定分类
add_filter( 'get_terms', 'custom_exclude_category', 10, 3 );
function custom_exclude_category($terms, $taxonomies, $args)
{
    $new_terms = array();
    if (in_array('product_cat', $taxonomies) && ! is_admin() &&is_shop()) {
        foreach ($terms as $key => $term) {
            // 指定的分类slug
            if (!in_array($term->slug, array( 'gift-shop' ))) {
                $new_terms[] = $term;
            }
        }
        $terms = $new_terms;
    }
    return $terms;
}

 50 total views,  2 views today

Revisions

Comments are closed.