Created
August 19, 2015 15:09
-
-
Save fuyuko/274f165ae02d6e380c01 to your computer and use it in GitHub Desktop.
WooCommerce Subcategory Content Template Overwrite - This template shows, subcategory's title, thumbnail, description, and its subcategries' links (and their subcategories links) Example Site: http://loadhook.wp3.cazbah.us/product-category/electric-chain-hoists/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* The template for displaying product category thumbnails within loops. | |
* | |
* Override this template by copying it to yourtheme/woocommerce/content-product_cat.php | |
* | |
* @author WooThemes | |
* @package WooCommerce/Templates | |
* @version 2.4.0 | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
global $woocommerce_loop; | |
// Store loop count we're currently on | |
if ( empty( $woocommerce_loop['loop'] ) ) { | |
$woocommerce_loop['loop'] = 0; | |
} | |
// Store column count for displaying the grid | |
if ( empty( $woocommerce_loop['columns'] ) ) { | |
$woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 4 ); | |
} | |
// Increase loop count | |
$woocommerce_loop['loop'] ++; | |
?> | |
<li <?php wc_product_cat_class(); ?>> | |
<?php do_action( 'woocommerce_before_subcategory', $category ); ?> | |
<a href="<?php echo get_term_link( $category->slug, 'product_cat' ); ?>"> | |
<?php | |
/** | |
* woocommerce_before_subcategory_title hook | |
* | |
* @hooked woocommerce_subcategory_thumbnail - 10 | |
*/ | |
do_action( 'woocommerce_before_subcategory_title', $category ); | |
?> | |
<h3> | |
<?php | |
echo $category->name; | |
//if ( $category->count > 0 ) | |
// echo apply_filters( 'woocommerce_subcategory_count_html', ' <mark class="count">(' . $category->count . ')</mark>', $category ); | |
?> | |
</h3> | |
<?php | |
/** | |
* woocommerce_after_subcategory_title hook | |
*/ | |
do_action( 'woocommerce_after_subcategory_title', $category ); | |
?> | |
</a> | |
<?php | |
echo $category->description; | |
//get subcategories | |
$args = array( | |
'hierarchical' => 1, | |
'show_option_none' => '', | |
'hide_empty' => 0, | |
'parent' => $category->term_id, | |
'taxonomy' => 'product_cat' | |
); | |
$subcategories = get_categories($args); | |
//echo subcategory links | |
if(!is_null($subcategories)){ | |
echo '<ul class="subcategories">'; | |
foreach($subcategories as $subcat){ | |
echo '<li><a href="/product-category/' . $subcat->category_nicename . '/">' . $subcat->name . '</a>'; | |
//get subcategories of the sub-category | |
$args = array( | |
'hierarchical' => 1, | |
'show_option_none' => '', | |
'hide_empty' => 0, | |
'parent' => $subcat->term_id, | |
'taxonomy' => 'product_cat' | |
); | |
$subchildren = get_categories($args); | |
if(!is_null($subchildren)){ | |
echo '<ul class="subcat-children">' . "\n"; | |
foreach($subchildren as $subchild){ | |
echo '<li><a href="/product-category/' . $subchild->category_nicename . '/">' . $subchild->name . '</a>' ."</li>\n"; | |
} | |
echo '</ul>'; | |
} | |
echo "</li>\n"; | |
} | |
echo '</ul>'; | |
} | |
do_action( 'woocommerce_after_subcategory', $category ); | |
?> | |
</li> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment