Created
October 8, 2020 08:38
-
-
Save basmiddelham/ee32d079edd36637a6a444d36b7015c0 to your computer and use it in GitHub Desktop.
Custom Woocommerce product 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
<?php | |
/** | |
* Custom Woocommerce product search | |
*/ | |
add_filter( 'get_product_search_form', function ( $form ) { | |
$form ='<form role="search" method="get" class="woocommerce-product-search" action="' . esc_url( home_url( '/' ) ) . '"> | |
<label class="screen-reader-text" for="woocommerce-product-search-field">' . esc_html__( 'Search for:', 'woocommerce' ) . '</label> | |
<div class="input-group"> | |
<input type="search" | |
id="woocommerce-product-search-field" | |
class="search-field form-control form-control-sm" | |
placeholder="' . esc_attr__( 'Search products…', 'woocommerce' ) . '" | |
value="' . get_search_query() . '" | |
name="s" /> | |
<button type="submit" | |
class="btn btn-secondary btn-sm" | |
value="' . esc_attr_x( 'Search', 'submit button', 'woocommerce' ) . '">' | |
. esc_html_x( 'Search', 'submit button', 'woocommerce' ) . | |
'</button> | |
<input type="hidden" name="post_type" value="product" /> | |
</div> | |
</form>'; | |
return $form; | |
}, 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment