Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
If you're experiencing a fatal error when switching languages on a product category page, specifically with the error message 'Fatal Error Illegal offset type in isset or empty' in

/wp-content/plugins/sitepress-multilingual-cms/classes/core-abstract-classes/class-wpml-element-translation.php:282

, we have identified a solution that does not require modifying the WPML plugin.
Solution:
The issue arises from a piece of code in

wp-content/themes/shopkeeper-child/woocommerce/archive-product.php

that retrieves a term named 'prod-cat__msg_banner'. The error occurs because the value returned is interpreted as an array with a blank element. Here are two solutions:
1. No code: Change the value in the database for the term ID to not be a serialized value. You can reference the original term ID 1135 to see how it is saved.
2. Using code: In

wp-content/themes/shopkeeper-child/woocommerce/archive-product.php

at line 316, after the code:

if (!empty($msg_banner)) { global $wp_query; }

add:

if (is_array($msg_banner)){ $msg_banner = $msg_banner[0]; }

Please test any of the solutions after making a full backup and let us know the results.

If this solution does not resolve your issue or seems outdated, we recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the problem persists, please open a new support ticket at WPML support forum.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by Mateus Getulio 6 months ago.

Assisted by: Mateus Getulio.

Author Posts
July 31, 2024 at 4:25 pm

zakW

Background of the issue:
I am getting a fatal error when I try to switch language on a product category page. The error message is: Fatal Error Illegal offset type in isset or empty in /wp-content/plugins/sitepress-multilingual-cms/classes/core-abstract-classes/class-wpml-element-translation.php:282. I am aware of a temporary fix for this here - https://wpml.org/forums/topic/fatal-error-on-language-switch/. I am looking for a solution that does not require me to modify the plugin.

Symptoms:
Fatal Error Illegal offset type in isset or empty in /wp-content/plugins/sitepress-multilingual-cms/classes/core-abstract-classes/class-wpml-element-translation.php:282

Questions:
Is there a solution for the fatal error that does not require modifying the WPML plugin?
Can you please advise me on other possible fixes for this issue?

July 31, 2024 at 4:52 pm
August 1, 2024 at 6:04 pm #16031068

Mateus Getulio
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hey there,

I checked this out but so far I couldn't find a fix for it.

I asked my colleagues to have a look at this issue in order to see if there's anything I'm missing.

I'll come back here as soon as one of my colleagues reply back to me (which it shouldn't take long).

Thanks,

August 2, 2024 at 1:17 pm #16033700

Mateus Getulio
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hi,

I have escalated this ticket to our 2nd tier of support where our 2nd tier specialists will take a deeper look at this issue and will try to find a solution.

I will get back to you as soon as I get an answer from them.

Best regards,
Mateus

August 5, 2024 at 8:37 am #16038027

zakW

Hi, following up if there has been a solution on this. Thanks.

August 5, 2024 at 3:02 pm #16040889

Mateus Getulio
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello there,

Upon further review, our team identified the culprit of the issue and eventually two solutions:

In the file: wp-content/themes/shopkeeper-child/woocommerce/archive-product.php there's a piece of code retrieving a term named prod-cat__msg_banner:

									$msg_banner  = get_term_meta( $prod_cat_id, 'prod-cat__msg_banner', true ) ?: esc_html( get_option( 'options_global_msg_banner' ) );

The value returned when you visit: /de/kollektionen/cushions-de/ is a:1:{i:0;s:0:"";} which is interpreted as an array with 1 element that is blank and this produces the error.

The term for /de/kollektionen/cushions-de/ have the ID 1705 and if you look in the DB you can see the value above a:1:{i:0;s:0:"";}. The original term has the ID 1135, you can check that it is okay having a plain value rather than a serialized field, hence the main language working properly without throwing errors.

There are two solutions for this issue:

1- No code:
Change the value in the database to not be a serialized value. You can look at the original term ID 1135 to see how it is saved.

2- Using code:
Go to wp-content/themes/shopkeeper-child/woocommerce/archive-product.php line 316 and after the code:

if ( !empty( $msg_banner ) )

{										global $wp_query;

add this:

if (is_array($msg_banner)){
 $msg_banner = $msg_banner[0];
}

Can you please test any of the solutions after making a full backup and tell me the results?

Thank you,
Mateus