Skip Navigation

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

Problem:
If you're experiencing a fatal error on your shop page while searching, which results in a PHP error related to 'Call to a member function get_id() on bool', this might be due to an issue in the WooCommerce Multilingual plugin.
Solution:
We recommend you try the following steps after ensuring you have a full site backup:

1) Navigate to the

wp-content\plugins--woocommerce-multilingual\inc

folder.
2) Open the

class-wcml-comments.php

file for editing.
3) Scroll down to line 109.
4) Replace the existing code block with the following updated code:

From

foreach ( $translations as $translation ) {
	$product = wc_get_product( $translation );

	$ratings      = WC_Comments::get_rating_counts_for_product( $product );
	$review_count = WC_Comments::get_review_count_for_product( $product );

	if ( is_array( $ratings ) ) {
		foreach ( $ratings as $rating => $count ) {
			$average_ratings_sum   += $rating * $count;
			$average_ratings_count += $count;
			if ( isset( $ratings_count[ $rating ] ) ) {
				$ratings_count[ $rating ] += $count;
			} else {
				$ratings_count[ $rating ] = $count;
			}
		}
	}

	if ( $review_count ) {
		$reviews_count += $review_count;
	} else {
		update_post_meta( $translation, self::WCML_AVERAGE_RATING_KEY, null );
		update_post_meta( $translation, self::WCML_REVIEW_COUNT_KEY, null );
		update_post_meta( $translation, self::WCML_RATING_COUNT_KEY, null );
	}
}

To

foreach ( $translations as $translation ) {
	$product = wc_get_product( $translation );

	if ($product) {
		$ratings      = WC_Comments::get_rating_counts_for_product( $product );
		$review_count = WC_Comments::get_review_count_for_product( $product );

		if ( is_array( $ratings ) ) {
			foreach ( $ratings as $rating => $count ) {
				$average_ratings_sum   += $rating * $count;
				$average_ratings_count += $count;
				if ( isset( $ratings_count[ $rating ] ) ) {
					$ratings_count[ $rating ] += $count;
				} else {
					$ratings_count[ $rating ] = $count;
				}
			}
		}

		if ( $review_count ) {
			$reviews_count += $review_count;
		} else {
			update_post_meta( $translation, self::WCML_AVERAGE_RATING_KEY, null );
			update_post_meta( $translation, self::WCML_REVIEW_COUNT_KEY, null );
			update_post_meta( $translation, self::WCML_RATING_COUNT_KEY, null );
		}
	}
	
}

5) Clear all types of caches.

Please note, this issue has been escalated to our developers for further investigation and resolution.

If this solution does not resolve your issue, or if it seems outdated or irrelevant to your case, we highly 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 needed, 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 1 reply, has 2 voices.

Last updated by Bigul 1 year, 6 months ago.

Assisted by: Bigul.

Author Posts
June 30, 2023 at 3:43 pm #13924905

tuomoN-2

Hi Bigul,

Fatal error in shop page while searching hidden link

[21-Jun-2023 19:16:01 UTC] PHP Fatal error:  Uncaught Error: Call to a member function get_id() on bool in C:\laragon\www\compsupp-6811\wp-content\plugins\woocommerce\includes\class-wc-comments.php:447
Stack trace:
#0 C:\laragon\www\compsupp-6811\wp-content\plugins\--woocommerce-multilingual\inc\class-wcml-comments.php(112): WC_Comments::get_rating_counts_for_product(false)
#1 C:\laragon\www\compsupp-6811\wp-content\plugins\--woocommerce-multilingual\inc\class-wcml-comments.php(168): WCML_Comments->recalculate_comment_rating(83)
#2 C:\laragon\www\compsupp-6811\wp-includes\class-wp-hook.php(310): WCML_Comments->filter_average_rating(NULL, 83, '_wc_rating_coun...', true)
#3 C:\laragon\www\compsupp-6811\wp-includes\plugin.php(205): WP_Hook->apply_filters(NULL, Array)
#4 C:\laragon\www\compsupp-6811\wp-includes\meta.php(633): apply_filters('get_post_metada...', NULL, 83, '_wc_rating_coun...', true, 'post')
#5 C:\laragon\www\compsupp-6811\wp-includes\meta.php(572): get_metadata_raw('post', 83, '_wc_rating_coun...', true)
#6 C:\laragon\www\compsupp-6811\wp-in in C:\laragon\www\compsupp-6811\wp-content\plugins\woocommerce\includes\class-wc-comments.php on line 447
June 30, 2023 at 5:05 pm #13925201

Bigul
Supporter

Languages: English (English )

Timezone: Europe/Vienna (GMT+01:00)

Hello,

Welcome to the WPML support forum. I will do my best to help you to resolve the issue.

Please try the following steps after a full site backup{mandatory} and make sure the issue is existing or not.

1) Go to *wp-content\plugins--woocommerce-multilingual\inc* folder
2) Open *class-wcml-comments.php* file for edit
3) Scroll down to line 109
4) Make the following changes & save the file

From

foreach ( $translations as $translation ) {
	$product = wc_get_product( $translation );

	$ratings      = WC_Comments::get_rating_counts_for_product( $product );
	$review_count = WC_Comments::get_review_count_for_product( $product );

	if ( is_array( $ratings ) ) {
		foreach ( $ratings as $rating => $count ) {
			$average_ratings_sum   += $rating * $count;
			$average_ratings_count += $count;
			if ( isset( $ratings_count[ $rating ] ) ) {
				$ratings_count[ $rating ] += $count;
			} else {
				$ratings_count[ $rating ] = $count;
			}
		}
	}

	if ( $review_count ) {
		$reviews_count += $review_count;
	} else {
		update_post_meta( $translation, self::WCML_AVERAGE_RATING_KEY, null );
		update_post_meta( $translation, self::WCML_REVIEW_COUNT_KEY, null );
		update_post_meta( $translation, self::WCML_RATING_COUNT_KEY, null );
	}
}

To

foreach ( $translations as $translation ) {
	$product = wc_get_product( $translation );

	if ($product) {
		$ratings      = WC_Comments::get_rating_counts_for_product( $product );
		$review_count = WC_Comments::get_review_count_for_product( $product );

		if ( is_array( $ratings ) ) {
			foreach ( $ratings as $rating => $count ) {
				$average_ratings_sum   += $rating * $count;
				$average_ratings_count += $count;
				if ( isset( $ratings_count[ $rating ] ) ) {
					$ratings_count[ $rating ] += $count;
				} else {
					$ratings_count[ $rating ] = $count;
				}
			}
		}

		if ( $review_count ) {
			$reviews_count += $review_count;
		} else {
			update_post_meta( $translation, self::WCML_AVERAGE_RATING_KEY, null );
			update_post_meta( $translation, self::WCML_REVIEW_COUNT_KEY, null );
			update_post_meta( $translation, self::WCML_RATING_COUNT_KEY, null );
		}
	}
	
}

5) Clear all types of caches

Please note, this bug is escalated to our developers for detailed debugging and fixing.

--
Thanks!

Bigul