Woocommerce header and footer missing from category page

Hi,

I’m having a strange problem. This is the website: http://woodbraceletsbibi.com/

It uses roots, woocommerce, wpml.

If I switch to product category page (Shop > Wooden Bracelets) and then switch to any other language except English, it doesn’t load header and footer. I know it used to work, but I’m not sure at what point during updating Woocommerce it brake down.

I also know it it’s ignoring archive-product.php in theme folder.

Can anyone please help me troubleshoot this? Thanks.

1 Like

I see know that Woocommerce is completely ignoring the woocommerce folder in my theme.

If it was a WooCommerce update that broke your site, then you should probably see what happened with their updates. Their support would also be a good place to start

Same issue there.
I can’t tell if it is an update problem, since I’m working on my site right now.

Looks like the base.php is not included when I browse a category in a language that is not the main one. I tried to debug putting in random echoes, and it looks like the function __toString() in wrapper.php is not called at all when I browse said pages.

__toString() is a magic method: PHP: Magic Methods - Manual

With an object, you generally interact with the object by calling it’s properties or methods. __toString() covers what happens if you do something with the class where a string is expected, IE:

$wrapper = new SageWrapping;
echo $wrapper;

__toString() would be used here.

Ok, that’s cool, but that wasn’t my point. I’ll try to explain better, maybe you can point me in the right direction to debug this issue.

As I already said, it happens when you browse a category while a language different from the main one is selected. In short, the output contains only the content you put in woocommerce/archive-product.php (that is, no header, no footer, or whatever you wrote in base.php).

Trying to find out where things go wrong, I opened lib/wrapper.php. I see a class with 3 functions, so I wrote a couple of echoes in one of them at a time, then I compared the outputs between a page that works and one that doesn’t. I tryed to echo $templates, $base and a static string. The output is the same when I echo from construct and wrap. Echoes from toString() don’t show up in the pages with this issue, neither print_r of $template nor the static string. From that I assumed that somewhere a “call” to toString is missing. Where should I look now?

Ok, I found the problem!
There is another hook that triggers with priority 100 and override what the wrapper is doing.
So, in order to solve, I changed this line in lib/wrapper.php:

add_filter('template_include', [__NAMESPACE__ . '\\SageWrapping', 'wrap'], 101); // priority 101

The hook that create the problem is set by Woocommerce Multilingual, the legacy plugin between WPML and Woocommerce.

Hope this can bel helpful also for you @marjanbajc !

2 Likes

Ohhhhh yeaaaah! Great great job! Wouldn’t figure it out in a million years! Thanks so much!