Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Single Product Block Causing Fatal Error on Product Pages For Logged Out Users When Jetpack woocommerce-analytics Module is Active #9453

Closed
@katiebethbrown

Description

@katiebethbrown

Describe the bug

When using the Single Product Block, single product pages return a fatal error for logged out users when the Jetpack woocommerce-analytics module is active.

To reproduce

Steps to reproduce the behavior:

  1. Enable the WooCommerce Analytics Jetpack module.
  2. Use the single product block on the single product template.
  3. Create a product.
  4. Visit the product page on the front end when logged out.
  5. See fatal error.

Expected behavior

For the single product page to load for logged out users.

Error

[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

Environment

WordPress (please complete the following information):

  • WordPress version: 6.2
  • Gutenberg version (if installed): 15.7.1
  • WooCommerce version: 7.7.0
  • WooCommerce Blocks version: 10.2.0
  • Site language: English
  • Any other plugins installed: WordPress.com eCommerce plan managed plugins
  • Jetpack version: 12.2-a.5

Additional context

We're running into this on a Team51 partner site. Per the dev:

The problem is the plugin woo-gutenberg-products-block at woo-gutenberg-products-block/src/BlockTypes/AddToCartForm.php Line 52

The function access global $product

protected function render( $attributes, $content, $block ) {
global $product;

Then overwrites it

/**
* Trigger the single product add to cart action for each product type.
*
* @since 9.7.0
*/
do_action( 'woocommerce_' . $product->get_type() . '_add_to_cart' );
$product = ob_get_clean();
if ( ! $product ) {
return '';
}

Related issue in the JP repo:
Automattic/jetpack#11301 (comment)

Metadata

Metadata

Assignees

Labels

block: single productIssues related to the single product block.priority: highThe issue/PR is high priority—it affects lots of customers substantially, but not critically.type: bugThe issue/PR concerns a confirmed bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions