woof_draw_products_get_args
过滤传递给 woof_draw_products AJAX 处理器的合并 GET 参数。该钩子将请求链接中的 URL 查询字符串与当前的 参数合并,让您有机会在通过 [woof_products] 短代码渲染产品之前修改或扩展查询数据。
在两个位置调用:主 woof_draw_products AJAX 处理器和 by_text 扩展的文本搜索处理器。
参数
$query_args (array) — 合并的 URL 查询参数与当前 值数组,已通过 wc_clean() 进行净化处理。
$link (string) — 来自 AJAX 请求的原始 URL。
源文件
index.php,第 2728 行ext/by_text/index.php,第 981 行
代码示例
add_filter("woof_draw_products_get_args", function ($query_args, $link) {
// Force a specific product category in the query
$query_args["product_cat"] = "clothing";
return $query_args;
}, 10, 2);
使用说明
- 将此代码添加到您的主题的
functions.php文件或自定义插件中。 - 返回的数组会通过
array_map进行传递,并在过滤器运行后对空格进行正则替换。 - 此钩子由
url_request和by_text扩展内部使用。 - 接受 2 个参数 — 记得在函数签名中声明
$a, $b。