• Hello,
    If anyone is looking to let a user select a product category for their woocommerce search, you can use the following code in product-searchform.php

    Took me a few tries to figure it out so hopefully this helps someone. Thanks!

    <form method=”get” action=”<?php bloginfo(‘url’); ?>”>
    <fieldset>
    <input type=”text” name=”s” value=”<?php echo get_search_query(); ?>” placeholder=”<?php echo esc_attr_x( ‘Search Products…’, ‘placeholder’, ‘woocommerce’ ); ?>” maxlength=”50″ required=”required” title=”<?php echo esc_attr_x( ‘Search for:’, ‘label’, ‘woocommerce’ ); ?>” />
    <input type=”hidden” name=”post_type” value=”product” />
    <select name=”product_cat”>
    <option value=”>All</option>
    <?php
    $product_categories = get_terms( ‘product_cat’, $args );
    foreach( $product_categories as $cat ) {
    echo ‘<option value=”‘. $cat->slug .'”>’ . $cat->name . ‘</option>’;
    }
    ?>
    </select>
    <input type=”submit” value=”<?php echo esc_attr_x( ‘Search’, ‘submit button’, ‘woocommerce’ ); ?>” />
    </fieldset>
    </form>

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘WooCommerce – Select category for product search’ is closed to new replies.