Answer the question
In order to leave comments, you need to log in
How to scroll page to archive-product after search in woocommerce?
Search in the topic is arranged like this
$args = array(
'number' => '',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => true
);
$product_categories = get_terms( 'product_cat', $args );
$categories_show = '<option value="">'.__('All Categories','storevilla').'</option>';
$check = '';
if(is_search()){
if(isset($_GET['term']) && $_GET['term']!=''){
$check = sanitize_text_field( wp_unslash( $_GET['term'] ) );
}
}
$checked = '';
$allcat = __('All Categories','storevilla');
$categories_show .= '<optgroup class="sv-advance-search" label="'.esc_attr( $allcat ).'">';
foreach($product_categories as $category){
if(isset($category->slug)){
if(trim($category->slug) == trim($check)){
$checked = 'selected="selected"';
}
$categories_show .= '<option '.$checked.' value="'.esc_attr( $category->slug ).'">'.esc_html( $category->name ).'</option>';
$checked = '';
}
}
$categories_show .= '</optgroup>';
$form = '<form role="search" method="get" id="searchform" action="' . esc_url( home_url( '/' ) ) . '">
<div class="sv_search_wrap">
<select class="sv_search_product false" name="term">'.$categories_show.'</select>
</div>
<div class="sv_search_form">
<input type="text" value="' . get_search_query() . '" name="s" id="s" placeholder="' .esc_attr__('Поиск','storevilla'). '" />
<button type="submit" id="searchsubmit"> <img src=" '. get_bloginfo( 'stylesheet_directory' ) . '/assets/icons/loupe.svg"></button>
<input type="hidden" name="post_type" value="product" />
<input type="hidden" name="taxonomy" value="product_cat" />
</div>
</form>';
return $form;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question