Automattic\WooCommerce\Blocks\BlockTypes
MiniCart::get_template_part_contents
Get the mini cart template part contents to render inside the drawer.
Method of the class: MiniCart{}
No Hooks.
Returns
String. The contents of the template part.
Usage
// protected - for code of main (parent) or child class $result = $this->get_template_part_contents( $do_blocks );
- $do_blocks(true|false)
- Whether to apply do_blocks() to the template part contents.
Default:true
MiniCart::get_template_part_contents() MiniCart::get template part contents code WC 10.7.0
protected function get_template_part_contents( $do_blocks = true ) {
$template_name = 'mini-cart';
$template_part_contents = '';
// Determine if we need to load the template part from the DB, the theme or WooCommerce in that order.
$templates_from_db = BlockTemplateUtils::get_block_templates_from_db( array( $template_name ), 'wp_template_part' );
if ( is_countable( $templates_from_db ) && count( $templates_from_db ) > 0 ) {
$template_slug_to_load = $templates_from_db[0]->theme;
} else {
$theme_has_mini_cart = BlockTemplateUtils::theme_has_template_part( $template_name );
$template_slug_to_load = $theme_has_mini_cart ? get_stylesheet() : BlockTemplateUtils::PLUGIN_SLUG;
}
$template_part = get_block_template( $template_slug_to_load . '//' . $template_name, 'wp_template_part' );
if ( $template_part && ! empty( $template_part->content ) ) {
if ( $do_blocks ) {
$template_part_contents = do_blocks( $template_part->content );
} else {
$template_part_contents = $template_part->content;
}
}
if ( '' === $template_part_contents ) {
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
$file_contents = file_get_contents( Package::get_path() . 'templates/' . BlockTemplateUtils::DIRECTORY_NAMES['TEMPLATE_PARTS'] . '/' . $template_name . '.html' );
if ( $do_blocks ) {
$template_part_contents = do_blocks(
$file_contents
);
} else {
$template_part_contents = $file_contents;
}
}
return $template_part_contents;
}