Categories

Monday, November 18, 2024
#919814419350 therichposts@gmail.com
WoocommerceWordpress Tricks

Woocommerce Custom Search With Select Query

How to add download pdf link in woocommerce single product page?

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>
</form>
<?php 
/*Search*/
  if(isset($_GET['searchtxt']))
  {
    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' );
      ?>
      <ul>
      <li><img src="<?php echo $attachment[0] ?>" /></li>
      <li><?php echo $product->post_title ?></li>  
      </ul>
      <?php
    }
  } 
/*Search*/
?>
<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) {
      $("#productS").submit();
    });
  });
</script>

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

Thank you,

Jatt,

TheRichPost

 

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

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