HUSKY - Product Filter for WooCommerce

woof_husky_txt_option

过滤Husky文本搜索自动补全下拉菜单中每个渲染的HTML选项,从而允许自定义单个搜索结果项。

参数

$html (string) — 来自模板的单个搜索结果选项的渲染HTML字符串

$data (array) — 关联数组,包含产品数据:id、标题、永久链接、缩略图、摘要、面包屑导航、标签和选项

源文件

ext/by_text/index.php:1066

代码示例


add_filter('woof_husky_txt_option', function($html, $data) {
    // Add a price badge to each result
    $product = wc_get_product($data['id']);
    if ($product) {
        $price = wc_price($product->get_price());
        $html = str_replace('</a>', '</a> <span class="price-badge">' . $price . '</span>', $html);
    }
    return $html;
}, 10, 2);

使用说明

  • 仅在存在有效模板路径时触发。
  • $data数组包含click_target(链接打开方式)、options和产品元数据。
  • 属于'by_text'扩展的Husky搜索功能的一部分。