Woocommerce - 按关键字在产品类别中搜索

问题描述 投票:0回答:1
wordpress woocommerce hook-woocommerce
1个回答
0
投票

你可以做到这一点没有钩子

只需将类别输入的“name”属性更改为“product_cat”即可。

所以删除钩子并更改你的代码,如下所示:

  <form role="search" method="get" action="<?php echo get_permalink( woocommerce_get_page_id( 'shop' ) ); ?>">
            <div class="search-bar-select hidden-sm hidden-xs">
                <strong textspan></span>
                <i></i>
                <select name="product_cat">
                <option value="" class="search-bar-select-text"><?php _e('[:ru]Все категории[:ro]Toate categoriile') ?></option>
                <?php foreach(woo_category_list(FALSE) as $category) { ?>
                <option value="<?php echo $category->slug; ?>"><?php echo $category->cat_name; ?></option>
                <?php } ?>
                </select>
            </div>
            <div class="search-bar-input">
                <input type="text" name="s" value="<?php echo get_search_query(); ?>" placeholder="<?php _e('[:ru]Поиск по сайту ...[:ro]Căutare pe site') ?>" />
            </div>
            <input type="hidden" name="post_type" value="product" />
            <div class="search-bar-btn">
                <button type="submit"><i class="fa fa-search"></i></button>
            </div>
        </form>

要在下拉列表中列出所有产品猫,请使用以下方法:

(而不是 foreach(woo_category_list(FALSE) as $category) )

<?php 
$args = array(
   'taxonomy' => 'product_cat',
   'name' => 'product_cat',
   'value_field' => 'slug',
   'class' => 'something'
);
wp_dropdown_categories( $args );

?>
© www.soinside.com 2019 - 2024. All rights reserved.