2013-06-06 12:27:04 +00:00
|
|
|
<?php
|
2013-09-12 13:41:02 +00:00
|
|
|
/**
|
|
|
|
* Template Loader
|
|
|
|
*
|
|
|
|
* @class WC_Template
|
2014-05-28 13:52:50 +00:00
|
|
|
* @version 2.2.0
|
2013-09-12 13:41:02 +00:00
|
|
|
* @package WooCommerce/Classes
|
|
|
|
* @category Class
|
|
|
|
* @author WooThemes
|
|
|
|
*/
|
|
|
|
class WC_Template_Loader {
|
2013-06-06 12:27:04 +00:00
|
|
|
|
2013-09-12 13:41:02 +00:00
|
|
|
/**
|
2014-05-28 13:52:50 +00:00
|
|
|
* Hook in methods
|
2013-09-12 13:41:02 +00:00
|
|
|
*/
|
2014-05-28 13:52:50 +00:00
|
|
|
public static function init() {
|
|
|
|
add_filter( 'template_include', array( __CLASS__, 'template_loader' ) );
|
|
|
|
add_filter( 'comments_template', array( __CLASS__, 'comments_template_loader' ) );
|
2013-06-06 12:27:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a template.
|
|
|
|
*
|
|
|
|
* Handles template usage so that we can use our own templates instead of the themes.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param mixed $template
|
|
|
|
* @return string
|
|
|
|
*/
|
2014-05-28 13:52:50 +00:00
|
|
|
public static function template_loader( $template ) {
|
2013-06-06 12:27:04 +00:00
|
|
|
$find = array( 'woocommerce.php' );
|
|
|
|
$file = '';
|
|
|
|
|
|
|
|
if ( is_single() && get_post_type() == 'product' ) {
|
|
|
|
|
|
|
|
$file = 'single-product.php';
|
|
|
|
$find[] = $file;
|
2014-06-19 12:45:09 +00:00
|
|
|
$find[] = WC()->template_path() . $file;
|
2013-06-06 12:27:04 +00:00
|
|
|
|
2014-05-22 09:51:40 +00:00
|
|
|
} elseif ( is_product_taxonomy() ) {
|
2013-06-06 12:27:04 +00:00
|
|
|
|
2014-05-22 09:51:40 +00:00
|
|
|
$term = get_queried_object();
|
2013-06-06 12:27:04 +00:00
|
|
|
|
2014-05-22 09:51:40 +00:00
|
|
|
if ( is_tax( 'product_cat' ) || is_tax( 'product_tag' ) ) {
|
|
|
|
$file = 'taxonomy-' . $term->taxonomy . '.php';
|
|
|
|
} else {
|
|
|
|
$file = 'archive-product.php';
|
|
|
|
}
|
|
|
|
|
|
|
|
$find[] = 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php';
|
2014-06-19 12:45:09 +00:00
|
|
|
$find[] = WC()->template_path() . 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php';
|
2014-05-22 09:51:40 +00:00
|
|
|
$find[] = 'taxonomy-' . $term->taxonomy . '.php';
|
2014-06-19 12:45:09 +00:00
|
|
|
$find[] = WC()->template_path() . 'taxonomy-' . $term->taxonomy . '.php';
|
2014-05-22 09:51:40 +00:00
|
|
|
$find[] = $file;
|
2014-06-19 12:45:09 +00:00
|
|
|
$find[] = WC()->template_path() . $file;
|
2013-06-06 12:27:04 +00:00
|
|
|
|
2013-11-25 14:07:22 +00:00
|
|
|
} elseif ( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) {
|
2013-06-06 12:27:04 +00:00
|
|
|
|
|
|
|
$file = 'archive-product.php';
|
|
|
|
$find[] = $file;
|
2014-06-19 12:45:09 +00:00
|
|
|
$find[] = WC()->template_path() . $file;
|
2013-06-06 12:27:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $file ) {
|
2014-05-22 09:51:40 +00:00
|
|
|
$template = locate_template( array_unique( $find ) );
|
2013-10-23 16:21:03 +00:00
|
|
|
$status_options = get_option( 'woocommerce_status_options', array() );
|
2014-05-22 09:51:40 +00:00
|
|
|
if ( ! $template || ( ! empty( $status_options['template_debug_mode'] ) && current_user_can( 'manage_options' ) ) ) {
|
2013-10-23 15:52:58 +00:00
|
|
|
$template = WC()->plugin_path() . '/templates/' . $file;
|
2014-05-22 09:51:40 +00:00
|
|
|
}
|
2013-06-06 12:27:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $template;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* comments_template_loader function.
|
|
|
|
*
|
|
|
|
* @param mixed $template
|
|
|
|
* @return string
|
|
|
|
*/
|
2014-05-28 13:52:50 +00:00
|
|
|
public static function comments_template_loader( $template ) {
|
2013-06-06 12:27:04 +00:00
|
|
|
if ( get_post_type() !== 'product' )
|
|
|
|
return $template;
|
|
|
|
|
2014-06-19 12:45:09 +00:00
|
|
|
if ( file_exists( get_stylesheet_directory() . '/' . WC()->template_path() . 'single-product-reviews.php' ))
|
|
|
|
return get_stylesheet_directory() . '/' . WC()->template_path() . 'single-product-reviews.php';
|
|
|
|
elseif ( file_exists( get_template_directory() . '/' . WC()->template_path() . 'single-product-reviews.php' ))
|
|
|
|
return get_template_directory() . '/' . WC()->template_path() . 'single-product-reviews.php';
|
|
|
|
elseif ( file_exists( get_stylesheet_directory() . '/' . 'single-product-reviews.php' ))
|
|
|
|
return get_stylesheet_directory() . '/' . 'single-product-reviews.php';
|
|
|
|
elseif ( file_exists( get_template_directory() . '/' . 'single-product-reviews.php' ))
|
|
|
|
return get_template_directory() . '/' . 'single-product-reviews.php';
|
2013-06-06 12:27:04 +00:00
|
|
|
else
|
2013-09-12 13:41:02 +00:00
|
|
|
return WC()->plugin_path() . '/templates/single-product-reviews.php';
|
2013-06-06 12:27:04 +00:00
|
|
|
}
|
2013-08-06 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
2014-06-19 12:45:09 +00:00
|
|
|
WC_Template_Loader::init();
|