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.
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:
Example: Nexp_woocommerce_product_catID("Fashion Jewellery")
$ProdCat = Nexp_woocommerce_product_catID("Fashion Jewellery");
Post a Comment
Subscribe to Post Comments [Atom]
<< Home