hrough the `productId` attribute, so even if the * `productId` is passed to the inner block, it will still use the global post. * * @param array $block Block attributes. * @param array $context Block context. */ protected function replace_post_for_single_product_inner_block( $block, &$context ) { if ( $this->single_product_inner_blocks_names ) { $block_name = end( $this->single_product_inner_blocks_names ); if ( $block_name === $block['blockName'] ) { array_pop( $this->single_product_inner_blocks_names ); /** * This is a temporary fix to ensure the Post Title and Excerpt blocks work as expected * until Gutenberg versions 15.2 and 15.6 are included in the core of WordPress. * * Important: the original post data is restored in the restore_global_post method. * * @see https://github.com/WordPress/gutenberg/pull/48001 * @see https://github.com/WordPress/gutenberg/pull/49495 */ if ( 'core/post-excerpt' === $block_name || 'core/post-title' === $block_name ) { global $post; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited $post = get_post( $this->product_id ); if ( $post instanceof \WP_Post ) { setup_postdata( $post ); } } $context['postId'] = $this->product_id; $context['singleProduct'] = true; } } } /** * Render the Single Product block. * * @param array $attributes Block attributes. * @param string $content Block content. * @param WP_Block $block Block instance. * * @return string Rendered block type output. */ protected function render( $attributes, $content, $block ) { $product = wc_get_product( $block->context['postId'] ); if ( ! $product instanceof \WC_Product ) { return ''; } if ( ! $product->is_type( 'variable' ) ) { return parent::render( $attributes, $content, $block ); } $interactivity_context = array( 'productId' => $product->get_id(), 'variationId' => null, ); $html = new \WP_HTML_Tag_Processor( $content ); if ( $html->next_tag( array( 'tag_name' => 'div' ) ) ) { $html->set_attribute( 'data-wp-interactive', $this->get_full_block_name() ); $html->set_attribute( 'data-wp-context', wp_json_encode( $interactivity_context, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP ) ); } $updated_html = $html->get_updated_html(); return parent::render( $attributes, $updated_html, $block ); } /** * Get the frontend script handle for this block type. * * @param string $key Data to get, or default to everything. * * @return null This block has no frontend script. */ protected function get_block_type_script( $key = null ) { return null; } }
Fatal error: Uncaught Error: Class "Automattic\WooCommerce\Blocks\BlockTypes\SingleProduct" not found in /htdocs/surfshop.ma/wp-content/plugins/woocommerce/src/Blocks/BlockTypesController.php:117 Stack trace: #0 /htdocs/surfshop.ma/wp-includes/class-wp-hook.php(324): Automattic\WooCommerce\Blocks\BlockTypesController->register_blocks('') #1 /htdocs/surfshop.ma/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #2 /htdocs/surfshop.ma/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #3 /htdocs/surfshop.ma/wp-settings.php(704): do_action('init') #4 /htdocs/surfshop.ma/wp-config.php(98): require_once('/htdocs/surfsho...') #5 /htdocs/surfshop.ma/wp-load.php(50): require_once('/htdocs/surfsho...') #6 /htdocs/surfshop.ma/wp-blog-header.php(13): require_once('/htdocs/surfsho...') #7 /htdocs/surfshop.ma/index.php(17): require('/htdocs/surfsho...') #8 {main} thrown in /htdocs/surfshop.ma/wp-content/plugins/woocommerce/src/Blocks/BlockTypesController.php on line 117