1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
<?php /** * Template Loader * * @class WC_Template * @version 2.2.0 * @package WooCommerce/Classes * @category Class * @author WooThemes */ class WC_Template_Loader {
/** * Hook in methods */ public static function init() { add_filter( 'template_include', array( __CLASS__, 'template_loader' ) ); add_filter( 'comments_template', array( __CLASS__, 'comments_template_loader' ) ); }
/** * 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 */ public static function template_loader( $template ) { $find = array( 'woocommerce.php' ); $file = '';
if ( is_single() && get_post_type() == 'product' ) {
$file = 'single-product.php'; $find[] = $file; $find[] = WC()->template_path() . $file;
} elseif ( is_product_taxonomy() ) {
$term = get_queried_object();
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'; $find[] = WC()->template_path() . 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php'; $find[] = 'taxonomy-' . $term->taxonomy . '.php'; $find[] = WC()->template_path() . 'taxonomy-' . $term->taxonomy . '.php'; $find[] = $file; $find[] = WC()->template_path() . $file;
} elseif ( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) {
$file = 'archive-product.php'; $find[] = $file; $find[] = WC()->template_path() . $file;
}
if ( $file ) { $template = locate_template( array_unique( $find ) ); $status_options = get_option( 'woocommerce_status_options', array() ); if ( ! $template || ( ! empty( $status_options['template_debug_mode'] ) && current_user_can( 'manage_options' ) ) ) { $template = WC()->plugin_path() . '/templates/' . $file; } }
return $template; }
/** * comments_template_loader function. * * @param mixed $template * @return string */ public static function comments_template_loader( $template ) { if ( get_post_type() !== 'product' ) return $template;
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'; else return WC()->plugin_path() . '/templates/single-product-reviews.php'; } }
WC_Template_Loader::init();
|