How do I check if the user is on a taxonomy term parent, child or grandchild page?

Try get_ancestors():

$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );

$ancestors = get_ancestors( $term->term_id, 'product_range', 'taxonomy' );

$hierarchy_levels = count( $ancestors );

switch ( $hierarchy_levels ) {
    case 0:
        // THIS IS THE PARENT CATEGORY
        // DO YOUR STUFF
        break;

    case 1:
        // THIS IS THE PARENT CATEGORY
        // DO YOUR STUFF
        break;

    case 2:
        // THIS IS THE PARENT CATEGORY
        // DO YOUR STUFF
        break;
}

Another solution (but constraining) would be determining which hierarchy the user is currently on based on the url structure. The constraint would be that you have to keep a “simple” or “classical” hierarchy structure in your category URLs, as follow:

  • https://example.com/parent/child/grandchild/
  • https://example.com/parent/child/
  • https://example.com/parent/

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)