Created
May 4, 2019 16:13
-
-
Save trueqap/bc4d92def40fa8b8fb6d7e18ad2150e1 to your computer and use it in GitHub Desktop.
DIVI WooCommerce search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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