How to call Primary Category for WordPress Woocommerce

As per WordPress Codex for the function

get_term_by( $field, $value, $taxonomy, $output, $filter );

If $value does not exist, the return value will be false. If $taxonomy exists and $field and $value combinations exist, the Term will be returned.

So, you need to check the value of $name in your code

$term = get_term_by('name', $name, 'product_cat');
$markup['brand']   = $term ;