How to display woo-commerce product category name image and link by custom query

How to display woo-commerce product category name image and link by custom query

How to display woo-commerce product category name image and link by custom query

How to display WordPress woo-commerce product category image, name and category link by using a custom wordpress query or function. View the blew image if you want to show this product category image so this post is for you.

We can show this product category by woo-commerce shortcod and custom query also..

Just use this short code it will show all categories.

[product_categories number="0" parent="0"]

Just place this short code using wordpress php function

<?php echo do_shortcode('[product_categories number="0" parent="0"]');?>

Now we see how to display all categories by using custom query. Here i give you the function with a loop, this will show all woocommerce product category

/*get woocommerce category name image link*/
   <?php
	$prod_categories = get_terms( 
		'product_cat', array(
		'orderby'    => 'name',
		'order'      => 'ASC',
		'hide_empty' => true
	));

     foreach( $prod_categories as $prod_cat ) :
	$cat_thumb_id = get_woocommerce_term_meta( $prod_cat->term_id, 'thumbnail_id', true );
	$shop_catalog_img = wp_get_attachment_image_src( $cat_thumb_id, 'shop_catalog' );
	$term_link = get_term_link( $prod_cat, 'product_cat' );?>

	<div class="item category-banner">
		<div class="category-img">
			<a href="<?php echo $term_link;?>" class="cat-img">
				<img src="<?php echo $shop_catalog_img[0]; ?>" alt="<?php echo $prod_cat->name; ?>">
			</a>
		</div>
		<div class="category-details">
			<a class="name" href="<?php echo $term_link;?>"><?php echo $prod_cat->name; ?></a>
			<a class="shop-now" href="<?php echo $term_link;?>">Shop Now</a>
		</div>
	</div>

  <?php endforeach; wp_reset_query();?>

When you use this wordpress woocommerce function it will show all categories as blew image.



Related Jobs

Comments


  • wordpress
  • woo-commerce
  • woocommerce category
  • how to display category
  • product category display
  • show woocommerce category only