Skip to content

Instantly share code, notes, and snippets.

@jubalm
Created January 19, 2017 00:16
Show Gist options
  • Save jubalm/471d8fd4bb8a2291b40279f9dc8731e7 to your computer and use it in GitHub Desktop.
Save jubalm/471d8fd4bb8a2291b40279f9dc8731e7 to your computer and use it in GitHub Desktop.
<?php $subCategories = get_term_children($queried_object->term_id, 'product_cat') ?>
<?php if($queried_object->post_type == 'page'): $categories = get_terms('product_cat'); ?>
<?php foreach($categories as $category): ?>
<?php if($category->count && ($category->parent == 0)): ?>
<h4><?php echo $category->name ?></h4>
<?php echo do_shortcode('[product_category category="' . $category->slug . '"]'); ?>
<?php endif; ?>
<?php endforeach; ?>
<?php elseif(count($subCategories)): ?>
<?php foreach($subCategories as $subCategory): $subTerm = get_term_by( 'id', $subCategory, 'product_cat' ); ?>
<?php if($subTerm->count): ?>
<h4><?php echo $subTerm->name ?></h4>
<?php echo do_shortcode('[product_category category="' . $subTerm->slug . '"]'); ?>
<?php endif; ?>
<?php endforeach; ?>
<?php else: ?>
<?php woocommerce_product_loop_start(); ?>
<?php woocommerce_product_subcategories(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
<?php do_action( 'woocommerce_after_shop_loop' ); ?>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment