WoocommerceWordpress Tricks

Woocommerce Custom Search With Select Query

Woocommerce Custom Search With Select Query - The Rich Post


Hello to all, welcome to therichpost.com. In this post, I will tell you, Woocommerce Custom Search  With Select Query.

WordPress is the best CMS and Woocommerce is the best Ecommerce Plugin.

Woocommerce Custom Search  With Select Query, this is very basic thing but sometime, it is difficult to develop easy things so I am sharing this code on my blog.


Here is the working and tested code and you can this into your any wordpress theme’s template file:


<form method="get" id="productS">
<input type="text" name="searchtxt" class="" />
<button type="search"><i class="icon-search searcBtn"></i></button>
    global $wpdb;
    $result = $wpdb->get_results("SELECT * FROM `wp_posts` WHERE `post_title` like '%".$_GET['searchtxt']
    ."%' and post_type = 'product'");
    foreach ($result as $product) {
      $_product = wc_get_product( $product->ID );

      $attachment_ids[0] = get_post_thumbnail_id($product->ID);
      $attachment = wp_get_attachment_image_src($attachment_ids[0], 'thumbnail' );
      <li><img src="<?php echo $attachment[0] ?>" /></li>
      <li><?php echo $product->post_title ?></li>  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
  jQuery(document).ready(function($) {
    $(".searcBtn").click(function(event) {

If you have any query related to this post, then do comment below or ask questions.

Thank you,




Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Positive SSL