Reputation: 264
I want to show a few products per product category on front page. I am able to show the products but can't get the product category name displayed using the slug.
Upvotes: 1
Views: 13299
Reputation: 264
Okay, This worked :
<?php
$product_cat_name = get_term_by( 'slug', 'slugname', 'product_cat' );
echo $product_cat_name->name;
?>
Upvotes: 4
Reputation: 944
You can find product category using this code... I have also added code to get woocommerce category image
$catTerms = get_terms('product_cat', array('hide_empty' => 0, 'orderby' => 'ASC'));
foreach($catTerms as $catTerm) : ?>
<?php $thumbnail_id = get_woocommerce_term_meta( $catTerm->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id ); ?>
<a href="<?php echo site_url();?>/product-category/<?php echo $catTerm->slug; ?>">
<img src="<?php echo $image; ?>"></a>
<a href="<?php echo site_url();?>/product-category/<?php echo $catTerm->slug; ?>"> <h2><img src="<?php echo $a['url']; ?>">
<?php echo $catTerm->name; ?></h2></a>
<?php endforeach; ?>
Upvotes: 1