-
Notifications
You must be signed in to change notification settings - Fork 330
Description
Bug Description
There have been a couple of reports of fatal errors from WooCommerce users, with errors indicating a possible enhanced conversion tracking conflict.
Errors include the below (full errors lower down):
- Report 1:
PHP Fatal error: Uncaught Error: Call to a member function is_type() on string in/home/customer/www/[domain.com/public_html/wp-content/plugins/google-site-kit/includes/Core/Conversion_Tracking/Conversion_Event_Providers/WooCommerce.php:202](http://domain.com/public_html/wp-content/plugins/google-site-kit/includes/Core/Conversion_Tracking/Conversion_Event_Providers/WooCommerce.php:202) - Report 2:
PHP Fatal error: Uncaught Error: Call to a member function is_type() on string
Support topics and additional info:
- Report 1 | Support topic | SH info
- Report 2 | Support topic | SH info
Stack trace for report 1
[30-May-2025 18:23:30 UTC] PHP Fatal error: Uncaught Error: Call to a member function is_type() on string in /home/customer/www/domain.com/public_html/wp-content/plugins/google-site-kit/includes/Core/Conversion_Tracking/Conversion_Event_Providers/WooCommerce.php:202
Stack trace:
#0 /home/customer/www/domain.com/public_html/wp-content/plugins/google-site-kit/includes/Core/Conversion_Tracking/Conversion_Event_Providers/WooCommerce.php(100): Google\Site_Kit\Core\Conversion_Tracking\Conversion_Event_Providers\WooCommerce->get_formatted_product('')
#1 /home/customer/www/domain.com/public_html/wp-includes/class-wp-hook.php(326): Google\Site_Kit\Core\Conversion_Tracking\Conversion_Event_Providers\WooCommerce->Google\Site_Kit\Core\Conversion_Tracking\Conversion_Event_Providers\{closure}('<a href="https:...', '')
#2 /home/customer/www/domain.com/public_html/wp-includes/plugin.php(205): WP_Hook->apply_filters('<a href="https:...', Array)
#3 /home/customer/www/domain.com/public_html/wp-content/plugins/woo-parts-filter/include/mmy_metabox.php(87): apply_filters('woocommerce_loo...', '<a href="https:...', '', Array)
#4 /home/customer/www/domain.com/public_html/wp-content/plugins/woo-parts-filter/include/mmy_result_sc.php(101): get_Add_Cart_Link('3262')
#5 /home/customer/www/domain.com/public_html/wp-includes/shortcodes.php(434): mmyresult_html(Array, '', 'mmy_filter_resu...')
#6 [internal function]: do_shortcode_tag(Array)
#7 /home/customer/www/domain.com/public_html/wp-includes/shortcodes.php(273): preg_replace_callback('/\\[(\\[?)(mmy_fi...', 'do_shortcode_ta...', '<div id="wp-blo...')
#8 /home/customer/www/domain.com/public_html/wp-includes/class-wp-hook.php(324): do_shortcode('<div id="wp-blo...')
#9 /home/customer/www/domain.com/public_html/wp-includes/plugin.php(205): WP_Hook->apply_filters('<div id="wp-blo...', Array)
#10 /home/customer/www/domain.com/public_html/wp-includes/post-template.php(256): apply_filters('the_content', '<!-- wp:themeis...')
#11 /home/customer/www/domain.com/public_html/wp-content/themes/neve/inc/views/page_layout.php(29): the_content()
#12 /home/customer/www/domain.com/public_html/wp-includes/class-wp-hook.php(324): Neve\Views\Page_Layout->render_page('')
#13 /home/customer/www/domain.com/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
#14 /home/customer/www/domain.com/public_html/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#15 /home/customer/www/domain.com/public_html/wp-content/themes/neve/template-parts/content-page.php(9): do_action('neve_do_single_...')
#16 /home/customer/www/domain.com/public_html/wp-includes/template.php(812): require('/home/customer/...')
#17 /home/customer/www/domain.com/public_html/wp-includes/template.php(745): load_template('/home/customer/...', false, Array)
#18 /home/customer/www/domain.com/public_html/wp-includes/general-template.php(206): locate_template(Array, true, false, Array)
#19 /home/customer/www/domain.com/public_html/wp-content/themes/neve/page.php(47): get_template_part('template-parts/...', 'page')
#20 /home/customer/www/domain.com/public_html/wp-includes/template-loader.php(106): include('/home/customer/...')
#21 /home/customer/www/domain.com/public_html/wp-blog-header.php(19): require_once('/home/customer/...')
#22 /home/customer/www/domain.com/public_html/index.php(17): require('/home/customer/...')
#23 {main}
thrown in /home/customer/www/domain.com/public_html/wp-content/plugins/google-site-kit/includes/Core/Conversion_Tracking/Conversion_Event_Providers/WooCommerce.php on line 202
Error log for report 2
`Fatal error: Uncaught Error: Call to a member function is_type() on bool in /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-content/plugins/google-site-kit/includes/Core/Conversion_Tracking/Conversion_Event_Providers/WooCommerce.php:256 Stack trace: #0 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-content/plugins/google-site-kit/includes/Core/Conversion_Tracking/Conversion_Event_Providers/WooCommerce.php(335): Google\Site_Kit\Core\Conversion_Tracking\Conversion_Event_Providers\WooCommerce->get_formatted_product() #1 [internal function]: Google\Site_Kit\Core\Conversion_Tracking\Conversion_Event_Providers\WooCommerce->Google\Site_Kit\Core\Conversion_Tracking\Conversion_Event_Providers\{closure}() #2 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-content/plugins/google-site-kit/includes/Core/Conversion_Tracking/Conversion_Event_Providers/WooCommerce.php(332): array_map() #3 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-content/plugins/google-site-kit/includes/Core/Conversion_Tracking/Conversion_Event_Providers/WooCommerce.php(415): Google\Site_Kit\Core\Conversion_Tracking\Conversion_Event_Providers\WooCommerce->get_formatted_order() #4 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-content/plugins/google-site-kit/includes/Core/Conversion_Tracking/Conversion_Event_Providers/WooCommerce.php(207): Google\Site_Kit\Core\Conversion_Tracking\Conversion_Event_Providers\WooCommerce->maybe_add_purchase_inline_script() #5 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-includes/class-wp-hook.php(324): Google\Site_Kit\Core\Conversion_Tracking\Conversion_Event_Providers\WooCommerce->Google\Site_Kit\Core\Conversion_Tracking\Conversion_Event_Providers\{closure}() #6 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters() #7 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-includes/plugin.php(517): WP_Hook->do_action() #8 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-content/plugins/woocommerce/templates/checkout/thankyou.php(82): do_action() #9 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-content/plugins/woocommerce/includes/wc-core-functions.php(346): include('...') #10 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-content/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-checkout.php(336): wc_get_template() #11 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-content/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-checkout.php(66): WC_Shortcode_Checkout::order_received() #12 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-content/plugins/woocommerce/includes/class-wc-shortcodes.php(75): WC_Shortcode_Checkout::output() #13 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-content/plugins/woocommerce/includes/class-wc-shortcodes.php(98): WC_Shortcodes::shortcode_wrapper() #14 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-includes/shortcodes.php(434): WC_Shortcodes::checkout() #15 [internal function]: do_shortcode_tag() #16 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-includes/shortcodes.php(273): preg_replace_callback() #17 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-includes/class-wp-hook.php(324): do_shortcode() #18 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-includes/plugin.php(205): WP_Hook->apply_filters() #19 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-includes/post-template.php(256): apply_filters() #20 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-content/themes/houzez/content-page.php(4): the_content() #21 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-includes/template.php(812): require('...') #22 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-includes/template.php(745): load_template() #23 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-includes/general-template.php(206): locate_template() #24 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-content/themes/houzez/template/template-page.php(61): get_template_part() #25 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-includes/template-loader.php(106): include('...') #26 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-blog-header.php(19): require_once('...') #27 /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/index.php(17): require('...') #28 {main} thrown in /home/647786.cloudwaysapps.com/zaxmuzyddd/public_html/wp-content/plugins/google-site-kit/includes/Core/Conversion_Tracking/Conversion_Event_Providers/WooCommerce.php on line 256`Steps to reproduce
For report 2, the user shared the following steps, however, in test sites the errors was unreproducible so far, likely due to being unable to test the Houez theme:
- Place an order in Houez theme to create a listing using woocommerce to facilitate payments
- View the “Thank you” page (order received)
- Observe the PHP fatal error and site crash
Possible workaround
For report 1, the user mentioned the below:
I fixed just adding these lines at the beginning of get_formatted_product():
$product = wc_get_product( $product );
if ( ! $product || ! $product instanceof WC_Product ) { return; }
Somehow there is no product object.
site-kit-wp/includes/Core/Conversion_Tracking/Conversion_Event_Providers/WooCommerce.php
Line 255 in 73c19d3
| public function get_formatted_product( $product, $variation_id = 0, $variation = false, $quantity = false ) { |
Additional Context
- For report 1, there is an error appearing from a commercial plugin, WooCommerce Car/Parts Filter Plugin. I haven't been able to test this so far.
- Without using the above plugin, or the commercial theme and plugin mentioned in report 2 (Houzez theme with paid listing submissions via woocommerce), we've been unable to recreate any such issue for any support sites.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- Within WooCommerce conversion tracking, formatted product data should only be obtained for a valid product received via WooCommerce hooks or filters.
- The reported error should no longer occur due to a missing product or one of the incorrect types.
Implementation Brief
- In
includes/Core/Conversion_Tracking/Conversion_Event_Providers/WooCommerce.php:- Update the
get_formatted_productmethod:- Convert it to a
protectedmethod. - Add a type for the accepted
$productparameter ofWC_Product.
- Convert it to a
- Update the
register_hooksmethod:- In the action and filter callback functions, at first verify if the accepted/formed product is an instance of
WC_Product, and bail early if otherwise.
- In the action and filter callback functions, at first verify if the accepted/formed product is an instance of
- Update the
get_formatted_ordermethod:- When iterating through the order items to form the
itemsarray, firstly check if$item->get_product()is an instance ofWC_Product, and bail early if otherwise.
- When iterating through the order items to form the
- Update the
Test Coverage
- In
tests/phpunit/integration/Core/Conversion_Tracking/Conversion_Event_Providers/WooCommerceTest.php:- Add basic test coverage for the
get_formatted_ordermethod by passing a WooCommerce order that contains an invalid product and ensure that it is not included or processed in the resulting formatted array.
- Add basic test coverage for the
QA Brief
- Install either the "Houzez theme with paid listing submissions via woocommerce" or the woocommerce-carparts-filter-plugin mentioned in the issue summary/steps-to-reproduce
- Add WooCommerce products
- Set up Enhanced Conversion Tracking for WooCommerce products in Site Kit
- Add products to cart as an anonymous user
- No errors should appear on the frontend of the site
Changelog entry
- Fix enhanced conversion tracking fatal errors.