How can I detect whether current page is a product sub category page?
I’ve tried with the following but it will always print out “NO”
function is_subcategory($category = null) {
if (is_category()) {
if (null != $category){
$cat = get_category($category);
}else{
$cat = get_category(get_query_var('cat'),false);
}
if ($cat->parent == 0 ){
return false;
}else{
return true;
}
}
return false;
}
if (is_subcategory()){
echo "YES";
}else{
echo "NO";
}