1 <?php
2 3 4 5 6 7 8 9 10
11 class WC_Template_Loader {
12
13 14 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 23 24 25 26 27 28 29 30 31 32 33 34 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 76 77 78 79
80 public function ( $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();