these are customised templates that are loaded from the database. * @param string $template_type wp_template or wp_template_part. * * @return array Templates from the WooCommerce blocks plugin directory. */ public function get_block_templates_from_woocommerce( $slugs, $already_found_templates, $template_type = 'wp_template' ) { $directory = BlockTemplateUtils::get_templates_directory( $template_type ); $template_files = BlockTemplateUtils::get_template_paths( $directory ); $templates = array(); foreach ( $template_files as $template_file ) { if ( ! $this->package->is_experimental_build() && str_contains( $template_file, 'templates/parts/product-gallery.html' ) ) { break; } // Skip the template if it's blockified, and we should only use classic ones. if ( ! BlockTemplateUtils::should_use_blockified_product_grid_templates() && strpos( $template_file, 'blockified' ) !== false ) { continue; } $template_slug = BlockTemplateUtils::generate_template_slug_from_path( $template_file ); // This template does not have a slug we're looking for. Skip it. if ( is_array( $slugs ) && count( $slugs ) > 0 && ! in_array( $template_slug, $slugs, true ) ) { continue; } // If the theme already has a template, or the template is already in the list (i.e. it came from the // database) then we should not overwrite it with the one from the filesystem. if ( BlockTemplateUtils::theme_has_template( $template_slug ) || count( array_filter( $already_found_templates, function ( $template ) use ( $template_slug ) { $template_obj = (object) $template; //phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found return $template_obj->slug === $template_slug; } ) ) > 0 ) { continue; } if ( BlockTemplateUtils::template_is_eligible_for_product_archive_fallback_from_db( $template_slug, $already_found_templates ) ) { $template = clone BlockTemplateUtils::get_fallback_template_from_db( $template_slug, $already_found_templates ); $template_id = explode( '//', $template->id ); $template->id = $template_id[0] . '//' . $template_slug; $template->slug = $template_slug; $template->title = BlockTemplateUtils::get_block_template_title( $template_slug ); $template->description = BlockTemplateUtils::get_block_template_description( $template_slug ); $templates[] = $template; continue; } // If the theme has an archive-product.html template, but not a taxonomy-product_cat/tag/attribute.html template let's use the themes archive-product.html template. if ( BlockTemplateUtils::template_is_eligible_for_product_archive_fallback_from_theme( $template_slug ) ) { $template_file = BlockTemplateUtils::get_theme_template_path( 'archive-product' ); $templates[] = BlockTemplateUtils::create_new_block_template_object( $template_file, $template_type, $template_slug, true ); continue; } // At this point the template only exists in the Blocks filesystem, if is a taxonomy-product_cat/tag/attribute.html template // let's use the archive-product.html template from Blocks. if ( BlockTemplateUtils::template_is_eligible_for_product_archive_fallback( $template_slug ) ) { $template_file = $this->get_template_path_from_woocommerce( 'archive-product' ); $templates[] = BlockTemplateUtils::create_new_block_template_object( $template_file, $template_type, $template_slug, false ); continue; } // At this point the template only exists in the Blocks filesystem and has not been saved in the DB, // or superseded by the theme. $templates[] = BlockTemplateUtils::create_new_block_template_object( $template_file, $template_type, $template_slug ); } return $templates; } /** * Get and build the block template objects from the block template files. * * @param array $slugs An array of slugs to retrieve templates for. * @param string $template_type wp_template or wp_template_part. * * @return array WP_Block_Template[] An array of block template objects. */ public function get_block_templates( $slugs = array(), $template_type = 'wp_template' ) { $templates_from_db = BlockTemplateUtils::get_block_templates_from_db( $slugs, $template_type ); $templates_from_woo = $this->get_block_templates_from_woocommerce( $slugs, $templates_from_db, $template_type ); $templates = array_merge( $templates_from_db, $templates_from_woo ); return BlockTemplateUtils::filter_block_templates_by_feature_flag( $templates ); } /** * Returns the path of a template on the Blocks template folder. * * @param string $template_slug Block template slug e.g. single-product. * @param string $template_type wp_template or wp_template_part. * * @return string */ public function get_template_path_from_woocommerce( $template_slug, $template_type = 'wp_template' ) { return BlockTemplateUtils::get_templates_directory( $template_type ) . '/' . $template_slug . '.html'; } /** * Checks whether a block template with that name exists in Woo Blocks * * @param string $template_name Template to check. * @param array $template_type wp_template or wp_template_part. * * @return boolean */ public function block_template_is_available( $template_name, $template_type = 'wp_template' ) { if ( ! $template_name ) { return false; } $directory = BlockTemplateUtils::get_templates_directory( $template_type ) . '/' . $template_name . '.html'; return is_readable( $directory ) || $this->get_block_templates( array( $template_name ), $template_type ); } /** * Renders the default block template from Woo Blocks if no theme templates exist. */ public function render_block_template() { if ( is_embed() || ! BlockTemplateUtils::supports_block_templates() ) { return; } if ( is_singular( 'product' ) && $this->block_template_is_available( 'single-product' ) ) { global $post; $valid_slugs = [ 'single-product' ]; if ( 'product' === $post->post_type && $post->post_name ) { $valid_slugs[] = 'single-product-' . $post->post_name; } $templates = get_block_templates( array( 'slug__in' => $valid_slugs ) ); if ( isset( $templates[0] ) && BlockTemplateUtils::template_has_legacy_template_block( $templates[0] ) ) { add_filter( 'woocommerce_disable_compatibility_layer', '__return_true' ); } if ( ! BlockTemplateUtils::theme_has_template( 'single-product' ) ) { add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 ); } } elseif ( ( is_product_taxonomy() && is_tax( 'product_cat' ) ) && $this->block_template_is_available( 'taxonomy-product_cat' ) ) { $templates = get_block_templates( array( 'slug__in' => array( 'taxonomy-product_cat' ) ) ); if ( isset( $templates[0] ) && BlockTemplateUtils::template_has_legacy_template_block( $templates[0] ) ) { add_filter( 'woocommerce_disable_compatibility_layer', '__return_true' ); } if ( ! BlockTemplateUtils::theme_has_template( 'taxonomy-product_cat' ) ) { add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 ); } } elseif ( ( is_product_taxonomy() && is_tax( 'product_tag' ) ) && $this->block_template_is_available( 'taxonomy-product_tag' ) ) { $templates = get_block_templates( array( 'slug__in' => array( 'taxonomy-product_tag' ) ) ); if ( isset( $templates[0] ) && BlockTemplateUtils::template_has_legacy_template_block( $templates[0] ) ) { add_filter( 'woocommerce_disable_compatibility_layer', '__return_true' ); } if ( ! BlockTemplateUtils::theme_has_template( 'taxonomy-product_tag' ) ) { add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 ); } } elseif ( is_post_type_archive( 'product' ) && is_search() ) { $templates = get_block_templates( array( 'slug__in' => array( ProductSearchResultsTemplate::SLUG ) ) ); if ( isset( $templates[0] ) && BlockTemplateUtils::template_has_legacy_template_block( $templates[0] ) ) { add_filter( 'woocommerce_disable_compatibility_layer', '__return_true' ); } if ( ! BlockTemplateUtils::theme_has_template( ProductSearchResultsTemplate::SLUG ) ) { add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 ); } } elseif ( ( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) && $this->block_template_is_available( 'archive-product' ) ) { $templates = get_block_templates( array( 'slug__in' => array( 'archive-product' ) ) ); if ( isset( $templates[0] ) && BlockTemplateUtils::template_has_legacy_template_block( $templates[0] ) ) { add_filter( 'woocommerce_disable_compatibility_layer', '__return_true' ); } if ( ! BlockTemplateUtils::theme_has_template( 'archive-product' ) ) { add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 ); } } elseif ( is_cart() && ! BlockTemplateUtils::theme_has_template( CartTemplate::get_slug() ) && $this->block_template_is_available( CartTemplate::get_slug() ) ) { add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 ); } elseif ( is_checkout() && ! BlockTemplateUtils::theme_has_template( CheckoutTemplate::get_slug() ) && $this->block_template_is_available( CheckoutTemplate::get_slug() ) ) { add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 ); } else { $queried_object = get_queried_object(); if ( is_null( $queried_object ) ) { return; } if ( isset( $queried_object->taxonomy ) && taxonomy_is_product_attribute( $queried_object->taxonomy ) && $this->block_template_is_available( ProductAttributeTemplate::SLUG ) ) { $templates = get_block_templates( array( 'slug__in' => array( ProductAttributeTemplate::SLUG ) ) ); if ( isset( $templates[0] ) && BlockTemplateUtils::template_has_legacy_template_block( $templates[0] ) ) { add_filter( 'woocommerce_disable_compatibility_layer', '__return_true' ); } if ( ! BlockTemplateUtils::theme_has_template( ProductAttributeTemplate::SLUG ) ) { add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 ); } } } } /** * Remove the template panel from the Sidebar of the Shop page because * the Site Editor handles it. * * @see https://github.com/woocommerce/woocommerce-gutenberg-products-block/issues/6278 * * @param bool $is_support Whether the active theme supports block templates. * * @return bool */ public function remove_block_template_support_for_shop_page( $is_support ) { global $pagenow, $post; if ( is_admin() && 'post.php' === $pagenow && function_exists( 'wc_get_page_id' ) && is_a( $post, 'WP_Post' ) && wc_get_page_id( 'shop' ) === $post->ID ) { return false; } return $is_support; } /** * Update the product archive title to "Shop". * * @param string $post_type_name Post type 'name' label. * @param string $post_type Post type. * * @return string */ public function update_product_archive_title( $post_type_name, $post_type ) { if ( function_exists( 'is_shop' ) && is_shop() && 'product' === $post_type ) { return __( 'Shop', 'woocommerce' ); } return $post_type_name; } /** * Migrates page content to templates if needed. */ public function maybe_migrate_content() { // Migration should occur on a normal request to ensure every requirement is met. // We are postponing it if WP is in maintenance mode, installing, WC installing or if the request is part of a WP-CLI command. if ( wp_is_maintenance_mode() || ! get_option( 'woocommerce_db_version', false ) || Constants::is_defined( 'WP_SETUP_CONFIG' ) || Constants::is_defined( 'WC_INSTALLING' ) || Constants::is_defined( 'WP_CLI' ) ) { return; } if ( ! BlockTemplateMigrationUtils::has_migrated_page( 'cart' ) ) { BlockTemplateMigrationUtils::migrate_page( 'cart' ); } if ( ! BlockTemplateMigrationUtils::has_migrated_page( 'checkout' ) ) { BlockTemplateMigrationUtils::migrate_page( 'checkout' ); } } }
Fatal error: Uncaught Error: Class 'Automattic\WooCommerce\Blocks\BlockTemplatesController' not found in /home/arasetne/public_html/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/Domain/Bootstrap.php:289 Stack trace: #0 /home/arasetne/public_html/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/Registry/AbstractDependencyType.php(42): Automattic\WooCommerce\Blocks\Domain\Bootstrap->Automattic\WooCommerce\Blocks\Domain\{closure}(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #1 /home/arasetne/public_html/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/Registry/SharedType.php(28): Automattic\WooCommerce\Blocks\Registry\AbstractDependencyType->resolve_value(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #2 /home/arasetne/public_html/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/Registry/Container.php(96): Automattic\WooCommerce\Blocks\Registry\SharedType->get(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #3 /home/arasetne/public_h in /home/arasetne/public_html/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/Domain/Bootstrap.php on line 289