Implement Exact Product Search in Woocommerce

Amit Patriwala
why-should-you-optimize-website-for-retina-displays

Today, One of our clients want relevant search for their product, they said it’s a crucial functionality of the site and they have almost 55,000 products on their website so it would better if the search is relevant. Our development team started working on it, they have found good plug-ins and solutions and we have shown to clients, but the are not happy. Finally, we have written customized code for it and now it’s work well with clients. We know you came across this kind of situations sometime and you need proper solutions. I believe below solution is work for you.

The Woocommerce Default search:

woocommerce-default-search

The Woocommerce Exact search:

Woocommerce-Exact-Search

Now, you can get an idea of the difference – right? how to implement it?

It’s a simple, go to theme function.php file and copy paste below code:

woocommerce-product-search

Also, you can copy below code:

/* Add the fiter for the product search*/
add_filter( ‘posts_search’, ‘ivory_perfect’, 20, 2 );

/*function for exact search*/
function ivory_perfect( $search, $wp_query ) {
global $wpdb;

if ( empty( $search ) )
return $search;

$q = $wp_query->query_vars;
$n = !empty( $q[‘exact’] ) ? ” : ‘%’;

$search = $searchand = ”;

foreach ( (array) $q[‘search_terms’] as $term ) {
$term = esc_sql( like_escape( $term ) );

$search .= “{$searchand}($wpdb->posts.post_title REGEXP ‘[[:<:]]{$term}[[:>:]]’) OR ($wpdb->posts.post_content REGEXP ‘[[:<:]]{$term}[[:>:]]’) OR ($wpdb->posts.post_excerpt REGEXP ‘[[:<:]]{$term}[[:>:]]’)”;

$searchand = ‘ AND ‘;
}

if ( ! empty( $search ) ) {
$search = ” AND ({$search}) “;
if ( ! is_user_logged_in() )
$search .= ” AND ($wpdb->posts.post_password = ”) “;
}

return $search;
}

Hope its work for you!!

India’s top Strategic Branding & Creative Website Design Agency

iVory Web Design & Branding Agency, a full-service website design & branding agency with offices in Ahmedabad and Baroda, is one of the Gujarat’s top website design & branding agency. Our services include advertising, marketing, business consulting, branding, logo design, corporate identity design, brochure design, digital marketing, media buying and planning, radio and TV advertising, Web design and development, online video advertising, social media marketing, SEO and Mobile Application Development. For the latest trends in website design and branding, contact iVory Web Design Private Limited today at 079-2762-2039 or visit www.ivorywebdesign.com.

Are looking for creative website design agency in Allentown, PA? or creative website design agency in Baroda, Gujarat? or creative website design in Florida, USA? or Creative Website Design Agency in Rajkot, Gujarat? or Creative Website Design Agency in Ahmedabad, Gujarat? or Are you looking for mobile application development agency in Ahmedabad? or Are you looking for mobile website design agency in Ahmedabad?

It's only fair to share...Share on Facebook0Share on Google+0Tweet about this on Twitter2Share on LinkedIn0

Author: Amit Patriwala

I’m a Programmer (.Net, PHP & Coldfusion), Consultant (Application Architecture Design, Web Portal Design, and Database design), Blogger (Digital Marketing, Website Design, Website Development, and Website Optimization & Latest Technology Stuff) and Strategist (Brand Design & Development). I work with companies, agencies, and top management executives to optimize their online brand presence with digital strategy, website design & development strategy, content marketing strategy and social media marketing.

My blog is about all the things to do with “Branding”, “Digital Marketing” and “Website Optimization”.

I’m passionate about the “Brand” since my college timing, I pursued my bachelor’s degree in information technology (B.E.I.T) from renowned engineering college “Nirma Institute of Technology”.