Skip to content

Instantly share code, notes, and snippets.

@corsonr
Created December 12, 2013 09:17
Show Gist options
  • Save corsonr/7925232 to your computer and use it in GitHub Desktop.
Save corsonr/7925232 to your computer and use it in GitHub Desktop.
WooCommerce: products search form using a custom template file
<?php
$form = '<form role="search" method="get" id="searchform" action="' . esc_url( home_url( '/' ) ) . '">
<div>
<label class="screen-reader-text" for="s">' . __( 'Search for:', 'woocommerce' ) . '</label>
<input type="text" value="' . get_search_query() . '" name="s" id="s" placeholder="' . __( 'My Super Search form', 'woocommerce' ) . '" />
<input type="submit" id="searchsubmit" value="'. esc_attr__( 'Search', 'woocommerce' ) .'" />
<input type="hidden" name="post_type" value="product" />
</div>
</form>';
echo $form;
@neerajing
Copy link

I want to add 2 text field on product search form. Use he following code, where second text field name will be define and use AND condition.

<input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search Location&hellip;', 'placeholder', 'woocommerce' ); ?>" value="<?php echo get_search_query(); ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label', 'woocommerce' ); ?>" />

<input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search Date&hellip;', 'placeholder', 'woocommerce' ); ?>" value="<?php echo get_search_query(); ?>" name="s1" title="<?php echo esc_attr_x( 'Search for:', 'label', 'woocommerce' ); ?>" />

<input type="submit" value="<?php echo esc_attr_x( 'Search', 'submit button', 'woocommerce' ); ?>" />
<input type="hidden" name="post_type" value="product" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment