Home / Woo-Commerce / How to Display Product specific category with WooCommerce ?

How to Display Product specific category with WooCommerce ?

[tblock tcuscolor="#444" title="How to Display Product specific category with WooCommerce ?" tag="h3"/]
<?php

$cate = get_queried_object();
$cateID = $cate->term_id;

$args = array(
'hierarchical' => 1,
'show_option_none' => '',
'hide_empty' => 0,
'parent' => $cateID,
'taxonomy' => 'product_cat'
);
$subcats = get_categories($args);
foreach ($subcats as $sc) {
$link = get_term_link( $sc->slug, $sc->taxonomy );

?>

<ul class="products">
<?php
$args = array( 'post_type' => 'product','product_cat' => $sc->slug, 'posts_per_page' => 1000,);
$loop = new WP_Query( $args );
if ($loop->have_posts()) {
echo '<h1><a href="'. $link .'">'.$sc->name.'</a></h1>';
$i = 1;
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<?php

global $product, $woocommerce_loop,$wp_query;

?>
<li class="product">

<a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">

<?php woocommerce_show_product_sale_flash( $post, $product ); ?>

<?php

if (has_post_thumbnail( $loop->post->ID ))
echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog');
else
echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="300px" height="300px" />';

?>

<h3><?php the_title(); ?></h3>

<span class="price"><?php echo $product->get_price_html(); ?></span>

</a>

<?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>

</li>
<?php
//echo $i++;
endwhile;

?>

<?php } wp_reset_query(); ?>

</ul>

<?php } ?>

About admin

Check Also

Follow My Blog Post v1.8.1 – WordPress Plugin

Download Free Follow My Blog Post WordPress Plugin 1.8.1 – CodeCanyon | Follow My Blog Post v1.8.1 – WordPress Plugin allows your valued users to easily follow changes on a particular post/page for your WordPress site. By using this stunning tool visitors can opt to follow the page, post, tags, category, authors etc with or without creating a user account. […] Do you need any custome Development Click here and fill your requirement...

Leave a Reply

Your email address will not be published. Required fields are marked *