CRITICAL : Uncaught Error
-
Hello,
in the error logs I see this error coming back a few times per day :
CRITICAL : Uncaught Error: Call to a member function get_id() on null in /home/dynamitem/public_html/wp-content/plugins/official-facebook-pixel/integration/class-facebookwordpresswoocommerce.php:646
I cannot see if something happens while people are shopping, we can test and test and everything seems to work, however these errors should not be there. As business is slower then usual I want this resolved so we know it this is causing anything.
We have Woocommerce 3.8.5 installed, flatsome theme and everything is up to date.
Metapixel for WordPress is version 4.1.3
Woocommerce 9.8.5 (but noticed there is a newer version available just now)
PHP Version 8.3.20
I am not a programmer/developer myself, just the webshop owner, if there is anybody out there that can help me out that would be appreciated!
René
The page I need help with: [log in to see the link]
-
we are having a similar issue
PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in /www/onetoworld_639/public/wp-content/plugins/official-facebook-pixel/integration/class-facebookwordpresswoocommerce.php:231
Stack trace:
#0 /www/onetoworld_639/public/wp-content/plugins/official-facebook-pixel/integration/class-facebookwordpresswoocommerce.php(231): count(false)
#1 /www/onetoworld_639/public/wp-content/plugins/official-facebook-pixel/integration/class-facebookwordpresswoocommerce.php(208): FacebookPixelPlugin\Integration\FacebookWordpressWooCommerce::getProductCategory(28207)
#2 [internal function]: FacebookPixelPlugin\Integration\FacebookWordpressWooCommerce::createViewContentEvent(Object(WC_Product_Simple))
#3 /www/onetoworld_639/public/wp-content/plugins/official-facebook-pixel/core/class-servereventfactory.php(306): call_user_func_array(Array, Array)
#4 /www/onetoworld_639/public/wp-content/plugins/official-facebook-pixel/integration/class-facebookwordpresswoocommerce.php(174): FacebookPixelPlugin\Core\ServerEventFactory::safe_create_event('ViewContent', Array, Array, 'woocommerce')
#5 /www/onetoworld_639/public/wp-includes/class-wp-hook.php(324): FacebookPixelPlugin\Integration\FacebookWordpressWooCommerce::trackViewContentEvent('')
#6 /www/onetoworld_639/public/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)
#7 /www/onetoworld_639/public/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#8 /www/onetoworld_639/public/wp-content/plugins/woocommerce/templates/content-single-product.php(76): do_action('woocommerce_aft...')its because on file wp-content/plugins/official-facebook-pixel/integration/class-facebookwordpresswoocommerce.php around line 231 you guys aren’t checking if the get_terms function is not returning empty. it causes a fatal error on the count function on a false return from that function changing that line to
return ! empty( $categories ) && count( $categories ) > 0 ? $categories[0]->name : null;that solves the issue for us it was actually causing product pages not to load at all for the ones with no categories.
Hello, thanks for the reply. I am not a developer, I don’t know if our issue is of the same type and what to do now. I do have more information, see here:
2025-06-10T00:28:27+00:00 Critical Uncaught Error: Call to a member function get_id() on null in /home/dynamitem/public_html/wp-content/plugins/official-facebook-pixel/integration/class-facebookwordpresswoocommerce.php:646
Aanvullende context
{
"error": {
"type": 1,
"file": "/home/dynamitem/public_html/wp-content/plugins/official-facebook-pixel/integration/class-facebookwordpresswoocommerce.php",
"line": 646
},
"remote-logging": true,
"backtrace": [
"",
"#0 /home/dynamitem/public_html/wp-content/plugins/official-facebook-pixel/integration/class-facebookwordpresswoocommerce.php(426): FacebookPixelPlugin\Integration\FacebookWordpressWooCommerce::getProductId()",
"#1 [internal function]: FacebookPixelPlugin\Integration\FacebookWordpressWooCommerce::createAddToCartEvent()",
"#2 /home/dynamitem/public_html/wp-content/plugins/official-facebook-pixel/core/class-servereventfactory.php(306): call_user_func_array()",
"#3 /home/dynamitem/public_html/wp-content/plugins/official-facebook-pixel/integration/class-facebookwordpresswoocommerce.php(346): FacebookPixelPlugin\Core\ServerEventFactory::safe_create_event()",
"#4 /home/dynamitem/public_html/wp-includes/class-wp-hook.php(326): FacebookPixelPlugin\Integration\FacebookWordpressWooCommerce::trackAddToCartEvent()",
"#5 /home/dynamitem/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()",
"#6 /home/dynamitem/public_html/wp-includes/plugin.php(517): WP_Hook->do_action()",
"#7 /home/dynamitem/public_html/wp-content/plugins/woocommerce/includes/class-wc-cart.php(1317): do_action()",
"#8 /home/dynamitem/public_html/wp-content/plugins/woocommerce/includes/class-wc-form-handler.php(871): WC_Cart->add_to_cart()",
"#9 /home/dynamitem/public_html/wp-content/plugins/woocommerce/includes/class-wc-form-handler.php(843): WC_Form_Handler::add_to_cart_handler_simple()",
"#10 /home/dynamitem/public_html/wp-includes/class-wp-hook.php(324): WC_Form_Handler::add_to_cart_action()",
"#11 /home/dynamitem/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()",
"#12 /home/dynamitem/public_html/wp-includes/plugin.php(517): WP_Hook->do_action()",
"#13 /home/dynamitem/public_html/wp-settings.php(749): do_action()",
"#14 /home/dynamitem/public_html/wp-config.php(116): require_once('/home/dynamitem...')",
"#15 /home/dynamitem/public_html/wp-load.php(50): require_once('/home/dynamitem...')",
"#16 /home/dynamitem/public_html/wp-blog-header.php(13): require_once('/home/dynamitem...')",
"#17 /home/dynamitem/public_html/index.php(17): require('/home/dynamitem...')",
"#18 {main}",
"thrown"
]
}Maybe this helps? If any one can help or tell what code to find and/or replace (I assume around line 646?) or edit I can ask the hosting company to do so.
-
This reply was modified 11 months, 2 weeks ago by
renegeelen.
Hi @renegeelen – thanks for reaching out!
Can you try the following:
- Temporarily disable all cache plugins and clear the cache
- Reinstall, then re-connect the plugin to your page
If the issue persist, please share your system status report using PrivateBin.
@cornershop – feel free to open this is as a Pull Request on the official repo, so that the Dev team can take it into consideration for future releases.
Kind regards,
MarijaMy hosting company made the change exactly as @cornershop suggested and that fixed our issue also.
So all is fine now, no need to reinstall, etc.
Thanks for all the help!
Thanks for letting us know @renegeelen !
We will be marking this ticket a resolved now, feel free to reach out again if you need any assistance.
Kind regards,
MarijaThere were no fatal errors yesterday – but today they are back and now referring to line 647 instead of 646:
Uncaught Error: Call to a member function get_id() on null in /home/dynamitem/public_html/wp-content/plugins/official-facebook-pixel/integration/class-facebookwordpresswoocommerce.php:647
Aanvullende context
{
"error": {
"type": 1,
"file": "/home/dynamitem/public_html/wp-content/plugins/official-facebook-pixel/integration/class-facebookwordpresswoocommerce.php",
"line": 647
},
"remote-logging": true,
"backtrace": [
"",
"#0 /home/dynamitem/public_html/wp-content/plugins/official-facebook-pixel/integration/class-facebookwordpresswoocommerce.php(427): FacebookPixelPlugin\Integration\FacebookWordpressWooCommerce::getProductId()",
"#1 [internal function]: FacebookPixelPlugin\Integration\FacebookWordpressWooCommerce::createAddToCartEvent()",
"#2 /home/dynamitem/public_html/wp-content/plugins/official-facebook-pixel/core/class-servereventfactory.php(306): call_user_func_array()",
"#3 /home/dynamitem/public_html/wp-content/plugins/official-facebook-pixel/integration/class-facebookwordpresswoocommerce.php(347): FacebookPixelPlugin\Core\ServerEventFactory::safe_create_event()",
"#4 /home/dynamitem/public_html/wp-includes/class-wp-hook.php(326): FacebookPixelPlugin\Integration\FacebookWordpressWooCommerce::trackAddToCartEvent()",
"#5 /home/dynamitem/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()",
"#6 /home/dynamitem/public_html/wp-includes/plugin.php(517): WP_Hook->do_action()",
"#7 /home/dynamitem/public_html/wp-content/plugins/woocommerce/includes/class-wc-cart.php(1317): do_action()",
"#8 /home/dynamitem/public_html/wp-content/plugins/woocommerce/includes/class-wc-form-handler.php(871): WC_Cart->add_to_cart()",
"#9 /home/dynamitem/public_html/wp-content/plugins/woocommerce/includes/class-wc-form-handler.php(843): WC_Form_Handler::add_to_cart_handler_simple()",
"#10 /home/dynamitem/public_html/wp-includes/class-wp-hook.php(324): WC_Form_Handler::add_to_cart_action()",
"#11 /home/dynamitem/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()",
"#12 /home/dynamitem/public_html/wp-includes/plugin.php(517): WP_Hook->do_action()",
"#13 /home/dynamitem/public_html/wp-settings.php(749): do_action()",
"#14 /home/dynamitem/public_html/wp-config.php(116): require_once('/home/dynamitem...')",
"#15 /home/dynamitem/public_html/wp-load.php(50): require_once('/home/dynamitem...')",
"#16 /home/dynamitem/public_html/wp-blog-header.php(13): require_once('/home/dynamitem...')",
"#17 /home/dynamitem/public_html/index.php(17): require('/home/dynamitem...')",
"#18 {main}",
"thrown"
]
}Hi @renegeelen ,
Do you know if there is any custom code to allow updating/publishing a product without a category, as the “Uncategorized” category should be selected by default – ie, a product should always have a category name?
In any case, the Dev has been notified of the issue and is working on a fix, and we will let you know as soon as it is available.
Kind regards,
MarijaHello @marijastuntcoders
All my products are in categories, we have had that we forgot to attach a category to a product once or twice, that product ended up in the “uncategorized” category. After adding a category that was empty again.
So I don’t know of any custom coding…
-
This reply was modified 11 months, 2 weeks ago by
renegeelen.
@marijastuntcoders – as my site generates much less orders the last days / weeks which is quite worrying, can something like these errors cause that? Test orders that I try to do myself work fine but there has to be something that causes this to happen.
The errors were caused on the 13th of June like 10 times but none on the 14th of June. I don’t understand what is happening…..
The company that does my marketing has installed this app a long time ago. If I “deactivate” this for the time being (untill there is an update), will it not harm woocommerce in working and should the error logs no longer be generated? After an update I can activate it again and it should work again?
Thanks for your help in advance!
Hi @renegeelen
There is a console error on your site indicating that the Pixel ID is duplicated.
Is your website using any other plugins, custom code, or integrations to connect the Pixel (other than the Meta Pixel for WordPress plugin)? If so, please remove them and reinstall/reconnect the Pixel to your site again.
This error is unlikely to cause slower traffic/ordering on your website, as the site is working properly, and the test orders you created went through without issue.
Deactivating the plugin should get rid of the error, and the rest of your WooCommerce shop won’t be affected, but keep in mind that you will no longer be able to run Ads and track events.
Kind regards,
MarijaHi, it looks like this still isn’t resolved? You all pushed a new version that said it fixed this issue, but the code suggestion that @cornershop provided didn’t seem to make it into the new version.
Hi @marijastuntcoders ,
The wordpress function get_the_terms return false if no categories are found after the applied filter get_the_terms. So the final code of FacebookWordpressWooCommerce->getProductCategory( $product_id ) should be:
private static function getProductCategory( $product_id ) {
$categories = get_the_terms(
$product_id,
'product_cat'
);
return is_array($categories) && count( $categories ) > 0 ? $categories[0]->name : null;
}$categories inside count function must be a countable.
Hi @jakeypeester — if you are still having issues, please open a new thread on the forum so we can assist you further.
@pedrocordeiro — thanks for sharing the snippet, can you share it on the GitHub issues page as well, so that the Dev team can take it into consideration?
Kind regards,
Marija -
This reply was modified 11 months, 2 weeks ago by
The topic ‘CRITICAL : Uncaught Error’ is closed to new replies.