Q:

get_terms: determine if taxonomy term has children

I'm looking to determine if a taxonomy term has children.  See the below markup and I'll explain what I mean:
<? php
$terms = get_terms("wpsc_product_category");
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
    foreach( get_terms( 'wpsc_product_category', array( 'hide_empty' => false, 'parent' => 0 ) ) as $parent_term ) { ? >
    <li class="header-menu-item" data-hook="<?php echo $parent_term->slug; ? >">
        <a href="<?php echo home_url(); ? >/products/<?php echo $parent_term->slug; ? >"><? php echo $parent_term->name; ? ></a>                
    </li>
    <? php }
} ? >

So this outputs a list of all parent taxonomy terms for the wpsc_product_category taxonomy, but I want to determine if the taxonomy term has children or not, and if so add the parent class to the relevant header-menu-item so I can attach a jquery function to it.  I'm not sure if this is possible?  Any suggestions would be greatly appreciated! 

A:

The get_term_children function should help here.  
This returns an array, either with the child terms inside it, or empty.  Checking if this array is truthy or not as you loop through will then let you determine whether or not to add the class. 
<? php
    $terms = get_terms('wpsc_product_category');
    if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
    foreach( get_terms( 'wpsc_product_category', array( 'hide_empty' => false, 'parent' => 0 ) ) as $parent_term ) {
        $term_children = get_term_children($parent_term->term_id, 'wpsc_product_category'); ? >
        <li class="header-menu-item<?php echo ($term_children ? '  parent' : ''); ? >" data-hook="<?php echo $parent_term->slug; ? >">
            <a href="<?php echo home_url(); ? >/products/<?php echo $parent_term->slug; ? >"><? php echo $parent_term->name; ? ></a>                
        </li>
    <? php }
} ? >

