Refined the way in which tabs are added to products
This commit is contained in:
parent
55d2237d9f
commit
3e5b4141f6
|
@ -212,6 +212,8 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
|
||||||
* Templating - Replaced Fancybox with prettyPhoto
|
* Templating - Replaced Fancybox with prettyPhoto
|
||||||
* Templating - loop-shop which was depricated is now gone for good.
|
* Templating - loop-shop which was depricated is now gone for good.
|
||||||
* Templating - Renamed empty.php to cart-empty.php to make clearer.
|
* Templating - Renamed empty.php to cart-empty.php to make clearer.
|
||||||
|
* Templating - Renamed sorting.php to orderby.php to better reflect contained hooks and code.
|
||||||
|
* Templating - Product tabs rewritten - new filter to define tab titles, priorities, and display callbacks.
|
||||||
|
|
||||||
* Tweak - Sorting uses GET to make it cache friendly
|
* Tweak - Sorting uses GET to make it cache friendly
|
||||||
* Tweak - Optimised class loading (autoload). Reduced memory consumption.
|
* Tweak - Optimised class loading (autoload). Reduced memory consumption.
|
||||||
|
|
|
@ -4,23 +4,37 @@
|
||||||
*
|
*
|
||||||
* @author WooThemes
|
* @author WooThemes
|
||||||
* @package WooCommerce/Templates
|
* @package WooCommerce/Templates
|
||||||
* @version 1.6.4
|
* @version 2.0.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||||
|
|
||||||
// Get tabs
|
/**
|
||||||
ob_start();
|
* Filter tabs and allow third parties to add their own
|
||||||
|
*
|
||||||
do_action('woocommerce_product_tabs');
|
* Each tab is an array containing title, callback and priority. See @woocommerce_default_product_tabs()
|
||||||
|
*/
|
||||||
$tabs = trim( ob_get_clean() );
|
$tabs = apply_filters( 'woocommerce_product_tabs', array() );
|
||||||
|
|
||||||
if ( ! empty( $tabs ) ) : ?>
|
if ( ! empty( $tabs ) ) : ?>
|
||||||
|
|
||||||
<div class="woocommerce-tabs">
|
<div class="woocommerce-tabs">
|
||||||
<ul class="tabs">
|
<ul class="tabs">
|
||||||
<?php echo $tabs; ?>
|
<?php foreach ( $tabs as $key => $tab ) : ?>
|
||||||
|
|
||||||
|
<li class="<?php echo $key ?>_tab">
|
||||||
|
<a href="#tab-<?php echo $key ?>"><?php echo apply_filters( 'woocommerce_product_' . $key . '_tab_title', $tab['title'], $key ) ?></a>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<?php endforeach; ?>
|
||||||
</ul>
|
</ul>
|
||||||
<?php do_action('woocommerce_product_tab_panels'); ?>
|
<?php foreach ( $tabs as $key => $tab ) : ?>
|
||||||
|
|
||||||
|
<div class="panel entry-content" id="tab-<?php echo $key ?>">
|
||||||
|
<?php call_user_func( $tab['callback'], $key, $tab ) ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php endforeach; ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Additonal Information tab
|
||||||
|
*
|
||||||
|
* @author WooThemes
|
||||||
|
* @package WooCommerce/Templates
|
||||||
|
* @version 2.0.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||||
|
|
||||||
|
global $woocommerce, $post, $product;
|
||||||
|
|
||||||
|
$heading = apply_filters( 'woocommerce_product_additional_information_heading', __( 'Additional Information', 'woocommerce' ) );
|
||||||
|
?>
|
||||||
|
|
||||||
|
<h2><?php echo $heading; ?></h2>
|
||||||
|
|
||||||
|
<?php $product->list_attributes(); ?>
|
|
@ -1,29 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Attributes tab
|
|
||||||
*
|
|
||||||
* @author WooThemes
|
|
||||||
* @package WooCommerce/Templates
|
|
||||||
* @version 1.6.4
|
|
||||||
*/
|
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|
||||||
|
|
||||||
global $woocommerce, $post, $product;
|
|
||||||
|
|
||||||
$show_attr = ( get_option( 'woocommerce_enable_dimension_product_attributes' ) == 'yes' ? true : false );
|
|
||||||
|
|
||||||
if ( $product->has_attributes() || ( $show_attr && $product->has_dimensions() ) || ( $show_attr && $product->has_weight() ) ) {
|
|
||||||
?>
|
|
||||||
<div class="panel entry-content" id="tab-attributes">
|
|
||||||
|
|
||||||
<?php $heading = apply_filters('woocommerce_product_additional_information_heading', __( 'Additional Information', 'woocommerce' )); ?>
|
|
||||||
|
|
||||||
<h2><?php echo $heading; ?></h2>
|
|
||||||
|
|
||||||
<?php $product->list_attributes(); ?>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<?php
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -4,21 +4,16 @@
|
||||||
*
|
*
|
||||||
* @author WooThemes
|
* @author WooThemes
|
||||||
* @package WooCommerce/Templates
|
* @package WooCommerce/Templates
|
||||||
* @version 1.6.4
|
* @version 2.0.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||||
|
|
||||||
global $woocommerce, $post;
|
global $woocommerce, $post;
|
||||||
|
|
||||||
if ( $post->post_content ) : ?>
|
$heading = esc_html( apply_filters('woocommerce_product_description_heading', __( 'Product Description', 'woocommerce' ) ) );
|
||||||
<div class="panel entry-content" id="tab-description">
|
?>
|
||||||
|
|
||||||
<?php $heading = esc_html( apply_filters('woocommerce_product_description_heading', __( 'Product Description', 'woocommerce' ) ) ); ?>
|
<h2><?php echo $heading; ?></h2>
|
||||||
|
|
||||||
<h2><?php echo $heading; ?></h2>
|
<?php the_content(); ?>
|
||||||
|
|
||||||
<?php the_content(); ?>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<?php endif; ?>
|
|
|
@ -1,20 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Reviews tab
|
|
||||||
*
|
|
||||||
* @author WooThemes
|
|
||||||
* @package WooCommerce/Templates
|
|
||||||
* @version 1.6.4
|
|
||||||
*/
|
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|
||||||
|
|
||||||
global $woocommerce, $post;
|
|
||||||
|
|
||||||
if ( comments_open() ) : ?>
|
|
||||||
<div class="panel entry-content" id="tab-reviews">
|
|
||||||
|
|
||||||
<?php comments_template(); ?>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<?php endif; ?>
|
|
|
@ -1,22 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Attributes tab
|
|
||||||
*
|
|
||||||
* @author WooThemes
|
|
||||||
* @package WooCommerce/Templates
|
|
||||||
* @version 1.6.4
|
|
||||||
*/
|
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|
||||||
|
|
||||||
global $product;
|
|
||||||
|
|
||||||
$show_attr = ( get_option( 'woocommerce_enable_dimension_product_attributes' ) == 'yes' ? true : false );
|
|
||||||
|
|
||||||
if ( $product->has_attributes() || ( $show_attr && $product->has_dimensions() ) || ( $show_attr && $product->has_weight() ) ) {
|
|
||||||
?>
|
|
||||||
<li class="attributes_tab"><a href="#tab-attributes"><?php echo apply_filters('woocommerce_product_additional_information_tab_title', __( 'Additional Information', 'woocommerce' )); ?></a></li>
|
|
||||||
|
|
||||||
<?php
|
|
||||||
}
|
|
||||||
?>
|
|
|
@ -1,16 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Description tab
|
|
||||||
*
|
|
||||||
* @author WooThemes
|
|
||||||
* @package WooCommerce/Templates
|
|
||||||
* @version 1.6.4
|
|
||||||
*/
|
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|
||||||
|
|
||||||
global $post;
|
|
||||||
|
|
||||||
if ( $post->post_content ) : ?>
|
|
||||||
<li class="description_tab"><a href="#tab-description"><?php echo apply_filters('woocommerce_product_description_tab_title', __( 'Description', 'woocommerce' )) ?></a></li>
|
|
||||||
<?php endif; ?>
|
|
|
@ -1,14 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Reviews tab
|
|
||||||
*
|
|
||||||
* @author WooThemes
|
|
||||||
* @package WooCommerce/Templates
|
|
||||||
* @version 1.6.4
|
|
||||||
*/
|
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|
||||||
|
|
||||||
if ( comments_open() ) : ?>
|
|
||||||
<li class="reviews_tab"><a href="#tab-reviews"><?php echo apply_filters('woocommerce_reviews_tab_title', __( 'Reviews', 'woocommerce' )) ?><?php echo comments_number(' (0)', ' (1)', ' (%)'); ?></a></li>
|
|
||||||
<?php endif; ?>
|
|
|
@ -155,20 +155,9 @@ if ( ! is_admin() || defined('DOING_AJAX') ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Product page tabs
|
* Product page tabs
|
||||||
*
|
|
||||||
* @see woocommerce_product_description_tab()
|
|
||||||
* @see woocommerce_product_attributes_tab()
|
|
||||||
* @see woocommerce_product_reviews_tab()
|
|
||||||
* @see woocommerce_product_description_panel()
|
|
||||||
* @see woocommerce_product_attributes_panel()
|
|
||||||
* @see woocommerce_product_reviews_panel()
|
|
||||||
*/
|
*/
|
||||||
add_action( 'woocommerce_product_tabs', 'woocommerce_product_description_tab', 10 );
|
add_filter( 'woocommerce_product_tabs', 'woocommerce_default_product_tabs' );
|
||||||
add_action( 'woocommerce_product_tabs', 'woocommerce_product_attributes_tab', 20 );
|
add_filter( 'woocommerce_product_tabs', 'woocommerce_sort_product_tabs', 99 );
|
||||||
add_action( 'woocommerce_product_tabs', 'woocommerce_product_reviews_tab', 30 );
|
|
||||||
add_action( 'woocommerce_product_tab_panels', 'woocommerce_product_description_panel', 10 );
|
|
||||||
add_action( 'woocommerce_product_tab_panels', 'woocommerce_product_attributes_panel', 20 );
|
|
||||||
add_action( 'woocommerce_product_tab_panels', 'woocommerce_product_reviews_panel', 30 );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checkout
|
* Checkout
|
||||||
|
|
|
@ -445,7 +445,7 @@ if ( ! function_exists( 'woocommerce_catalog_ordering' ) ) {
|
||||||
|
|
||||||
$orderby = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
|
$orderby = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
|
||||||
|
|
||||||
woocommerce_get_template( 'loop/sorting.php', array( 'orderby' => $orderby ) );
|
woocommerce_get_template( 'loop/orderby.php', array( 'orderby' => $orderby ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -695,46 +695,6 @@ if ( ! function_exists( 'woocommerce_quantity_input' ) ) {
|
||||||
|
|
||||||
if ( ! function_exists( 'woocommerce_product_description_tab' ) ) {
|
if ( ! function_exists( 'woocommerce_product_description_tab' ) ) {
|
||||||
|
|
||||||
/**
|
|
||||||
* Output the description tab.
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @subpackage Product/Tabs
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function woocommerce_product_description_tab() {
|
|
||||||
woocommerce_get_template( 'single-product/tabs/tab-description.php' );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( ! function_exists( 'woocommerce_product_attributes_tab' ) ) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Output the attributes tab.
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @subpackage Product/Tabs
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function woocommerce_product_attributes_tab() {
|
|
||||||
woocommerce_get_template( 'single-product/tabs/tab-attributes.php' );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( ! function_exists( 'woocommerce_product_reviews_tab' ) ) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Output the reviews tab.
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @subpackage Product/Tabs
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
function woocommerce_product_reviews_tab() {
|
|
||||||
woocommerce_get_template( 'single-product/tabs/tab-reviews.php' );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! function_exists( 'woocommerce_product_description_panel' ) ) {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Output the description tab content.
|
* Output the description tab content.
|
||||||
*
|
*
|
||||||
|
@ -742,11 +702,11 @@ if ( ! function_exists( 'woocommerce_product_description_panel' ) ) {
|
||||||
* @subpackage Product/Tabs
|
* @subpackage Product/Tabs
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function woocommerce_product_description_panel() {
|
function woocommerce_product_description_tab() {
|
||||||
woocommerce_get_template( 'single-product/tabs/description.php' );
|
woocommerce_get_template( 'single-product/tabs/description.php' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( ! function_exists( 'woocommerce_product_attributes_panel' ) ) {
|
if ( ! function_exists( 'woocommerce_product_additional_information_tab' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Output the attributes tab content.
|
* Output the attributes tab content.
|
||||||
|
@ -755,11 +715,11 @@ if ( ! function_exists( 'woocommerce_product_attributes_panel' ) ) {
|
||||||
* @subpackage Product/Tabs
|
* @subpackage Product/Tabs
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function woocommerce_product_attributes_panel() {
|
function woocommerce_product_additional_information_tab() {
|
||||||
woocommerce_get_template( 'single-product/tabs/attributes.php' );
|
woocommerce_get_template( 'single-product/tabs/additional-information.php' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( ! function_exists( 'woocommerce_product_reviews_panel' ) ) {
|
if ( ! function_exists( 'woocommerce_product_reviews_tab' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Output the reviews tab content.
|
* Output the reviews tab content.
|
||||||
|
@ -768,11 +728,76 @@ if ( ! function_exists( 'woocommerce_product_reviews_panel' ) ) {
|
||||||
* @subpackage Product/Tabs
|
* @subpackage Product/Tabs
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function woocommerce_product_reviews_panel() {
|
function woocommerce_product_reviews_tab() {
|
||||||
woocommerce_get_template( 'single-product/tabs/reviews.php' );
|
woocommerce_get_template( 'single-product/tabs/reviews.php' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ! function_exists( 'woocommerce_default_product_tabs' ) ) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add default product tabs to product pages.
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param mixed $tabs
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function woocommerce_default_product_tabs( $tabs = array() ) {
|
||||||
|
global $product, $post;
|
||||||
|
|
||||||
|
// Description tab - shows product content
|
||||||
|
if ( $post->post_content )
|
||||||
|
$tabs['description'] = array(
|
||||||
|
'title' => __( 'Description', 'woocommerce' ),
|
||||||
|
'priority' => 10,
|
||||||
|
'callback' => 'woocommerce_product_description_tab'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Additonal information tab - shows attributes
|
||||||
|
if ( $product->has_attributes() || ( get_option( 'woocommerce_enable_dimension_product_attributes' ) == 'yes' && ( $product->has_dimensions() || $product->has_weight() ) ) )
|
||||||
|
$tabs['additional_information'] = array(
|
||||||
|
'title' => __( 'Additional Information', 'woocommerce' ),
|
||||||
|
'priority' => 20,
|
||||||
|
'callback' => 'woocommerce_product_additional_information_tab'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Reviews tab - shows comments
|
||||||
|
if ( comments_open() )
|
||||||
|
$tabs['reviews'] = array(
|
||||||
|
'title' => sprintf( __( 'Reviews (%d)', 'woocommerce' ), get_comments_number( $post->ID ) ),
|
||||||
|
'priority' => 30,
|
||||||
|
'callback' => 'comments_template'
|
||||||
|
);
|
||||||
|
|
||||||
|
return $tabs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! function_exists( 'woocommerce_sort_product_tabs' ) ) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort tabs by priority
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function woocommerce_sort_product_tabs( $tabs = array() ) {
|
||||||
|
|
||||||
|
// Re-order tabs by priority
|
||||||
|
if ( ! function_exists( '_sort_priority_callback' ) ) {
|
||||||
|
function _sort_priority_callback( $a, $b ) {
|
||||||
|
if ( $a['priority'] == $b['priority'] )
|
||||||
|
return 0;
|
||||||
|
return ( $a['priority'] < $b['priority'] ) ? -1 : 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uasort( $tabs, '_sort_priority_callback' );
|
||||||
|
|
||||||
|
return $tabs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! function_exists( 'woocommerce_comments' ) ) {
|
if ( ! function_exists( 'woocommerce_comments' ) ) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue