Category widget hierarchy on single product page
This commit is contained in:
parent
82056f1f8a
commit
e9c94cd2e8
|
@ -103,6 +103,7 @@ Yes you can! Join in on our GitHub repository :) https://github.com/woothemes/wo
|
|||
* Notice is now shown in admin when the configuration may cause permalink errors
|
||||
* Trigger 'change' event on the hidden variation_id input
|
||||
* Load non-minified woocommerce.js file if SCRIPT_DEBUG is on
|
||||
* Category widget hierarchy on single product page
|
||||
|
||||
= 1.4.3 - 16/02/2012 =
|
||||
* Fix for variation shipping class detection
|
||||
|
|
|
@ -80,7 +80,7 @@ class WooCommerce_Widget_Product_Categories extends WP_Widget {
|
|||
|
||||
} elseif ( $s ) {
|
||||
|
||||
global $wp_query;
|
||||
global $wp_query, $post;
|
||||
|
||||
$cat_args['title_li'] = '';
|
||||
$cat_args['hierarchical'] = 1;
|
||||
|
@ -89,12 +89,23 @@ class WooCommerce_Widget_Product_Categories extends WP_Widget {
|
|||
|
||||
$cats = get_terms( 'product_cat', apply_filters('woocommerce_product_categories_widget_args', $cat_args) );
|
||||
|
||||
$this->current_cat = false;
|
||||
$this->cat_ancestors = array();
|
||||
|
||||
if (is_tax('product_cat')) :
|
||||
|
||||
$this->current_cat = $wp_query->queried_object;
|
||||
$this->cat_ancestors = get_ancestors( $this->current_cat->term_id, 'product_cat' );
|
||||
else :
|
||||
$this->current_cat = false;
|
||||
$this->cat_ancestors = array();
|
||||
|
||||
elseif (is_singular('product')) :
|
||||
|
||||
$product_category = wp_get_post_terms( $post->ID, 'product_cat' );
|
||||
|
||||
if ($product_category) :
|
||||
$this->current_cat = end($product_category);
|
||||
$this->cat_ancestors = get_ancestors( $this->current_cat->term_id, 'product_cat' );
|
||||
endif;
|
||||
|
||||
endif;
|
||||
|
||||
echo '<ul>';
|
||||
|
@ -106,7 +117,7 @@ class WooCommerce_Widget_Product_Categories extends WP_Widget {
|
|||
|
||||
echo '<li class="cat-item cat-item-'.$cat->term_id;
|
||||
|
||||
if (is_tax('product_cat', $cat->slug)) echo ' current-cat';
|
||||
if ($this->current_cat->term_id == $cat->term_id || is_tax('product_cat', $cat->slug)) echo ' current-cat';
|
||||
if (
|
||||
$this->current_cat
|
||||
&& in_array( $cat->term_id, $this->cat_ancestors )
|
||||
|
@ -163,7 +174,7 @@ class WooCommerce_Widget_Product_Categories extends WP_Widget {
|
|||
|
||||
echo '<li class="cat-item cat-item-'.$child->term_id;
|
||||
|
||||
if (is_tax('product_cat', $child->slug)) echo ' current-cat';
|
||||
if ($this->current_cat->term_id == $child->term_id || is_tax('product_cat', $child->slug)) echo ' current-cat';
|
||||
if (
|
||||
$this->current_cat
|
||||
&& in_array( $child->term_id, $this->cat_ancestors )
|
||||
|
|
Loading…
Reference in New Issue