Woocommerce Advanced Search with Attributes

I hope someone can help me with this. I have a woocommerce site that all of my products have an attribute of a specific city. I would like the main product search to have a text field and a drop down of the the cities so the results are only products with the relevant term in the specified city.

I cannot find anything on how to add the attribute drop down and make sure that this filter is part of the search query. Help!

Read More

Update:

Found something useful by using taxonomies in a drop down menu on the searchform.php file:

            <?php
            function get_terms_dropdown($taxonomies, $args){
            $myterms = get_terms($taxonomies, $args);
            $optionname = "optionname";
            $emptyvalue= "";
            $output ="<select name='".$optionname."'><option selected='".$selected."' value='".$emptyvalue."'>Select a City</option>'";

            foreach($myterms as $term){
            $term_taxonomy=$term->pa_city; //CHANGE ME
            $term_slug=$term->slug;
            $term_name =$term->name;
            $link = $term_slug;
            $output .="<option name='".$link."' value='".$link."'>".$term_name."</option>";
            }
            $output .="</select>";
            return $output;
            }

            $taxonomies = array('pa_city'); // CHANGE ME
            $args = array('order'=>'ASC','hide_empty'=>true);
            echo get_terms_dropdown($taxonomies, $args);

            ?>

Only problem is I cannot find where to pass the option name taxonomy in woocommerce. This search does not appear to use search.php. Does anyone know where I can pass this in woocommerce?

Related posts

Leave a Reply