is also * contains hooked functions that will be removed by remove_default_hooks. * * The array format: * [ * => [ * block_name => , * position => before|after, * hooked => [ * => , * ... * ], * permanently_removed_actions => [ * * ] * ], * ] * Where: * - hook-name is the name of the hook that will be replaced. * - block-name is the name of the block that will replace the hook. * - position is the position of the block relative to the hook. * - hooked is an array of functions hooked to the hook that will be * replaced. The key is the function name and the value is the * priority. * - permanently_removed_actions is an array of functions that we do not want to re-add after they have been removed to avoid duplicate content with the Products block and its inner blocks. */ protected function set_hook_data() { $this->hook_data = array( 'woocommerce_before_main_content' => array( 'block_names' => array( 'core/query', 'woocommerce/product-collection' ), 'position' => 'before', 'hooked' => array( 'woocommerce_output_content_wrapper' => 10, 'woocommerce_breadcrumb' => 20, ), ), 'woocommerce_after_main_content' => array( 'block_names' => array( 'core/query', 'woocommerce/product-collection' ), 'position' => 'after', 'hooked' => array( 'woocommerce_output_content_wrapper_end' => 10, ), ), 'woocommerce_before_shop_loop_item_title' => array( 'block_names' => array( 'core/post-title' ), 'position' => 'before', 'hooked' => array( 'woocommerce_show_product_loop_sale_flash' => 10, 'woocommerce_template_loop_product_thumbnail' => 10, ), ), 'woocommerce_shop_loop_item_title' => array( 'block_names' => array( 'core/post-title' ), 'position' => 'after', 'hooked' => array( 'woocommerce_template_loop_product_title' => 10, ), ), 'woocommerce_after_shop_loop_item_title' => array( 'block_names' => array( 'core/post-title' ), 'position' => 'after', 'hooked' => array( 'woocommerce_template_loop_rating' => 5, 'woocommerce_template_loop_price' => 10, ), ), 'woocommerce_before_shop_loop_item' => array( 'block_names' => array( self::LOOP_ITEM_ID ), 'position' => 'before', 'hooked' => array( 'woocommerce_template_loop_product_link_open' => 10, ), ), 'woocommerce_after_shop_loop_item' => array( 'block_names' => array( self::LOOP_ITEM_ID ), 'position' => 'after', 'hooked' => array( 'woocommerce_template_loop_product_link_close' => 5, 'woocommerce_template_loop_add_to_cart' => 10, ), ), 'woocommerce_before_shop_loop' => array( 'block_names' => array( 'core/post-template', 'woocommerce/product-template' ), 'position' => 'before', 'hooked' => array( 'woocommerce_output_all_notices' => 10, 'woocommerce_result_count' => 20, 'woocommerce_catalog_ordering' => 30, ), 'permanently_removed_actions' => array( 'woocommerce_output_all_notices', 'woocommerce_result_count', 'woocommerce_catalog_ordering', ), ), 'woocommerce_after_shop_loop' => array( 'block_names' => array( 'core/post-template', 'woocommerce/product-template' ), 'position' => 'after', 'hooked' => array( 'woocommerce_pagination' => 10, ), 'permanently_removed_actions' => array( 'woocommerce_pagination', ), ), 'woocommerce_no_products_found' => array( 'block_names' => array( 'core/query-no-results' ), 'position' => 'before', 'hooked' => array( 'wc_no_products_found' => 10, ), 'permanently_removed_actions' => array( 'wc_no_products_found', ), ), 'woocommerce_archive_description' => array( 'block_names' => array( 'core/term-description' ), 'position' => 'before', 'hooked' => array( 'woocommerce_taxonomy_archive_description' => 10, 'woocommerce_product_archive_description' => 10, ), ), ); } /** * Check if current page is a product archive template. */ private function is_archive_template() { return is_shop() || is_product_taxonomy(); } /** * Loop through inner blocks recursively to find the Products blocks that * inherits query from template. * * @param array $block Parsed block data. */ private function inner_blocks_walker( &$block ) { if ( $this->is_products_block_with_inherit_query( $block ) || $this->is_product_collection_block_with_inherit_query( $block ) ) { $this->inject_attribute( $block ); $this->remove_default_hooks(); } if ( ! empty( $block['innerBlocks'] ) ) { array_walk( $block['innerBlocks'], array( $this, 'inner_blocks_walker' ) ); } } /** * Restore default hooks except the ones that are not supposed to be re-added. */ private function restore_default_hooks() { foreach ( $this->hook_data as $hook => $data ) { if ( ! isset( $data['hooked'] ) ) { continue; } foreach ( $data['hooked'] as $callback => $priority ) { if ( ! in_array( $callback, $data['permanently_removed_actions'] ?? array(), true ) ) { add_action( $hook, $callback, $priority ); } } } } /** * Check if block is within the product-query namespace * * @param array $block Parsed block data. */ private function is_block_within_namespace( $block ) { $attributes = $block['attrs']; return isset( $attributes['__woocommerceNamespace'] ) && 'woocommerce/product-query/product-template' === $attributes['__woocommerceNamespace']; } /** * Check if block has isInherited attribute asigned * * @param array $block Parsed block data. */ private function is_block_inherited( $block ) { $attributes = $block['attrs']; $outcome = isset( $attributes['isInherited'] ) && 1 === $attributes['isInherited']; return $outcome; } /** * The core/post-template has two different block names: * - core/post-template when the wrapper is rendered. * - core/null when the loop item is rendered. * * @param array $block Parsed block data. */ private function is_null_post_template( $block ) { $block_name = $block['blockName']; return 'core/null' === $block_name && ( $this->is_block_inherited( $block ) || $this->is_block_within_namespace( $block ) ); } /** * Check if block is a Post template * * @param string $block_name Block name. */ private function is_post_template( $block_name ) { return 'core/post-template' === $block_name; } /** * Check if block is a Product Template * * @param string $block_name Block name. */ private function is_product_template( $block_name ) { return 'woocommerce/product-template' === $block_name; } /** * Check if block is eaither a Post template or Product Template * * @param string $block_name Block name. */ private function is_post_or_product_template( $block_name ) { return $this->is_post_template( $block_name ) || $this->is_product_template( $block_name ); } /** * Check if the block is a Products block that inherits query from template. * * @param array $block Parsed block data. */ private function is_products_block_with_inherit_query( $block ) { return 'core/query' === $block['blockName'] && isset( $block['attrs']['namespace'] ) && 'woocommerce/product-query' === $block['attrs']['namespace'] && isset( $block['attrs']['query']['inherit'] ) && $block['attrs']['query']['inherit']; } /** * Check if the block is a Product Collection block that inherits query from template. * * @param array $block Parsed block data. */ private function is_product_collection_block_with_inherit_query( $block ) { return 'woocommerce/product-collection' === $block['blockName'] && isset( $block['attrs']['query']['inherit'] ) && $block['attrs']['query']['inherit']; } /** * Recursively inject the custom attribute to all nested blocks. * * @param array $block Parsed block data. */ private function inject_attribute( &$block ) { $block['attrs']['isInherited'] = 1; if ( ! empty( $block['innerBlocks'] ) ) { array_walk( $block['innerBlocks'], array( $this, 'inject_attribute' ) ); } } }
Fatal error: Uncaught Error: Class "Automattic\WooCommerce\Blocks\Templates\ArchiveProductTemplatesCompatibility" not found in /htdocs/wp-content/plugins/woocommerce/src/Blocks/Domain/Bootstrap.php:282 Stack trace: #0 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/AbstractDependencyType.php(42): Automattic\WooCommerce\Blocks\Domain\Bootstrap->Automattic\WooCommerce\Blocks\Domain\{closure}(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #1 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/SharedType.php(28): Automattic\WooCommerce\Blocks\Registry\AbstractDependencyType->resolve_value(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #2 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/Container.php(96): Automattic\WooCommerce\Blocks\Registry\SharedType->get(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #3 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Domain/Bootstrap.php(172): Automattic\WooCommerce\Blocks\Registry\Container->get('Automattic\\WooC...') #4 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Domain/Bootstrap.php(86): Automattic\WooCommerce\Blocks\Domain\Bootstrap->init() #5 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Package.php(106): Automattic\WooCommerce\Blocks\Domain\Bootstrap->__construct(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #6 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/AbstractDependencyType.php(42): Automattic\WooCommerce\Blocks\Package::Automattic\WooCommerce\Blocks\{closure}(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #7 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/SharedType.php(28): Automattic\WooCommerce\Blocks\Registry\AbstractDependencyType->resolve_value(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #8 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Registry/Container.php(96): Automattic\WooCommerce\Blocks\Registry\SharedType->get(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #9 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Package.php(44): Automattic\WooCommerce\Blocks\Registry\Container->get('Automattic\\WooC...') #10 [internal function]: Automattic\WooCommerce\Blocks\Package::init() #11 /htdocs/wp-content/plugins/woocommerce/src/Packages.php(128): call_user_func(Array) #12 /htdocs/wp-content/plugins/woocommerce/src/Packages.php(64): Automattic\WooCommerce\Packages::initialize_packages() #13 /htdocs/wp-includes/class-wp-hook.php(324): Automattic\WooCommerce\Packages::on_init('') #14 /htdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #15 /htdocs/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #16 /htdocs/wp-settings.php(555): do_action('plugins_loaded') #17 /htdocs/wp-config.php(104): require_once('/htdocs/wp-sett...') #18 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #19 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #20 /htdocs/index.php(17): require('/htdocs/wp-blog...') #21 {main} thrown in /htdocs/wp-content/plugins/woocommerce/src/Blocks/Domain/Bootstrap.php on line 282