abstracts
9 years ago
admin
9 years ago
api
9 years ago
cli
9 years ago
data-stores
9 years ago
emails
9 years ago
gateways
9 years ago
interfaces
9 years ago
legacy
9 years ago
libraries
9 years ago
log-handlers
9 years ago
payment-tokens
9 years ago
shipping
9 years ago
shortcodes
9 years ago
theme-support
9 years ago
vendor
9 years ago
walkers
9 years ago
widgets
9 years ago
class-wc-ajax.php
9 years ago
class-wc-api.php
9 years ago
class-wc-auth.php
9 years ago
class-wc-autoloader.php
9 years ago
class-wc-background-emailer.php
9 years ago
class-wc-background-updater.php
9 years ago
class-wc-breadcrumb.php
9 years ago
class-wc-cache-helper.php
9 years ago
class-wc-cart.php
9 years ago
class-wc-checkout.php
9 years ago
class-wc-cli.php
9 years ago
class-wc-comments.php
9 years ago
class-wc-countries.php
9 years ago
class-wc-coupon.php
9 years ago
class-wc-customer-download.php
9 years ago
class-wc-customer.php
9 years ago
class-wc-data-exception.php
9 years ago
class-wc-data-store.php
9 years ago
class-wc-datetime.php
9 years ago
class-wc-deprecated-action-hooks.php
9 years ago
class-wc-deprecated-filter-hooks.php
9 years ago
class-wc-download-handler.php
9 years ago
class-wc-emails.php
9 years ago
class-wc-embed.php
9 years ago
class-wc-form-handler.php
9 years ago
class-wc-frontend-scripts.php
9 years ago
class-wc-geo-ip.php
9 years ago
class-wc-geolocation.php
9 years ago
class-wc-https.php
9 years ago
class-wc-install.php
9 years ago
class-wc-integrations.php
9 years ago
class-wc-legacy-api.php
9 years ago
class-wc-log-levels.php
9 years ago
class-wc-logger.php
9 years ago
class-wc-order-factory.php
9 years ago
class-wc-order-item-coupon.php
9 years ago
class-wc-order-item-fee.php
9 years ago
class-wc-order-item-meta.php
9 years ago
class-wc-order-item-product.php
9 years ago
class-wc-order-item-shipping.php
9 years ago
class-wc-order-item-tax.php
9 years ago
class-wc-order-item.php
9 years ago
class-wc-order-refund.php
9 years ago
class-wc-order.php
9 years ago
class-wc-payment-gateways.php
9 years ago
class-wc-payment-tokens.php
9 years ago
class-wc-post-data.php
9 years ago
class-wc-post-types.php
9 years ago
class-wc-product-attribute.php
9 years ago
class-wc-product-download.php
9 years ago
class-wc-product-external.php
9 years ago
class-wc-product-factory.php
9 years ago
class-wc-product-grouped.php
9 years ago
class-wc-product-simple.php
9 years ago
class-wc-product-variable.php
9 years ago
class-wc-product-variation.php
9 years ago
class-wc-query.php
9 years ago
class-wc-register-wp-admin-settings.php
9 years ago
class-wc-session-handler.php
9 years ago
class-wc-shipping-rate.php
9 years ago
class-wc-shipping-zone.php
9 years ago
class-wc-shipping-zones.php
9 years ago
class-wc-shipping.php
9 years ago
class-wc-shortcodes.php
9 years ago
class-wc-structured-data.php
9 years ago
class-wc-tax.php
9 years ago
class-wc-template-loader.php
9 years ago
class-wc-tracker.php
9 years ago
class-wc-validation.php
9 years ago
class-wc-webhook.php
9 years ago
wc-account-functions.php
9 years ago
wc-attribute-functions.php
9 years ago
wc-cart-functions.php
9 years ago
wc-conditional-functions.php
9 years ago
wc-core-functions.php
9 years ago
wc-coupon-functions.php
9 years ago
wc-deprecated-functions.php
9 years ago
wc-formatting-functions.php
9 years ago
wc-notice-functions.php
9 years ago
wc-order-functions.php
9 years ago
wc-order-item-functions.php
9 years ago
wc-page-functions.php
9 years ago
wc-product-functions.php
9 years ago
wc-rest-functions.php
9 years ago
wc-stock-functions.php
9 years ago
wc-template-functions.php
9 years ago
wc-template-hooks.php
9 years ago
wc-term-functions.php
9 years ago
wc-update-functions.php
9 years ago
wc-user-functions.php
9 years ago
wc-webhook-functions.php
9 years ago
wc-widget-functions.php
9 years ago
class-wc-template-loader.php
146 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; // Exit if accessed directly |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Template Loader |
| 9 | * |
| 10 | * @class WC_Template |
| 11 | * @version 2.2.0 |
| 12 | * @package WooCommerce/Classes |
| 13 | * @category Class |
| 14 | * @author WooThemes |
| 15 | */ |
| 16 | class WC_Template_Loader { |
| 17 | |
| 18 | /** |
| 19 | * Hook in methods. |
| 20 | */ |
| 21 | public static function init() { |
| 22 | add_filter( 'template_include', array( __CLASS__, 'template_loader' ) ); |
| 23 | add_filter( 'comments_template', array( __CLASS__, 'comments_template_loader' ) ); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Load a template. |
| 28 | * |
| 29 | * Handles template usage so that we can use our own templates instead of the themes. |
| 30 | * |
| 31 | * Templates are in the 'templates' folder. woocommerce looks for theme. |
| 32 | * overrides in /theme/woocommerce/ by default. |
| 33 | * |
| 34 | * For beginners, it also looks for a woocommerce.php template first. If the user adds. |
| 35 | * this to the theme (containing a woocommerce() inside) this will be used for all. |
| 36 | * woocommerce templates. |
| 37 | * |
| 38 | * @param mixed $template |
| 39 | * @return string |
| 40 | */ |
| 41 | public static function template_loader( $template ) { |
| 42 | if ( is_embed() ) { |
| 43 | return $template; |
| 44 | } |
| 45 | |
| 46 | if ( $default_file = self::get_template_loader_default_file() ) { |
| 47 | /** |
| 48 | * Filter hook to choose which files to find before WooCommerce does it's own logic. |
| 49 | * |
| 50 | * @since 3.0.0 |
| 51 | * @var array |
| 52 | */ |
| 53 | $search_files = self::get_template_loader_files( $default_file ); |
| 54 | $template = locate_template( $search_files ); |
| 55 | |
| 56 | if ( ! $template || WC_TEMPLATE_DEBUG_MODE ) { |
| 57 | $template = WC()->plugin_path() . '/templates/' . $default_file; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | return $template; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Get the default filename for a template. |
| 66 | * |
| 67 | * @since 3.0.0 |
| 68 | * @return string |
| 69 | */ |
| 70 | private static function get_template_loader_default_file() { |
| 71 | if ( is_singular( 'product' ) ) { |
| 72 | $default_file = 'single-product.php'; |
| 73 | } elseif ( is_product_taxonomy() ) { |
| 74 | $term = get_queried_object(); |
| 75 | |
| 76 | if ( is_tax( 'product_cat' ) || is_tax( 'product_tag' ) ) { |
| 77 | $default_file = 'taxonomy-' . $term->taxonomy . '.php'; |
| 78 | } else { |
| 79 | $default_file = 'archive-product.php'; |
| 80 | } |
| 81 | } elseif ( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) { |
| 82 | $default_file = 'archive-product.php'; |
| 83 | } else { |
| 84 | $default_file = ''; |
| 85 | } |
| 86 | return $default_file; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Get an array of filenames to search for a given template. |
| 91 | * |
| 92 | * @since 3.0.0 |
| 93 | * @param string $file The default file name. |
| 94 | * @return string[] |
| 95 | */ |
| 96 | private static function get_template_loader_files( $default_file ) { |
| 97 | $search_files = apply_filters( 'woocommerce_template_loader_files', array(), $default_file ); |
| 98 | $search_files[] = 'woocommerce.php'; |
| 99 | |
| 100 | if ( is_product_taxonomy() ) { |
| 101 | $term = get_queried_object(); |
| 102 | $search_files[] = 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php'; |
| 103 | $search_files[] = WC()->template_path() . 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php'; |
| 104 | $search_files[] = 'taxonomy-' . $term->taxonomy . '.php'; |
| 105 | $search_files[] = WC()->template_path() . 'taxonomy-' . $term->taxonomy . '.php'; |
| 106 | } |
| 107 | |
| 108 | $search_files[] = $default_file; |
| 109 | $search_files[] = WC()->template_path() . $default_file; |
| 110 | |
| 111 | return array_unique( $search_files ); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Load comments template. |
| 116 | * |
| 117 | * @param mixed $template |
| 118 | * @return string |
| 119 | */ |
| 120 | public static function comments_template_loader( $template ) { |
| 121 | if ( get_post_type() !== 'product' ) { |
| 122 | return $template; |
| 123 | } |
| 124 | |
| 125 | $check_dirs = array( |
| 126 | trailingslashit( get_stylesheet_directory() ) . WC()->template_path(), |
| 127 | trailingslashit( get_template_directory() ) . WC()->template_path(), |
| 128 | trailingslashit( get_stylesheet_directory() ), |
| 129 | trailingslashit( get_template_directory() ), |
| 130 | trailingslashit( WC()->plugin_path() ) . 'templates/', |
| 131 | ); |
| 132 | |
| 133 | if ( WC_TEMPLATE_DEBUG_MODE ) { |
| 134 | $check_dirs = array( array_pop( $check_dirs ) ); |
| 135 | } |
| 136 | |
| 137 | foreach ( $check_dirs as $dir ) { |
| 138 | if ( file_exists( trailingslashit( $dir ) . 'single-product-reviews.php' ) ) { |
| 139 | return trailingslashit( $dir ) . 'single-product-reviews.php'; |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | WC_Template_Loader::init(); |
| 146 |