Advertisement
Guest User

Untitled

a guest
May 24th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.53 KB | None | 0 0
  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' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement