1 <?php
 2 /**
 3  * Template Loader
 4  *
 5  * @class       WC_Template
 6  * @version     2.1.0
 7  * @package     WooCommerce/Classes
 8  * @category    Class
 9  * @author      WooThemes
10  */
11 class WC_Template_Loader {
12 
13     /**
14      * Constructor
15      */
16     public function __construct() {
17         add_filter( 'template_include', array( $this, 'template_loader' ) );
18         add_filter( 'comments_template', array( $this, 'comments_template_loader' ) );
19     }
20 
21     /**
22      * Load a template.
23      *
24      * Handles template usage so that we can use our own templates instead of the themes.
25      *
26      * Templates are in the 'templates' folder. woocommerce looks for theme
27      * overrides in /theme/woocommerce/ by default
28      *
29      * For beginners, it also looks for a woocommerce.php template first. If the user adds
30      * this to the theme (containing a woocommerce() inside) this will be used for all
31      * woocommerce templates.
32      *
33      * @param mixed $template
34      * @return string
35      */
36     public function template_loader( $template ) {
37         $find = array( 'woocommerce.php' );
38         $file = '';
39 
40         if ( is_single() && get_post_type() == 'product' ) {
41 
42             $file   = 'single-product.php';
43             $find[] = $file;
44             $find[] = WC_TEMPLATE_PATH . $file;
45 
46         } elseif ( is_tax( 'product_cat' ) || is_tax( 'product_tag' ) ) {
47 
48             $term = get_queried_object();
49 
50             $file       = 'taxonomy-' . $term->taxonomy . '.php';
51             $find[]     = 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php';
52             $find[]     = WC_TEMPLATE_PATH . 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php';
53             $find[]     = $file;
54             $find[]     = WC_TEMPLATE_PATH . $file;
55 
56         } elseif ( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) {
57 
58             $file   = 'archive-product.php';
59             $find[] = $file;
60             $find[] = WC_TEMPLATE_PATH . $file;
61 
62         }
63 
64         if ( $file ) {
65             $template       = locate_template( $find );
66             $status_options = get_option( 'woocommerce_status_options', array() );
67             if ( ! $template || ( ! empty( $status_options['template_debug_mode'] ) && current_user_can( 'manage_options' ) ) )
68                 $template = WC()->plugin_path() . '/templates/' . $file;
69         }
70 
71         return $template;
72     }
73 
74     /**
75      * comments_template_loader function.
76      *
77      * @param mixed $template
78      * @return string
79      */
80     public function comments_template_loader( $template ) {
81         if ( get_post_type() !== 'product' )
82             return $template;
83 
84         if ( file_exists( STYLESHEETPATH . '/' . WC_TEMPLATE_PATH . 'single-product-reviews.php' ))
85             return STYLESHEETPATH . '/' . WC_TEMPLATE_PATH . 'single-product-reviews.php';
86         elseif ( file_exists( TEMPLATEPATH . '/' . WC_TEMPLATE_PATH . 'single-product-reviews.php' ))
87             return TEMPLATEPATH . '/' . WC_TEMPLATE_PATH . 'single-product-reviews.php';
88         elseif ( file_exists( STYLESHEETPATH . '/' . 'single-product-reviews.php' ))
89             return STYLESHEETPATH . '/' . 'single-product-reviews.php';
90         elseif ( file_exists( TEMPLATEPATH . '/' . 'single-product-reviews.php' ))
91             return TEMPLATEPATH . '/' . 'single-product-reviews.php';
92         else
93             return WC()->plugin_path() . '/templates/single-product-reviews.php';
94     }
95 }
96 
97 new WC_Template_Loader();
WooCommerce API documentation generated by ApiGen 2.8.0