R
R
Rasul Gudantov2018-01-30 14:41:42
WordPress
Rasul Gudantov, 2018-01-30 14:41:42

How to make a search in woocommerce in each category?

Hello!
Can you tell me how to make a separate search in each category?
That is, there are 3 main categories in the WooCommerce store, and the products in these categories have the same article numbers. It turns out that when you enter an article in the search, not only the product from the desired category, but also from another one (which is very disturbing) can come out.
For example: I went to the KAMAZ category and want to find a product by the required article, but the search gives me a product from all three categories.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rasul Gudantov, 2018-01-30
@Grarnik

Somehow I found the info on how to do a search by category. Just searched for 3 days)
Go to the /your_theme/woocommerce/product-searchform.php file and replace it with the one below.

<form method="get" id="searchform" class="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>" role="search">

<?php if (class_exists('WooCommerce')) : ?>
<?php
if(isset($_REQUEST['product_cat']) && !empty($_REQUEST['product_cat']))
{
$optsetlect=$_REQUEST['product_cat'];
}
else{
$optsetlect=0;
}
$args = array(
'show_option_all' => esc_html__( 'Все категории', 'woocommerce' ),
'hierarchical' => 1,
'depth' => 2,
'class' => 'cat',
'echo' => 1,
'value_field' => 'slug',
'selected' => $optsetlect
);
$args['taxonomy'] = 'product_cat';
$args['name'] = 'product_cat';
$args['class'] = 'cate-dropdown hidden-xs';
wp_dropdown_categories($args);

?>

<input type="hidden" value="product" name="post_type">
<?php endif; ?>

<input type="text" name="s" class="" id="s2" value="<?php echo get_search_query(); ?>" placeholder="Поиск по товарам.." />

<button type="submit" class="pic-sea" value=""><i class="fa fa-search"></i></button>

</form>

depth is the category nesting level, if necessary, set it to 1.
Source: https://opttour.ru/web/wordpress/poisk-po-kategoriyam/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question