Product Fix Category shortcode.php




/* Product Category Navigation*/ function product_categories( $atts ) { ob_start(); $term = get_queried_object(); $current_cat_id = $term->term_id; $terms = get_terms( array( 'taxonomy' => 'product_category', 'hide_empty' => false, 'orderby' => 'id', 'order' => 'DESC', ) ); echo '<div class="product-category-wrapper">'; echo '<ul class="category-items">'; echo '<li class="cat-item">'; echo '<a href="'.get_permalink(5305).'">All Products</a>'; echo '</li>'; foreach($terms as $term){ $term_link = get_term_link( $term, 'product_category' ); $term_name = $term->name; $active = ''; if($current_cat_id == $term->term_id) $active = 'active'; echo '<li class="cat-item '.$active.'">'; echo '<a href="'.$term_link.'">'.$term_name.'</a>'; echo '</li>'; } echo '</ul>'; echo '</div>'; return ob_get_clean(); } add_shortcode( 'product_categories', 'product_categories' );