This demo site runs SureCart with Relevanssi active, the same combination as your store. The four demo products are modelled on your shop, so the same search words work.
Try it
- Before the fix: https://sure.ivacode.com/product-search-before-1546989/
Type toolkit in the search box. Result: No products found. (exactly what your shop does). - With the fix: https://sure.ivacode.com/product-search-fixed-1546989/
Type toolkit. Result: the two Advocacy Toolkit products. Clear the box and all four come back. Sorting still works while a search is active. - Regular site search (still run by Relevanssi): https://sure.ivacode.com/?s=toolkit
This is where the Kadence, WordPress and Relevanssi search blocks send visitors. Products are listed together with pages and posts. These blocks cannot filter the shop grid.
Why the shop search came back empty
The SureCart Product Search block does not use the site search. When you type, it reloads the product list with ?products-search=toolkit and SureCart runs its own WordPress query for matching products.
Relevanssi replaces every front-end WordPress query that contains a search term with an empty one (SELECT * FROM wp_posts WHERE 1=2) to save database work, because it plans to supply the results itself. It only supplies them for the main site search results page. The SureCart product list is a separate query, so it is emptied and nothing refills it. Relevanssi documents this on its relevanssi_prevent_default_request page, together with the switch used below.
The fix
This tells Relevanssi to leave the SureCart product list query alone. The regular site search stays with Relevanssi.
/**
* SureCart shop search + Relevanssi.
*
* Relevanssi replaces every front-end WordPress query that contains a search
* term with an empty one ("SELECT * FROM wp_posts WHERE 1=2") and only fills in
* its own results for the main site search. The SureCart Product List (the
* search box on the shop page) runs its own product query, so it always ended
* up with "No products found."
*
* This tells Relevanssi to leave that one query alone, so WordPress runs the
* product search itself. The normal site search stays with Relevanssi.
*/
function cpj_surecart_skip_relevanssi( $value, $query ) {
$is_surecart_product_list = $query instanceof WP_Query
&& ! $query->is_main_query()
&& in_array( 'sc_product', (array) $query->get( 'post_type' ), true );
return $is_surecart_product_list ? false : $value;
}
add_filter( 'relevanssi_prevent_default_request', 'cpj_surecart_skip_relevanssi', 10, 2 );
add_filter( 'relevanssi_search_ok', 'cpj_surecart_skip_relevanssi', 10, 2 );
How to add it (WPCode, free)
- Plugins > Add New, search for WPCode, install and activate it.
- Code Snippets > + Add Snippet > Add Your Custom Code (New Snippet) > PHP Snippet.
- Give it a title, paste the code above into the Code Preview box.
- Insertion: Auto Insert, Location: Run Everywhere.
- Switch it to Active and click Save Snippet.
- Clear your site cache, then type a product name in the shop search box.
Prefer a child theme? Paste the same code at the end of your child theme’s functions.php instead.