wc_get_template_part( mixed $slug, string $name = '' )
Get template part (for templates like the shop-loop).
Description Description
WC_TEMPLATE_DEBUG_MODE will prevent overrides in themes from taking priority.
Parameters Parameters
- $slug
-
(Required) Template slug.
- $name
-
(Optional) Template name (default: '').
Default value: ''
Source Source
File: includes/wc-core-functions.php
function wc_get_template_part( $slug, $name = '' ) {
$cache_key = sanitize_key( implode( '-', array( 'template-part', $slug, $name, Constants::get_constant( 'WC_VERSION' ) ) ) );
$template = (string) wp_cache_get( $cache_key, 'woocommerce' );
if ( ! $template ) {
if ( $name ) {
$template = WC_TEMPLATE_DEBUG_MODE ? '' : locate_template(
array(
"{$slug}-{$name}.php",
WC()->template_path() . "{$slug}-{$name}.php",
)
);
if ( ! $template ) {
$fallback = WC()->plugin_path() . "/templates/{$slug}-{$name}.php";
$template = file_exists( $fallback ) ? $fallback : '';
}
}
if ( ! $template ) {
// If template file doesn't exist, look in yourtheme/slug.php and yourtheme/woocommerce/slug.php.
$template = WC_TEMPLATE_DEBUG_MODE ? '' : locate_template(
array(
"{$slug}.php",
WC()->template_path() . "{$slug}.php",
)
);
}
// Don't cache the absolute path so that it can be shared between web servers with different paths.
$cache_path = wc_tokenize_path( $template, wc_get_path_define_tokens() );
wc_set_template_cache( $cache_key, $cache_path );
} else {
// Make sure that the absolute path to the template is resolved.
$template = wc_untokenize_path( $template, wc_get_path_define_tokens() );
}
// Allow 3rd party plugins to filter template file from their plugin.
$template = apply_filters( 'wc_get_template_part', $template, $slug, $name );
if ( $template ) {
load_template( $template, false );
}
}