WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

Automattic\WooCommerce\Blocks

BlockTemplatesController::get_block_templates_from_woocommerce() public WC 1.0

Gets the templates from the WooCommerce blocks directory, skipping those for which a template already exists in the theme directory.

{} Это метод класса: BlockTemplatesController{}

Хуков нет.

Возвращает

Массив. Templates from the WooCommerce blocks plugin directory.

Использование

$BlockTemplatesController = new BlockTemplatesController();
$BlockTemplatesController->get_block_templates_from_woocommerce( $slugs, $already_found_templates, $template_type );
$slugs(string[]) (обязательный)
An array of slugs to filter templates by. Templates whose slug does not match will not be returned.
$already_found_templates(массив) (обязательный)
Templates that have already been found, these are customised templates that are loaded from the database.
$template_type(строка)
wp_template or wp_template_part.
По умолчанию: 'wp_template'

Код BlockTemplatesController::get_block_templates_from_woocommerce() WC 6.1.1

public function get_block_templates_from_woocommerce( $slugs, $already_found_templates, $template_type = 'wp_template' ) {
	$directory      = $this->get_templates_directory( $template_type );
	$template_files = BlockTemplateUtils::gutenberg_get_template_paths( $directory );
	$templates      = array();

	if ( 'wp_template_part' === $template_type ) {
		$dir_name = self::TEMPLATE_PARTS_DIR_NAME;
	} else {
		$dir_name = self::TEMPLATES_DIR_NAME;
	}

	foreach ( $template_files as $template_file ) {
		$template_slug = BlockTemplateUtils::generate_template_slug_from_path( $template_file, $dir_name );

		// 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 the theme has an archive-product.html template, but not a taxonomy-product_cat.html template let's use the themes archive-product.html template.
		if ( 'taxonomy-product_cat' === $template_slug && ! BlockTemplateUtils::theme_has_template( 'taxonomy-product_cat' ) && BlockTemplateUtils::theme_has_template( 'archive-product' ) ) {
			$template_file = get_stylesheet_directory() . '/' . self::TEMPLATES_DIR_NAME . '/archive-product.html';
			$templates[]   = BlockTemplateUtils::create_new_block_template_object( $template_file, $template_type, $template_slug, true );
			continue;
		}

		// If the theme has an archive-product.html template, but not a taxonomy-product_tag.html template let's use the themes archive-product.html template.
		if ( 'taxonomy-product_tag' === $template_slug && ! BlockTemplateUtils::theme_has_template( 'taxonomy-product_tag' ) && BlockTemplateUtils::theme_has_template( 'archive-product' ) ) {
			$template_file = get_stylesheet_directory() . '/' . self::TEMPLATES_DIR_NAME . '/archive-product.html';
			$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 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;
}