Template changes - for coen approval

This commit is contained in:
Mike Jolley 2012-07-11 11:23:31 +01:00
parent c687c214e7
commit 12dc3c033f
9 changed files with 257 additions and 124 deletions

View File

@ -153,6 +153,8 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
= 1.xxxx - xx/xx/2012 = = 1.xxxx - xx/xx/2012 =
* Feature - Support for ounces * Feature - Support for ounces
* Feature - Restore coupon usage count after order cancellation * Feature - Restore coupon usage count after order cancellation
* Templating - Dumped woocommerce_single_product_content(), woocommerce_archive_product_content(), woocommerce_product_taxonomy_content() and introduced a content-product.php template for ease of customisation.
* Templating - Documented templates listing hooked in functions.
* Tweak - Better WC_Product::get_image() function. Fixed instances where we were not echo'ing. * Tweak - Better WC_Product::get_image() function. Fixed instances where we were not echo'ing.
* Tweak - Pass valuable object data to woocommerce_email_headers and woocommerce_email_attachments filters. * Tweak - Pass valuable object data to woocommerce_email_headers and woocommerce_email_attachments filters.
* Tweak - Cart.php tweak: Disable hyperlinks for hidden products. * Tweak - Cart.php tweak: Disable hyperlinks for hidden products.

View File

@ -417,12 +417,22 @@ function woocommerce_product_page_shortcode($atts){
$args['p'] = $atts['id']; $args['p'] = $atts['id'];
} }
$product_query = new WP_Query($args); $single_product = new WP_Query( $args );
ob_start(); ob_start();
echo '<div class="single-product">';
woocommerce_single_product_content( $product_query ); while ( $single_product->have_posts() ) : $single_product->the_post(); ?>
echo '</div>';
<div class="single-product">
<?php woocommerce_get_template_part( 'content', 'product' ); ?>
</div>
<?php endwhile; // end of the loop.
wp_reset_query(); wp_reset_query();
return ob_get_clean(); return ob_get_clean();
} }

View File

@ -1,11 +1,78 @@
<?php get_header('shop'); ?> <?php
/**
* The Template for displaying product archives, including the main shop page which is a post type archive.
*
* Override this template by copying it to yourtheme/woocommerce/archive-product.php
*
* @package WooCommerce
* @since WooCommerce 1.0
* @todo replace loop-shop with a content template and include query/loop here instead.
*/
<?php do_action('woocommerce_before_main_content'); ?> get_header('shop'); ?>
<?php woocommerce_archive_product_content(); ?> <?php
/**
* woocommerce_before_main_content hook
*
* @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
* @hooked woocommerce_breadcrumb - 20
*/
do_action('woocommerce_before_main_content');
?>
<?php do_action('woocommerce_after_main_content'); ?> <h1 class="page-title">
<?php if ( is_search() ) : ?>
<?php
printf( __( 'Search Results: &ldquo;%s&rdquo;', 'woocommerce' ), get_search_query() );
if ( get_query_var( 'paged' ) )
printf( __( '&nbsp;&ndash; Page %s', 'woocommerce' ), get_query_var( 'paged' ) );
?>
<?php elseif ( is_tax() ) : ?>
<?php echo single_term_title( "", false ); ?>
<?php else : ?>
<?php
$shop_page = get_post( woocommerce_get_page_id( 'shop' ) );
<?php do_action('woocommerce_sidebar'); ?> echo apply_filters( 'the_title', ( $shop_page_title = get_option( 'woocommerce_shop_page_title' ) ) ? $shop_page_title : $shop_page->post_title );
?>
<?php endif; ?>
</h1>
<?php if ( is_tax() && get_query_var( 'paged' ) == 0 ) : ?>
<?php echo '<div class="term-description">' . wpautop( wptexturize( term_description() ) ) . '</div>'; ?>
<?php elseif ( ! is_search() && get_query_var( 'paged' ) == 0 && ! empty( $shop_page ) && is_object( $shop_page ) ) : ?>
<?php echo '<div class="page-description">' . apply_filters( 'the_content', $shop_page->post_content ) . '</div>'; ?>
<?php endif; ?>
<?php woocommerce_get_template_part( 'loop', 'shop' ); ?>
<?php
/**
* woocommerce_pagination hook
*
* @hooked woocommerce_pagination - 10
* @hooked woocommerce_catalog_ordering - 20
*/
do_action( 'woocommerce_pagination' );
?>
<?php
/**
* woocommerce_after_main_content hook
*
* @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
*/
do_action('woocommerce_after_main_content');
?>
<?php
/**
* woocommerce_sidebar hook
*
* @hooked woocommerce_get_sidebar - 10
*/
do_action('woocommerce_sidebar');
?>
<?php get_footer('shop'); ?> <?php get_footer('shop'); ?>

View File

@ -0,0 +1,64 @@
<?php
/**
* The template for displaying content in the single-product.php template
*
* Override this template by copying it to yourtheme/woocommerce/content-product.php
*
* @package WooCommerce
* @since WooCommerce 1.6
* @todo prepend class names with wc-
*/
?>
<?php
/**
* woocommerce_before_single_product hook
*
* @hooked woocommerce_show_messages - 10
*/
do_action( 'woocommerce_before_single_product' );
?>
<div itemscope itemtype="http://schema.org/Product" id="product-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
/**
* woocommerce_show_product_images hook
*
* @hooked woocommerce_show_product_sale_flash - 10
* @hooked woocommerce_show_product_images - 20
*/
do_action( 'woocommerce_before_single_product_summary' );
?>
<div class="summary">
<?php
/**
* woocommerce_single_product_summary hook
*
* @hooked woocommerce_template_single_title - 5
* @hooked woocommerce_template_single_price - 10
* @hooked woocommerce_template_single_excerpt - 20
* @hooked woocommerce_template_single_add_to_cart - 30
* @hooked woocommerce_template_single_meta - 40
* @hooked woocommerce_template_single_sharing - 50
*/
do_action( 'woocommerce_single_product_summary' );
?>
</div><!-- .summary -->
<?php
/**
* woocommerce_after_single_product_summary hook
*
* @hooked woocommerce_output_product_data_tabs - 10
* @hooked woocommerce_output_related_products - 20
*/
do_action( 'woocommerce_after_single_product_summary' );
?>
</div><!-- #product-<?php the_ID(); ?> -->
<?php do_action( 'woocommerce_after_single_product' ); ?>

View File

@ -1,11 +1,47 @@
<?php get_header('shop'); ?> <?php
/**
* The Template for displaying all single products.
*
* Override this template by copying it to yourtheme/woocommerce/single-product.php
*
* @package WooCommerce
* @since WooCommerce 1.0
*/
<?php do_action('woocommerce_before_main_content'); ?> get_header('shop'); ?>
<?php woocommerce_single_product_content(); ?> <?php
/**
* woocommerce_before_main_content hook
*
* @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
* @hooked woocommerce_breadcrumb - 20
*/
do_action('woocommerce_before_main_content');
?>
<?php do_action('woocommerce_after_main_content'); ?> <?php while ( have_posts() ) : the_post(); ?>
<?php do_action('woocommerce_sidebar'); ?> <?php woocommerce_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php
/**
* woocommerce_after_main_content hook
*
* @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
*/
do_action('woocommerce_after_main_content');
?>
<?php
/**
* woocommerce_sidebar hook
*
* @hooked woocommerce_get_sidebar - 10
*/
do_action('woocommerce_sidebar');
?>
<?php get_footer('shop'); ?> <?php get_footer('shop'); ?>

View File

@ -1,11 +1,10 @@
<?php get_header('shop'); ?> <?php
/**
* The Template for displaying products in a product category. Simple includes the archive template.
*
* Override this template by copying it to yourtheme/woocommerce/taxonomy-product_cat.php
*
* @package WooCommerce
*/
<?php do_action('woocommerce_before_main_content'); ?> woocommerce_get_template( 'archive-product.php' );
<?php woocommerce_product_taxonomy_content(); ?>
<?php do_action('woocommerce_after_main_content'); ?>
<?php do_action('woocommerce_sidebar'); ?>
<?php get_footer('shop'); ?>

View File

@ -1,11 +1,10 @@
<?php get_header('shop'); ?> <?php
/**
* The Template for displaying products in a product tag. Simple includes the archive template.
*
* Override this template by copying it to yourtheme/woocommerce/taxonomy-product_tag.php
*
* @package WooCommerce
*/
<?php do_action('woocommerce_before_main_content'); ?> woocommerce_get_template( 'archive-product.php' );
<?php woocommerce_product_taxonomy_content(); ?>
<?php do_action('woocommerce_after_main_content'); ?>
<?php do_action('woocommerce_sidebar'); ?>
<?php get_footer('shop'); ?>

View File

@ -13,53 +13,42 @@
if ( ! function_exists( 'woocommerce_content' ) ) { if ( ! function_exists( 'woocommerce_content' ) ) {
// This function is only used in the optional 'woocommerce.php' template // This function is only used in the optional 'woocommerce.php' template
// people can add to their themes to add basic woocommerce support. // people can add to their themes to add basic woocommerce support without
// using hooks or modifying core templates.
function woocommerce_content() { function woocommerce_content() {
if ( is_singular( 'product' ) )
woocommerce_single_product_content();
elseif ( is_tax( 'product_cat' ) || is_tax( 'product_tag' ) )
woocommerce_product_taxonomy_content();
else
woocommerce_archive_product_content();
}
}
if ( ! function_exists( 'woocommerce_archive_product_content' ) ) {
function woocommerce_archive_product_content() {
if ( ! is_search() ) { if ( is_singular( 'product' ) ) {
$shop_page = get_post( woocommerce_get_page_id( 'shop' ) );
$shop_page_title = apply_filters( 'the_title', ( get_option( 'woocommerce_shop_page_title' ) ) ? get_option( 'woocommerce_shop_page_title' ) : $shop_page->post_title ); while ( have_posts() ) : the_post();
if ( is_object( $shop_page ) )
$shop_page_content = $shop_page->post_content; woocommerce_get_template_part( 'content', 'product' );
endwhile;
} else { } else {
$shop_page_title = __( 'Search Results:', 'woocommerce' ) . ' &ldquo;' . get_search_query() . '&rdquo;';
if ( get_query_var( 'paged' ) ) $shop_page_title .= ' &mdash; ' . __( 'Page', 'woocommerce' ) . ' ' . get_query_var( 'paged' );
$shop_page_content = '';
}
?><h1 class="page-title"><?php echo $shop_page_title ?></h1> ?><h1 class="page-title">
<?php if ( is_search() ) : ?>
<?php printf( __( 'Search Results: &ldquo;%s&rdquo;', 'woocommerce' ), get_search_query() ); ?>
<?php elseif ( is_tax() ) : ?>
<?php echo single_term_title( "", false ); ?>
<?php else : ?>
<?php
$shop_page = get_post( woocommerce_get_page_id( 'shop' ) );
<?php if ( ! empty( $shop_page_content ) ) echo apply_filters( 'the_content', $shop_page_content ); ?> echo apply_filters( 'the_title', ( $shop_page_title = get_option( 'woocommerce_shop_page_title' ) ) ? $shop_page_title : $shop_page->post_title );
?>
<?php endif; ?>
<?php woocommerce_get_template_part( 'loop', 'shop' ); ?> <?php if ( get_query_var( 'paged' ) ) : ?>
<?php printf( __( '&nbsp;&ndash; Page %s', 'woocommerce' ), get_query_var( 'paged' ) ); ?>
<?php do_action( 'woocommerce_pagination' ); <?php endif; ?>
</h1>
}
}
if ( ! function_exists( 'woocommerce_product_taxonomy_content' ) ) {
function woocommerce_product_taxonomy_content() {
global $wp_query;
$term = get_term_by( 'slug', get_query_var( $wp_query->query_vars['taxonomy'] ) , $wp_query->query_vars['taxonomy'] );
?><h1 class="page-title"><?php echo wptexturize( $term->name ); ?></h1>
<?php if ( $term->description ) : ?>
<div class="term_description"><?php echo wpautop( wptexturize( $term->description ) ); ?></div>
<?php if ( is_tax() ) : ?>
<?php echo '<div class="term-description">' . wpautop( wptexturize( term_description() ) ) . '</div>'; ?>
<?php elseif ( ! is_search() && ! empty( $shop_page ) && is_object( $shop_page ) ) : ?>
<?php echo '<div class="page-description">' . apply_filters( 'the_content', $shop_page->post_content ) . '</div>'; ?>
<?php endif; ?> <?php endif; ?>
<?php woocommerce_get_template_part( 'loop', 'shop' ); ?> <?php woocommerce_get_template_part( 'loop', 'shop' ); ?>
@ -68,39 +57,6 @@ if ( ! function_exists( 'woocommerce_product_taxonomy_content' ) ) {
} }
} }
if ( ! function_exists( 'woocommerce_single_product_content' ) ) {
function woocommerce_single_product_content( $wc_query = false ) {
// Let developers override the query used, in case they want to use this function for their own loop/wp_query
if ( ! $wc_query ) {
global $wp_query;
$wc_query = $wp_query;
}
if ( $wc_query->have_posts() ) while ( $wc_query->have_posts() ) : $wc_query->the_post(); ?>
<?php do_action( 'woocommerce_before_single_product' ); ?>
<div itemscope itemtype="http://schema.org/Product" id="product-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php do_action( 'woocommerce_before_single_product_summary' ); ?>
<div class="summary">
<?php do_action( 'woocommerce_single_product_summary' ); ?>
</div>
<?php do_action( 'woocommerce_after_single_product_summary' ); ?>
</div>
<?php do_action( 'woocommerce_after_single_product' ); ?>
<?php endwhile;
}
} }
/** Global ****************************************************************/ /** Global ****************************************************************/