Automattic\WooCommerce\Blocks\Utils
BlockTemplateUtils::set_has_theme_file_if_fallback_is_available()
Sets the has_theme_file to true for templates with fallbacks
There are cases (such as tags, categories and attributes) in which fallback templates can be used; so, while technically the theme doesn't have a specific file for them, it is important that we tell Gutenberg that we do, in fact, have a theme file (i.e. the fallback one).
Note: this function changes the array that has been passed.
It returns true if anything was changed, false otherwise.
Method of the class: BlockTemplateUtils{}
No Hooks.
Return
true|false
.
Usage
$result = BlockTemplateUtils::set_has_theme_file_if_fallback_is_available( $query_result, $template );
- $query_result(array) (required)
- Array of template objects.
- $template(object) (required)
- A specific template object which could have a fallback.
BlockTemplateUtils::set_has_theme_file_if_fallback_is_available() BlockTemplateUtils::set has theme file if fallback is available code WC 9.4.2
public static function set_has_theme_file_if_fallback_is_available( $query_result, $template ) { foreach ( $query_result as &$query_result_template ) { if ( $query_result_template->slug === $template->slug && $query_result_template->theme === $template->theme ) { if ( self::template_is_eligible_for_fallback_from_theme( $template->slug ) ) { $query_result_template->has_theme_file = true; } return true; } } return false; }