wc_locate_template

Locate a template and return the path for inclusion.

Description

(string) wc_locate_template( (string) $template_name, (string) $template_path = '', (string) $default_path = '' ); 

This is the load order:

yourtheme / $template_path / $template_name yourtheme / $template_name $default_path / $template_name

Returns (string)

Parameters (3)

0. $template_name (string)
The template name.
1. $template_path — Optional. (string) => ''
The template path.
2. $default_path — Optional. (string) => ''
The default path.

Usage

  1. if ( !function_exists( 'wc_locate_template' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-core-functions.php'; 
  3.  
  4. // The template name. 
  5. $template_name = ''; 
  6.  
  7. // The template path. 
  8. $template_path = ''; 
  9.  
  10. // The default path. 
  11. $default_path = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = wc_locate_template($template_name, $template_path, $default_path); 
  15.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-core-functions.php  
  1. function wc_locate_template( $template_name, $template_path = '', $default_path = '' ) { 
  2. if ( ! $template_path ) { 
  3. $template_path = WC()->template_path(); 
  4.  
  5. if ( ! $default_path ) { 
  6. $default_path = WC()->plugin_path() . '/templates/'; 
  7.  
  8. // Look within passed path within the theme - this is priority. 
  9. $template = locate_template( 
  10. array( 
  11. trailingslashit( $template_path ) . $template_name,  
  12. $template_name,  
  13. ); 
  14.  
  15. // Get default template/ 
  16. if ( ! $template || WC_TEMPLATE_DEBUG_MODE ) { 
  17. $template = $default_path . $template_name; 
  18.  
  19. // Return what we found. 
  20. return apply_filters( 'woocommerce_locate_template', $template, $template_name, $template_path );