Created
December 11, 2017 17:42
-
-
Save ccurtin/3608d257025e86fc7578502bc65a41ee to your computer and use it in GitHub Desktop.
WooCommerce Search Products by Category Dropdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form name="myform" method="GET" action="<?php echo esc_url(home_url('/'));?>"> | |
<?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__('All Categories', 'woocommerce'), | |
'hierarchical' => 1, | |
'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="searchbox" maxlength="128" value="<?php echo get_search_query();?>" placeholder="<?php esc_attr_e('Search entire store here...', 'woocommerce');?>"> | |
<button type="submit" title="<?php esc_attr_e('Search', 'woocommerce');?>" class="search-btn-bg"><span><?php esc_attr_e('Search', 'woocommerce');?></span></button> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment