HUSKY - Product Filter for WooCommerce

woof_husky_txt_option

Huskyのテキスト検索オートコンプリートドロップダウン内の各レンダリングHTMLオプションをフィルタリングし、個々の検索結果アイテムをカスタマイズできるようにします。

パラメータ

$html (string) — テンプレートからの単一の検索結果オプションのレンダリングされたHTML文字列

$data (array) — 商品データの連想配列。id、title、permalink、thumbnail、excerpt、breadcrumb、labels、optionsを含みます。

ソースファイル

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(how_to_open_links)、options、および商品メタデータが含まれます。
  • 「by_text」拡張機能のHusky検索機能の一部です。