Skip to content

Instantly share code, notes, and snippets.

@trueqap
Created May 4, 2019 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trueqap/bc4d92def40fa8b8fb6d7e18ad2150e1 to your computer and use it in GitHub Desktop.
Save trueqap/bc4d92def40fa8b8fb6d7e18ad2150e1 to your computer and use it in GitHub Desktop.
DIVI WooCommerce search
function my_search_form( ) {
ob_start();
$post_type = isset($_GET['post_type'])?$_GET['post_type']:'';
?>
<form role="search" method="get" id="searchform" class="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<div>
<label class="screen-reader-text" for="s"><?php _x( 'Keresés:', 'label' ); ?></label>
<select class="searchfor">
<option value="" <?php selected( $post_type , '' ); ?>>Weboldalon</option>
<option value="product" <?php selected( $post_type , 'product' ); ?>>Termékek között</option>
</select>
<input type="text" value="<?php echo get_search_query(); ?>" name="s" id="s" />
<input type="hidden" class="post_type_search" name="" value="product" />
<input type="submit" id="searchsubmit" value="<?php echo esc_attr_x( 'Search', 'submit button' ); ?>" />
</div>
</form>
<script>
jQuery(function($){
$(document.body).on('change', '.searchfor', function(){
this.name = (this.value == 'product')?'post_type':'';
});
});
</script>
<?php
return ob_get_clean();
}
add_filter( 'get_search_form', 'my_search_form', 20 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment