wc_locate_template()
Locate a template and return the path for inclusion.
This is the load order:
yourtheme/$template_path/$template_name yourtheme/$template_name $default_path/$template_name
Hooks from the function
Returns
String.
Usage
wc_locate_template( $template_name, $template_path, $default_path );
- $template_name(string) (required)
- Template name.
- $template_path(string)
- Template path. .
Default:'' - $default_path(string)
- Default path. .
Default:''
wc_locate_template() wc locate template code WC 10.7.0
function wc_locate_template( $template_name, $template_path = '', $default_path = '' ) {
if ( ! $template_path ) {
$template_path = WC()->template_path();
}
if ( ! $default_path ) {
$default_path = WC()->plugin_path() . '/templates/';
}
// Look within passed path within the theme - this is priority.
if ( false !== strpos( $template_name, 'product_cat' ) || false !== strpos( $template_name, 'product_tag' ) ) {
$cs_template = str_replace( '_', '-', $template_name );
$template = locate_template(
array(
trailingslashit( $template_path ) . $cs_template,
$cs_template,
)
);
}
if ( empty( $template ) ) {
$template = locate_template(
array(
trailingslashit( $template_path ) . $template_name,
$template_name,
)
);
}
// Get default template/.
if ( ! $template || WC_TEMPLATE_DEBUG_MODE ) {
if ( empty( $cs_template ) ) {
$template = $default_path . $template_name;
} else {
$template = $default_path . $cs_template;
}
}
/**
* Filter to customize the path of a given WooCommerce template.
*
* Note: the $default_path argument was added in WooCommerce 9.5.0.
*
* @param string $template Full file path of the template.
* @param string $template_name Template name.
* @param string $template_path Template path.
* @param string $template_path Default WooCommerce templates path.
*
* @since 9.5.0 $default_path argument added.
*/
return apply_filters( 'woocommerce_locate_template', $template, $template_name, $template_path, $default_path );
}