title: WooCommerce filter search by category and custom field
body: <p>I want to ask how to create a woocommerce custom search form.</p>
  
  <p>My search and filter form has 3 fields:</p>
  
  <p><strong>Category:</strong> I managed to pull woocommerce product category into my custom search html form with <code>&lt;select&gt;</code> tag:</p>
  
  <pre><code>&lt;?php 
  $catTerms = get_terms('product_cat', array('hide_empty' =&gt; 0, 'orderby' =&gt; 'ASC', 'exclude' =&gt; '17,77'));
  foreach($catTerms as $catTerm) : ?&gt;
      &lt;option value="&lt;?php echo $catTerm-&gt;slug; ?&gt;"&gt;&lt;?php echo $catTerm-&gt;name; ?&gt;&lt;/option&gt;
  &lt;?php endforeach; ?&gt;
  </code></pre>
  
  <hr/>
  
  <p><strong>Filter By:</strong> (dropdown menu) by author:</p>
  
  <p>I added extra field to woocommerce using <code>woo_add_custom_general_fields_save()</code> function on theme's <code>functions.php,</code> works properly. </p>
  
  <p>Note: this is not 'custom field' we usually use on wordpress to add some more metadata, but this code below is to add more field on Product Data > General (on woocommerce).</p>
  
  <pre><code>function woo_add_custom_general_fields_save($post_id)
  {
      $woocommerce_textinput = $_POST['_book_author'];
      if( !empty( $woocommerce_textinput ) )
      update_post_meta( $post_id, '_book_author', esc_html( $woocommerce_textinput ) );
  }
  </code></pre>
  
  <hr/>
  
  <p><strong>By Title:</strong></p>
  
  <p>I managed to use this filter using <code>http://www.example.com/wp-root/woocommerce-product-page/?s=searchproducttitle</code></p>
  
  <p>Input text field:</p>
  
  <p>This is for user to search by keyword.</p>
  
  <p>So this is my complete custom html search form:</p>
  
  <pre><code>&lt;form action="&lt;?php echo site_url(); ?&gt;/pm-bookstore/" method="GET"&gt;
  
  &lt;select name=""&gt;
      &lt;?php $catTerms = get_terms('product_cat', array('hide_empty' =&gt; 0, 'orderby' =&gt; 'ASC', 'exclude' =&gt; '17,77')); ?&gt;
          &lt;?php foreach($catTerms as $catTerm) : ?&gt;
          &lt;option value="&lt;?php echo $catTerm-&gt;slug; ?&gt;"&gt;&lt;?php echo $catTerm-&gt;name; ?&gt;&lt;/option&gt;
      &lt;?php endforeach; ?&gt;                                            
  &lt;/select&gt;
  
  &lt;select name=""&gt;
      &lt;option value=""&gt;By author&lt;/option&gt;
      &lt;option value=""&gt;By title&lt;/option&gt;
  &lt;/select&gt;
  
  &lt;input type="text" placeholder="Search Book by Title, Author, ISBN..." name="s"&gt;
  &lt;button class="fa fa-search" type="submit"&gt;&lt;/button&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>For search parameter I expect to able to pull them all. But I only able to use the ?s parameter (which is only product title).</p>
  
  <p>I tried using another parameter, like, <code>product_cat</code>, <code>tag_ID</code>, but no success.</p>
  
  <p>At the moment I only able to use </p>
  
  <blockquote>
    <p><a href="http://www.example.com/wp-root/woocommerce-product-page/?s=searchproducttitle" rel="nofollow">http://www.example.com/wp-root/woocommerce-product-page/?s=searchproducttitle</a></p>
  </blockquote>
  
  <p>My expected result is:</p>
  
  <blockquote>
    <p><a href="http://www.example.com/wp-root/woocommerce-product-page/?s=searchproducttitle&amp;category=categoryslug&amp;author=authorname" rel="nofollow">http://www.example.com/wp-root/woocommerce-product-page/?s=searchproducttitle&amp;category=categoryslug&amp;author=authorname</a></p>
  </blockquote>
  
  <p>or</p>
  
  <blockquote>
    <p><a href="http://www.example.com/wp-root/woocommerce-product-page/?s=searchproducttitle&amp;category=categoryslug" rel="nofollow">http://www.example.com/wp-root/woocommerce-product-page/?s=searchproducttitle&amp;category=categoryslug</a></p>
  </blockquote>
  
  <p>How to make this search parameter working on woocommerce search?</p>
  
  <p>Thank you.</p>