Friday, 23 May 2014

Get Product Category Image By Category Name In woocommerce

Here is the function for category Image by Category Name in Woocommerce

function Nexp_woocommerce_product_cat($CatName){

$catTerms = get_terms( 'product_cat', array('hide_empty' => 0, 'orderby' => 'ASC'));
//print_r($catTerms);
foreach($catTerms as $catTerm) : 

if($catTerm->name == $CatName)
{
$thumbnail_id = get_woocommerce_term_meta( $catTerm->term_id, 'thumbnail_id', true ); 

// get the image URL
return $image = wp_get_attachment_url( $thumbnail_id );  ?>


<?php } endforeach;  


}


Place it in theme function.php file and call anywhere this function in the theme file.


Example:

$cat_Image = Nexp_woocommerce_product_cat("fashion jewellery");

<img src="<?php echo $cat_Image; ?>" />

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home