Friday, 23 May 2014

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.

2 Comments:

At 23 May 2014 at 04:30 , Blogger Yogesh Kumar said...

Example: Nexp_woocommerce_product_catID("Fashion Jewellery")

 
At 23 May 2014 at 04:30 , Blogger Yogesh Kumar said...

$ProdCat = Nexp_woocommerce_product_catID("Fashion Jewellery");

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home