woocommerce/includes/helpers/class-wc-template-helper.php

91 lines
2.7 KiB
PHP

<?php
return new WC_Template_Helper();
class WC_Template_Helper extends WC_Helper {
public $template_url;
public function __construct() {
$this->template_url = apply_filters( 'woocommerce_template_url', 'woocommerce/' );
}
/**
* 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.
*
* @access public
* @param mixed $template
* @return string
*/
public function template_loader( $template ) {
global $woocommerce;
$find = array( 'woocommerce.php' );
$file = '';
if ( is_single() && get_post_type() == 'product' ) {
$file = 'single-product.php';
$find[] = $file;
$find[] = $this->template_url . $file;
} elseif ( is_tax( 'product_cat' ) || is_tax( 'product_tag' ) ) {
$term = get_queried_object();
$file = 'taxonomy-' . $term->taxonomy . '.php';
$find[] = 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php';
$find[] = $this->template_url . 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php';
$find[] = $file;
$find[] = $this->template_url . $file;
} elseif ( is_post_type_archive( 'product' ) || is_page( woocommerce_get_page_id( 'shop' ) ) ) {
$file = 'archive-product.php';
$find[] = $file;
$find[] = $this->template_url . $file;
}
if ( $file ) {
$template = locate_template( $find );
if ( ! $template ) $template = $woocommerce->plugin_path() . '/templates/' . $file;
}
return $template;
}
/**
* comments_template_loader function.
*
* @access public
* @param mixed $template
* @return string
*/
public function comments_template_loader( $template ) {
global $woocommerce;
if ( get_post_type() !== 'product' )
return $template;
if ( file_exists( STYLESHEETPATH . '/' . $this->template_url . 'single-product-reviews.php' ))
return STYLESHEETPATH . '/' . $this->template_url . 'single-product-reviews.php';
elseif ( file_exists( TEMPLATEPATH . '/' . $this->template_url . 'single-product-reviews.php' ))
return TEMPLATEPATH . '/' . $this->template_url . 'single-product-reviews.php';
elseif ( file_exists( STYLESHEETPATH . '/' . 'single-product-reviews.php' ))
return STYLESHEETPATH . '/' . 'single-product-reviews.php';
elseif ( file_exists( TEMPLATEPATH . '/' . 'single-product-reviews.php' ))
return TEMPLATEPATH . '/' . 'single-product-reviews.php';
else
return $woocommerce->plugin_path() . '/templates/single-product-reviews.php';
}
}