Monday, 22 February 2016

cash snatching 3

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; ?>" />

Get Product Category Link By Category Name In woocommerce

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

function Nexp_woocommerce_product_cat_link($CatName){

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


if($catTerm->name == $CatName)
{

return get_term_link( $catTerm);


} 

endforeach;  


}

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

Call the function :

$ProdCatLink = Nexp_woocommerce_product_cat_link("Fashion Jewellery");


Get Product Category Id By Category Name In woocommerce

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

function Nexp_woocommerce_product_catID($CatName){

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


if($catTerm->name == $CatName)
{

return $catTerm->term_id;


}

endforeach;

}


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