Woocommerce Muestra el archivo por categorías, cata categoría linkea a su categoría hija hasta llegar al producto.
<?php
$parentid = get_queried_object_id();
$args = array(
'parent' => $parentid,
'childless' => false,
'hide_empty' => false,
'orderby' => 'count',
//'child_of' => 15,
//'fields' => 'all',
);
$terms = get_terms( 'product_cat', $args );
//print_r($parentid);
//print_r($terms);
if ( $terms ) {
foreach ( $terms as $term ) {
?>
<p>
<a href="<?php echo get_term_link( $term ); ?>" class="<?php echo $term->slug; ?>">
<?php echo $term->name; ?> <?php echo $term->count; ?>
</a>
</p>
<?php $term_name = $term->name; ?>
<?php if( $term->count != 0 ) : ?>
<?php $args = array(
'post_type' => 'product',
'category_name' => $term_name,
);
$wp_query = new WP_Query( $args ); ?>
<?php endif; ?>
<?php
}
}
$with_children = get_term_children( $parentid, 'product_cat' );
if( ! $with_children ) :
if ( have_posts() ) : while( have_posts() ) : the_post();
//the_title();
$tags = get_the_terms( $post->ID, 'product_tag' );
foreach ( $tags as $tag ) {
?>
<a href="<?php the_permalink(); ?>">
<?php echo $tag->name; ?>
</a>
<?php
}
//print_r($tags);
echo '<br>';
endwhile; else : if( !is_shop() ) : echo 'aún no hay productos'; endif; endif;
endif;
?>