Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WooCommerce Analytics: better fallback when conflicting with plugins changing product data #11301

Closed
jeherve opened this issue Feb 7, 2019 · 5 comments · Fixed by #30712
Closed
Assignees
Labels
[Feature] WooCommerce Analytics [Pri] Normal [Status] In Progress [Type] Bug When a feature is broken and / or not performing as intended

Comments

@jeherve
Copy link
Member

jeherve commented Feb 7, 2019

Steps to reproduce the issue

  1. Some plugins change the data returned by wc_get_product.
  2. It then causes Fatal Errors on our end, like so:
PHP Fatal error:  Uncaught Error: Call to undefined method WC_Product_Package::get_title() in /plugins/jetpack/7.0/modules/woocommerce-analytics/classes/wp-woocommerce-analytics-universal.php:172
Stack trace:
#0 /plugins/jetpack/7.0/modules/woocommerce-analytics/classes/wp-woocommerce-analytics-universal.php(90): Jetpack_WooCommerce_Analytics_Universal->get_product_details(Object(WC_Product_Package))
#1 /wp-includes/class-wp-hook.php(286): Jetpack_WooCommerce_Analytics_Universal->loop_session_events('')

We should aim to have a better fallback than this fatal in get_product_details.

@jeherve jeherve added [Type] Bug When a feature is broken and / or not performing as intended [Feature] WooCommerce Analytics [Pri] Low labels Feb 7, 2019
@kriskarkoski
Copy link

#10216325-hc

@stale
Copy link

stale bot commented Aug 7, 2019

This issue has been marked as stale. This happened because:

  • It has been inactive in the past 6 months.
  • It hasn’t been labeled `[Pri] Blocker`, `[Pri] High`.

No further action is needed. But it's worth checking if this ticket has clear reproduction steps and it is still reproducible. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation.

@stale stale bot added the [Status] Stale label Aug 7, 2019
@jeherve
Copy link
Member Author

jeherve commented Aug 19, 2021

This was also brought up in #20743, and is apparently caused by Elementor Pro:

CRITICAL Uncaught Error: Call to a member function get_id() on null in /nas/content/live/strymon/wp-content/plugins/jetpack/modules/woocommerce-analytics/classes/class-jetpack-woocommerce-analytics-universal.php:242
Stack trace:
#0 /nas/content/live/strymon/wp-includes/class-wp-hook.php(303): Jetpack_WooCommerce_Analytics_Universal->capture_product_view('')
#1 /nas/content/live/strymon/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters('', Array)
#2 /nas/content/live/strymon/wp-includes/plugin.php(470): WP_Hook->do_action(Array)
#3 /nas/content/live/strymon/wp-content/plugins/elementor-pro/modules/woocommerce/documents/product.php(123): do_action('woocommerce_aft...')
#4 /nas/content/live/strymon/wp-content/plugins/elementor-pro/modules/theme-builder/documents/theme-document.php(189): ElementorPro\Modules\Woocommerce\Documents\Product->after_get_content()
#5 /nas/content/live/strymon/wp-content/plugins/elementor-pro/modules/theme-builder/documents/theme-document.php(200): ElementorPro\Modules\ThemeBuilder\Docu in /nas/content/live/strymon/wp-content/plugins/jetpack/modules/woocommerce-analytics/classes/class-jetpack-woocommerce-analytics-universal.php on line 242

@katiebethbrown
Copy link

katiebethbrown commented May 11, 2023

We ran into this today on a T51 partner site that is not running Elementor. Single product pages load for logged in users, but return the fatal when logged out.

Toggling the Jetpack woocommerce-analytics module off resolved.

Active plugins:

+----------------------------+--------+------------------------------+----------+
| name                       | status | update                       | version  |
+----------------------------+--------+------------------------------+----------+
| akismet                    | active | none                         | 5.1      |
| gutenberg                  | active | none                         | 15.7.1   |
| jetpack                    | active | version higher than expected | 12.2-a.5 |
| layout-grid                | active | none                         | 1.8.2    |
| page-optimize              | active | none                         | 0.5.3    |
| woocommerce                | active | none                         | 7.7.0    |
| woocommerce-product-addons | active | none                         | 6.2.0    |
| woocommerce-services       | active | none                         | 2.2.4    |
| full-site-editing          | active | none                         | 3.65244  |
+----------------------------+--------+------------------------------+----------+
[11-May-2023 23:26:28 UTC] PHP Fatal error:  Uncaught Error: Call to a member function get_id()on string in /wordpress/plugins/jetpack/12.2-a.5/modules/woocommerce-analytics/classes/class-jetpack-woocommerce-analytics-universal.php:264
Stack trace:
#0 /wordpress/core/6.2/wp-includes/class-wp-hook.php(308): Jetpack_WooCommerce_Analytics_Universal->capture_product_view('')
#1 /wordpress/core/6.2/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters('', Array)
#2 /wordpress/core/6.2/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#3 /wordpress/plugins/woocommerce/7.7.0/packages/woocommerce-blocks/src/Templates/AbstractTemplateCompatibility.php(196): do_action('woocommerce_aft...')
#4 /wordpress/plugins/woocommerce/7.7.0/packages/woocommerce-blocks/src/Templates/SingleProductTemplateCompatibility.php(106): Automattic\WooCommerce\Blocks\Templates\AbstractTemplateCompatibility->get_hooks_buffer(Array, 'after')
#5 /wordpress/plugins/woocommerce/7.7.0/packages/woocommerce-blocks/src/Templates/SingleProductTemplateCompatibility.php(39): Automattic\WooCommerce\Blocks\Templates\SingleProductTemplateCompatibility->inject_hook_to_first_and_last_blocks('\n\t\t\t\t<div class...', Array, Array)
#6 /wordpress/plugins/woocommerce/7.7.0/packages/woocommerce-blocks/src/Templates/AbstractTemplateCompatibility.php(71): Automattic\WooCommerce\Blocks\Templates\SingleProductTemplateCompatibility->inject_hooks('\n\t\t\t\t<div class...', Array)
#7 /wordpress/core/6.2/wp-includes/class-wp-hook.php(310): Automattic\WooCommerce\Blocks\Templates\AbstractTemplateCompatibility->Automattic\WooCommerce\Blocks\Templates\{closure}('\n\t\t\t\t<div class...', Array)
#8 /wordpress/core/6.2/wp-includes/plugin.php(205): WP_Hook->apply_filters('\n\t\t\t\t<div class...', Array)
#9 /wordpress/core/6.2/wp-includes/class-wp-block.php(293): apply_filters('render_block', '\n\t\t\t\t<div class...', Array, Object(WP_Block))
#10 /wordpress/core/6.2/wp-includes/blocks.php(1051): WP_Block->render()
#11 /wordpress/core/6.2/wp-includes/blocks.php(1089): render_block(Array)
#12 /wordpress/core/6.2/wp-includes/block-template.php(240): do_blocks('<!-- wp:templat...')
#13 /wordpress/core/6.2/wp-includes/template-canvas.php(12): get_the_block_template_html()
#14 /wordpress/core/6.2/wp-includes/template-loader.php(106): include('/wordpress/core...')
#15 /wordpress/core/6.2/wp-blog-header.php(19): require_once('/wordpress/core...')
#16 /wordpress/core/6.2/index.php(17): require('/wordpress/core...')
#17 {main}
  thrown in /wordpress/plugins/jetpack/12.2-a.5/modules/woocommerce-analytics/classes/class-jetpack-woocommerce-analytics-universal.php on line 264

Edit: This appears to be caused by the WooCommerce Single Product block accessing global $product and then overwriting it.

jeherve added a commit that referenced this issue May 15, 2023
Fixes #11301

Some plugins make changes to Products and Orders, overwriting methods that we call in Jetpack. Let's check for such methods before we use them on our end, to avoid issues.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] WooCommerce Analytics [Pri] Normal [Status] In Progress [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants