HUSKY - Product Filter for WooCommerce

woof_dynamic_count_attr

Filters the WP_Query arguments before the dynamic product recount query is executed. This hook runs inside the WOOF_HELPER::dynamic_count method when the dynamic recount feature is enabled, and allows you to modify the query parameters that determine how many products match each filter term.

Parameters

$args (array) — The query arguments passed to WP_QueryWoofCounter. Includes tax_query, meta_query, post_type, and custom keys wc_query and woof_query.

$custom_type (string) — The custom type identifier passed to the recount method (e.g., taxonomy name).

Source File

index.php, line 1902

Code Example


add_filter("woof_dynamic_count_attr", function ($args, $custom_type) {
    // Exclude a specific product category from counts
    if (!isset($args["tax_query"])) {
        $args["tax_query"] = array();
    }
    $args["tax_query"][] = array(
        "taxonomy" => "product_cat",
        "field"    => "slug",
        "terms"    => "uncategorized",
        "operator" => "NOT IN"
    );
    return $args;
}, 10, 2);

Usage Notes

  • Add this code to your theme's functions.php file or a custom plugin.
  • The query already includes catalog visibility tax_query and the current filter tax_query/meta_query from WOOF_REQUEST.
  • Accepts 2 parameters — remember to declare $a, $b in your function signature.