WC_Template_Loader::template_loader()public staticWC 1.0

Load a template.

Handles template usage so that we can use our own templates instead of the theme's.

Templates are in the 'templates' folder. WooCommerce looks for theme overrides in /theme/woocommerce/ by default.

For beginners, it also looks for a woocommerce.php template first. If the user adds this to the theme (containing a woocommerce() inside) this will be used for all WooCommerce templates.

Method of the class: WC_Template_Loader{}

No Hooks.

Return

String.

Usage

$result = WC_Template_Loader::template_loader( $template );
$template(string) (required)
Template to load.

WC_Template_Loader::template_loader() code WC 8.6.1

public static function template_loader( $template ) {
	if ( is_embed() ) {
		return $template;
	}

	$default_file = self::get_template_loader_default_file();

	if ( $default_file ) {
		/**
		 * Filter hook to choose which files to find before WooCommerce does it's own logic.
		 *
		 * @since 3.0.0
		 * @var array
		 */
		$search_files = self::get_template_loader_files( $default_file );
		$template     = locate_template( $search_files );

		if ( ! $template || WC_TEMPLATE_DEBUG_MODE ) {
			if ( false !== strpos( $default_file, 'product_cat' ) || false !== strpos( $default_file, 'product_tag' ) ) {
				$cs_template = str_replace( '_', '-', $default_file );
				$template    = WC()->plugin_path() . '/templates/' . $cs_template;
			} else {
				$template = WC()->plugin_path() . '/templates/' . $default_file;
			}
		}
	}

	return $template;
}