Skip to content

Instantly share code, notes, and snippets.

@aimahdi
Last active November 11, 2025 08:59
Show Gist options
  • Select an option

  • Save aimahdi/6ae625e39e694dcd4665291a46080db0 to your computer and use it in GitHub Desktop.

Select an option

Save aimahdi/6ae625e39e694dcd4665291a46080db0 to your computer and use it in GitHub Desktop.
<?
add_filter('fluent_cart/shop_query', function ($query, $params) {
if (is_admin()) {
return $query;
}
// Term IDs to exclude (product-categories)
$excluded_ids = [11];
$query->whereDoesntHave('wp_terms', function ($rel) use ($excluded_ids) {
$rel->whereHas('taxonomy', function ($tt) use ($excluded_ids) {
$tt->where('taxonomy', 'product-categories')
->whereIn('term_id', $excluded_ids);
});
});
return $query;
}, 10, 2);
add_filter('get_terms', 'exclude_fluentcart_categories_frontend_only', 10, 3);
function exclude_fluentcart_categories_frontend_only($terms, $taxonomies, $args) {
if (!in_array('product-categories', $taxonomies)) {
return $terms;
}
if (is_admin()) {
return $terms;
}
if (is_singular('fluent-products')) {
return $terms;
}
$is_frontend_shop = (
!wp_doing_ajax() ||
(isset($_REQUEST['action']) && $_REQUEST['action'] === 'fluent_cart_shop_products')
);
if ($is_frontend_shop || !wp_doing_ajax()) {
$excluded_category_ids = array(2); //category ID
if (!empty($terms) && is_array($terms)) {
$terms = array_filter($terms, function($term) use ($excluded_category_ids) {
return !in_array($term->term_id, $excluded_category_ids);
});
}
}
return $terms;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment