HUSKY - Product Filter for WooCommerce

woof_draw_products_get_args

过滤传递给 woof_draw_products AJAX 处理程序的合并 GET 参数。此钩子将请求链接中的 URL 查询字符串与当前 参数合并,让您有机会在通过 [woof_products] shortcode 渲染产品之前修改或扩展查询数据。

在两个位置调用:主 woof_draw_products AJAX 处理程序和 by_text 扩展的文本搜索处理程序。

参数

$query_args (array) — URL 查询参数和当前 值的合并数组,已通过 wc_clean() 清理。

$link (string) — 来自 AJAX 请求的原始 URL。

源文件

index.php, line 2728
ext/by_text/index.php, line 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 进行处理,并用 regex 替换空格。
  • 此钩子由 url_requestby_text 扩展在内部使用。
  • 接受 2 个参数 — 请记住在您的函数签名中声明 $a, $b