HUSKY - Product Filter for WooCommerce

woof_dynamic_count_attr

在动态产品重新计数查询执行之前,过滤WP_Query参数。当启用动态重新计数功能时,此钩子会在WOOF_HELPER::dynamic_count方法内部运行,允许您修改查询参数,这些参数决定每个筛选条件匹配多少产品。

参数

$args (array) — 传递给WP_QueryWoofCounter的查询参数。包含tax_query、meta_query、post_type以及自定义键wc_querywoof_query

$custom_type (string) — 传递给重新计数方法的自定义类型标识符(例如,分类法名称)。

源文件

index.php,第1902行

代码示例


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);

使用说明

  • 将此代码添加到您主题的functions.php文件或自定义插件中。
  • 查询已包含来自WOOF_REQUEST的目录可见性tax_query和当前筛选的tax_query/meta_query。
  • 接受2个参数 — 记得在函数签名中声明$a, $b