2013-06-06 12:27:04 +00:00
|
|
|
<?php
|
2015-11-06 09:22:19 +00:00
|
|
|
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit; // Exit if accessed directly
|
|
|
|
}
|
|
|
|
|
2013-09-12 13:41:02 +00:00
|
|
|
/**
|
2015-11-03 13:53:50 +00:00
|
|
|
* Template Loader
|
2013-09-12 13:41:02 +00:00
|
|
|
*
|
|
|
|
* @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
|
|
|
/**
|
2015-11-03 13:31:20 +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.
|
|
|
|
*
|
2015-11-03 13:31:20 +00:00
|
|
|
* Templates are in the 'templates' folder. woocommerce looks for theme.
|
|
|
|
* overrides in /theme/woocommerce/ by default.
|
2013-06-06 12:27:04 +00:00
|
|
|
*
|
2015-11-03 13:31:20 +00:00
|
|
|
* 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.
|
2013-06-06 12:27:04 +00:00
|
|
|
* 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 = '';
|
|
|
|
|
2016-04-25 09:27:53 +00:00
|
|
|
if ( is_embed() ) {
|
|
|
|
return $template;
|
|
|
|
}
|
|
|
|
|
2013-06-06 12:27:04 +00:00
|
|
|
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 ) );
|
2014-10-03 09:52:11 +00:00
|
|
|
if ( ! $template || WC_TEMPLATE_DEBUG_MODE ) {
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-01-06 15:24:47 +00:00
|
|
|
* Load comments template.
|
2013-06-06 12:27:04 +00:00
|
|
|
*
|
|
|
|
* @param mixed $template
|
|
|
|
* @return string
|
|
|
|
*/
|
2014-05-28 13:52:50 +00:00
|
|
|
public static function comments_template_loader( $template ) {
|
2014-10-03 09:52:11 +00:00
|
|
|
if ( get_post_type() !== 'product' ) {
|
2013-06-06 12:27:04 +00:00
|
|
|
return $template;
|
2014-10-03 09:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$check_dirs = array(
|
|
|
|
trailingslashit( get_stylesheet_directory() ) . WC()->template_path(),
|
|
|
|
trailingslashit( get_template_directory() ) . WC()->template_path(),
|
|
|
|
trailingslashit( get_stylesheet_directory() ),
|
|
|
|
trailingslashit( get_template_directory() ),
|
2016-08-27 02:08:49 +00:00
|
|
|
trailingslashit( WC()->plugin_path() ) . 'templates/',
|
2014-10-03 09:52:11 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if ( WC_TEMPLATE_DEBUG_MODE ) {
|
|
|
|
$check_dirs = array( array_pop( $check_dirs ) );
|
|
|
|
}
|
2013-06-06 12:27:04 +00:00
|
|
|
|
2014-10-03 09:52:11 +00:00
|
|
|
foreach ( $check_dirs as $dir ) {
|
|
|
|
if ( file_exists( trailingslashit( $dir ) . 'single-product-reviews.php' ) ) {
|
|
|
|
return trailingslashit( $dir ) . '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();
|