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) — 传递给重新计数方法的自定义类型标识符(例如,taxonomy 名称)。

源文件

index.php, line 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 文件或自定义插件中。
  • 查询已包含目录可见性 tax_query 和来自 WOOF_REQUEST 的当前过滤 tax_query/meta_query。
  • 接受 2 个参数 — 请记住在您的函数签名中声明 $a, $b