2011-08-10 17:11:11 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* WooCommerce Templates
|
|
|
|
*
|
|
|
|
* Handles template usage so that we can use our own templates instead of the theme's.
|
|
|
|
*
|
|
|
|
* Templates are in the 'templates' folder. woocommerce looks for theme
|
|
|
|
* overides in /theme/woocommerce/ by default but this can be overwritten with WOOCOMMERCE_TEMPLATE_URL
|
|
|
|
*
|
|
|
|
* @package WooCommerce
|
|
|
|
* @category Core
|
|
|
|
* @author WooThemes
|
|
|
|
*/
|
|
|
|
function woocommerce_template_loader( $template ) {
|
2011-09-06 11:11:22 +00:00
|
|
|
global $woocommerce;
|
2011-08-10 17:11:11 +00:00
|
|
|
|
|
|
|
if ( is_single() && get_post_type() == 'product' ) {
|
|
|
|
|
|
|
|
$template = locate_template( array( 'single-product.php', WOOCOMMERCE_TEMPLATE_URL . 'single-product.php' ) );
|
|
|
|
|
2011-09-06 11:11:22 +00:00
|
|
|
if ( ! $template ) $template = $woocommerce->plugin_path() . '/templates/single-product.php';
|
2011-08-10 17:11:11 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
elseif ( is_tax('product_cat') ) {
|
|
|
|
|
|
|
|
$template = locate_template( array( 'taxonomy-product_cat.php', WOOCOMMERCE_TEMPLATE_URL . 'taxonomy-product_cat.php' ) );
|
|
|
|
|
2011-09-06 11:11:22 +00:00
|
|
|
if ( ! $template ) $template = $woocommerce->plugin_path() . '/templates/taxonomy-product_cat.php';
|
2011-08-10 17:11:11 +00:00
|
|
|
}
|
|
|
|
elseif ( is_tax('product_tag') ) {
|
|
|
|
|
|
|
|
$template = locate_template( array( 'taxonomy-product_tag.php', WOOCOMMERCE_TEMPLATE_URL . 'taxonomy-product_tag.php' ) );
|
|
|
|
|
2011-09-06 11:11:22 +00:00
|
|
|
if ( ! $template ) $template = $woocommerce->plugin_path() . '/templates/taxonomy-product_tag.php';
|
2011-08-10 17:11:11 +00:00
|
|
|
}
|
|
|
|
elseif ( is_post_type_archive('product') || is_page( get_option('woocommerce_shop_page_id') )) {
|
|
|
|
|
|
|
|
$template = locate_template( array( 'archive-product.php', WOOCOMMERCE_TEMPLATE_URL . 'archive-product.php' ) );
|
|
|
|
|
2011-09-06 11:11:22 +00:00
|
|
|
if ( ! $template ) $template = $woocommerce->plugin_path() . '/templates/archive-product.php';
|
2011-08-10 17:11:11 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $template;
|
|
|
|
|
|
|
|
}
|
|
|
|
add_filter( 'template_include', 'woocommerce_template_loader' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get template part (for templates like loop)
|
|
|
|
*/
|
|
|
|
function woocommerce_get_template_part( $slug, $name = '' ) {
|
2011-09-06 11:11:22 +00:00
|
|
|
global $woocommerce;
|
2011-08-10 17:11:11 +00:00
|
|
|
if ($name=='shop') :
|
|
|
|
if (!locate_template(array( 'loop-shop.php', WOOCOMMERCE_TEMPLATE_URL . 'loop-shop.php' ))) :
|
2011-09-06 11:11:22 +00:00
|
|
|
load_template( $woocommerce->plugin_path() . '/templates/loop-shop.php',false );
|
2011-08-10 17:11:11 +00:00
|
|
|
return;
|
|
|
|
endif;
|
|
|
|
endif;
|
|
|
|
get_template_part( WOOCOMMERCE_TEMPLATE_URL . $slug, $name );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the reviews template (comments)
|
|
|
|
*/
|
|
|
|
function woocommerce_comments_template($template) {
|
2011-09-06 11:11:22 +00:00
|
|
|
global $woocommerce;
|
2011-08-10 17:11:11 +00:00
|
|
|
|
|
|
|
if(get_post_type() !== 'product') return $template;
|
|
|
|
|
|
|
|
if (file_exists( STYLESHEETPATH . '/' . WOOCOMMERCE_TEMPLATE_URL . 'single-product-reviews.php' ))
|
|
|
|
return STYLESHEETPATH . '/' . WOOCOMMERCE_TEMPLATE_URL . 'single-product-reviews.php';
|
|
|
|
else
|
2011-09-06 11:11:22 +00:00
|
|
|
return $woocommerce->plugin_path() . '/templates/single-product-reviews.php';
|
2011-08-10 17:11:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
add_filter('comments_template', 'woocommerce_comments_template' );
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get other templates (e.g. product attributes)
|
|
|
|
*/
|
|
|
|
function woocommerce_get_template($template_name, $require_once = true) {
|
2011-09-06 11:11:22 +00:00
|
|
|
global $woocommerce;
|
2011-08-10 17:11:11 +00:00
|
|
|
if (file_exists( STYLESHEETPATH . '/' . WOOCOMMERCE_TEMPLATE_URL . $template_name )) load_template( STYLESHEETPATH . '/' . WOOCOMMERCE_TEMPLATE_URL . $template_name, $require_once );
|
|
|
|
elseif (file_exists( STYLESHEETPATH . '/' . $template_name )) load_template( STYLESHEETPATH . '/' . $template_name , $require_once);
|
2011-09-06 11:11:22 +00:00
|
|
|
else load_template( $woocommerce->plugin_path() . '/templates/' . $template_name , $require_once);
|
2011-08-10 17:11:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get other templates (e.g. product attributes) - path
|
|
|
|
*/
|
|
|
|
function woocommerce_get_template_file_url($template_name, $ssl = false) {
|
2011-09-06 11:11:22 +00:00
|
|
|
global $woocommerce;
|
2011-08-10 17:11:11 +00:00
|
|
|
if (file_exists( STYLESHEETPATH . '/' . WOOCOMMERCE_TEMPLATE_URL . $template_name ))
|
|
|
|
$return = get_bloginfo('template_url') . '/' . WOOCOMMERCE_TEMPLATE_URL . $template_name;
|
|
|
|
elseif (file_exists( STYLESHEETPATH . '/' . $template_name ))
|
|
|
|
$return = get_bloginfo('template_url') . '/' . $template_name;
|
|
|
|
else
|
2011-09-06 11:11:22 +00:00
|
|
|
$return = $woocommerce->plugin_url() . '/templates/' . $template_name;
|
2011-08-10 17:11:11 +00:00
|
|
|
|
|
|
|
if (get_option('woocommerce_force_ssl_checkout')=='yes' || is_ssl()) :
|
|
|
|
if ($ssl) $return = str_replace('http:', 'https:', $return);
|
|
|
|
endif;
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2011-08-31 10:51:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Front page archive/shop template
|
|
|
|
*/
|
|
|
|
if (!function_exists('woocommerce_front_page_archive')) {
|
|
|
|
function woocommerce_front_page_archive() {
|
|
|
|
|
|
|
|
global $paged;
|
|
|
|
|
|
|
|
if ( is_front_page() && is_page( get_option('woocommerce_shop_page_id') )) :
|
|
|
|
|
|
|
|
if ( get_query_var('paged') ) {
|
|
|
|
$paged = get_query_var('paged');
|
|
|
|
} else if ( get_query_var('page') ) {
|
|
|
|
$paged = get_query_var('page');
|
|
|
|
} else {
|
|
|
|
$paged = 1;
|
|
|
|
}
|
|
|
|
|
2011-09-02 14:42:04 +00:00
|
|
|
add_filter( 'parse_query', 'woocommerce_parse_query' );
|
|
|
|
|
2011-08-31 10:51:50 +00:00
|
|
|
query_posts( array( 'page_id' => '', 'post_type' => 'product', 'paged' => $paged ) );
|
|
|
|
|
|
|
|
define('SHOP_IS_ON_FRONT', true);
|
|
|
|
|
|
|
|
endif;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add_action('wp', 'woocommerce_front_page_archive', 1);
|
|
|
|
|
|
|
|
|
2011-08-10 17:11:11 +00:00
|
|
|
/**
|
|
|
|
* Add Body classes based on page/template
|
|
|
|
**/
|
|
|
|
global $woocommerce_body_classes;
|
|
|
|
|
|
|
|
function woocommerce_page_body_classes() {
|
|
|
|
|
|
|
|
global $woocommerce_body_classes;
|
|
|
|
|
|
|
|
$woocommerce_body_classes = (array) $woocommerce_body_classes;
|
|
|
|
|
2011-09-08 09:43:56 +00:00
|
|
|
$woocommerce_body_classes[] = 'theme-' . strtolower( get_current_theme() );
|
2011-08-10 17:11:11 +00:00
|
|
|
|
2011-09-08 09:43:56 +00:00
|
|
|
if (is_woocommerce()) $woocommerce_body_classes[] = 'woocommerce';
|
2011-08-10 17:11:11 +00:00
|
|
|
|
2011-09-08 09:43:56 +00:00
|
|
|
if (is_checkout()) $woocommerce_body_classes[] = 'woocommerce-checkout';
|
2011-08-10 17:11:11 +00:00
|
|
|
|
2011-09-08 09:43:56 +00:00
|
|
|
if (is_cart()) $woocommerce_body_classes[] = 'woocommerce-cart';
|
|
|
|
|
2011-08-10 17:11:11 +00:00
|
|
|
}
|
|
|
|
add_action('wp_head', 'woocommerce_page_body_classes');
|
|
|
|
|
|
|
|
function woocommerce_body_class($classes) {
|
|
|
|
|
|
|
|
global $woocommerce_body_classes;
|
|
|
|
|
|
|
|
$woocommerce_body_classes = (array) $woocommerce_body_classes;
|
|
|
|
|
|
|
|
$classes = array_merge($classes, $woocommerce_body_classes);
|
|
|
|
|
|
|
|
return $classes;
|
|
|
|
}
|
|
|
|
add_filter('body_class','woocommerce_body_class');
|