SHARE
TWEET

Untitled

a guest May 24th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. function custom_search( $query ) {
  4.  
  5.     if( ! is_admin() && $query->is_main_query() ) {
  6.  
  7.         if ( $query->is_search() ) {
  8.  
  9.             $meta_query = $query->get( 'meta_query' );
  10.  
  11.             $meta_query[] = array(
  12.                 'key'       => 'product_code',
  13.                 'value'     => $query->query['s'],
  14.                 'compare'   => 'LIKE'  
  15.             );
  16.  
  17.             $query->set( 'meta_query', $meta_query );
  18.  
  19.         }
  20.  
  21.     }
  22.  
  23. }
  24.  
  25. add_action( 'woocommerce_product_query' , 'custom_search' );
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top