AnonymousInactive
Hello Ross.
First I want to say thank you for helping me.
I added this:
add_filter(‘body_class’,’add_body_class_to_search_filter’);
function add_body_class_to_search_filter($classes) {
global $searchandfilter;
if($searchandfilter->active_sfid())
{
$classes[] = “tax-product_cat archive woocommerce woocommerce-page alt-style-default boxed-layout two-col-right width-930 two-col-right-930”;
}
// return the $classes array
return $classes;
}
and it is still crashing my staging site. Anything else that needs to be changed?
Thanks
AnonymousInactive
Hello Again.
So if there is no way to use the Woocommerce display and remove the “shop” part of the URL I am stuck with the archive method. Only issue is when I follow your instructions to remove $sf_form_data with $searchandfilter like below:
add_filter(‘body_class’,’add_body_class_to_search_filter’);
function add_body_class_to_search_filter($classes) {
global $searchandfilter;
if ($searchandfilter->is_valid_form())
{
$classes[] = “tax-product_cat archive woocommerce woocommerce-page alt-style-default boxed-layout two-col-right width-930 two-col-right-930”;
}
// return the $classes array
return $classes;
}
it still breaks my staging site, what else do I need to fix to get it to work properly? I tried only replacing the first instance of $sf_form_data with $searchandfilter and that didn’t work either.
Thanks
AnonymousInactive
I have this in the functions file –
add_filter(‘body_class’,’add_body_class_to_search_filter’);
function add_body_class_to_search_filter($classes) {
global $sf_form_data;
if ($sf_form_data->is_valid_form())
{
$classes[] = “tax-product_cat archive woocommerce woocommerce-page alt-style-default boxed-layout two-col-right width-930 two-col-right-930”;
}
// return the $classes array
return $classes;
}
line 105 is:
if ($sf_form_data->is_valid_form())
AnonymousInactive
So I have sort of figured this out – the body classes –
Search and Filter Search Results Page –
<body class=”blog gecko alt-style-default boxed-layout two-col-right width-930 two-col-right-930″>
Woocommerce Archive Product Results Page –
<body class=”archive tax-product_cat term-afghan term-297 woocommerce woocommerce-page gecko alt-style-default boxed-layout two-col-right width-930 two-col-right-930″>
So the Search and Filter template needs those body classes that are missing, I see the code in your link but just so I don’t mess anything up can you confirm what the code should look like in my case?
Thanks so much for your help!
John
AnonymousInactive
Hi Ross 🙂
I read in this forum that the best template to use for woocommerce is archive-product.php.
I’m using the shortcode method, but I don’t understand if I have to modify my results.php page in order to look like archive-product.php (using woocommerce functions, such as do_action( ‘woocommerce_before_shop_loop’)) or if it’s simply a matter of css.
Now my search works, but the results are in list and not in grid.
I’m trying to understand by reading your guide here
https://support.searchandfilter.com/forums/search/woocommerce-page/
Is it a good start? 🙂
Hi Paul
I’ve had a quick look… the problem seems to be the wrong CSS is being applied to the search results page.
As I mentioned before ,these customisations are normally out of scope of support, but I think I’ve cracked it anyway.
Essentially, on your shop page, the body
tag has the following class woocommerce-page
(amongst others).
When I add these in firebug to the search results page, the results look like a grid – not sure if its exactly the same, but very similar…
So what you need to do is add some wordpress code to add these two classes to your body tags, on search result pages (take from: https://support.searchandfilter.com/forums/search/woocommerce-page/):
add_filter('body_class','add_body_class_to_search_filter');
function add_body_class_to_search_filter($classes) {
global $sf_form_data;
if ($sf_form_data->is_valid_form())
{
$classes[] = "woocommerce-page";
}
// return the $classes array
return $classes;
}
You can add this to the functions.php
of your theme.
Hope that helps!
Hey Janno
I would say this is a theme specific issue and not a plugin issue. I generally do not provide support for customising your theme template files – as these are more to do with your theme than the plugin – for example you can use this template anywhere in your theme (that is not the product archive) and I’m sure you would find similar results/problems.
However, that being said, the first thing to do with this kind of problem is check what the differences are between these two pages.
So I had a quick look at the source of the both the pages – although very similar there is one big difference.
If you take a look at the opening body tag you will notice the woocommerce page formatted in a grid has the class woocommerce-page
and the results page does not.
I added it via the dom inspector to http://vanka.magicservices.nl/producten and the grid works 🙂
So there are two approaches to fixing this – the first – edit your css rules so the grid classes are also applied to the Search & Filter results page…
or
Add this class to the body tag on your results page 🙂 This option is easier and only requires copying and pasting some code into functions.php
:
add_filter('body_class','add_body_class_to_search_filter');
function add_body_class_to_search_filter($classes) {
global $sf_form_data;
if ($sf_form_data->is_valid_form())
{
$classes[] = "woocommerce-page";
}
// return the $classes array
return $classes;
}
Hope that helps!