I tried include custom fields value in woocommerce search but i have a problem.
On Google and Stack too, i saw examples with pre_get_posts, so i thought this is good direction and i made code like this:
function custom_search( $query ) {
if( ! is_admin() && $query->is_main_query() ) {
if ( $query->is_search() ) {
$meta_query = array(
'key' => 'custom_color',
'value' => $query->query['s'],
'compare' => 'LIKE'
);
$query->set( 'meta_query', $meta_query );
}
}
}
add_action( 'pre_get_posts' , 'custom_search' );
Unfortunately it's not working. Can You help me?