How to get RankMath Primary Category name instead of ID?

I am using the parameter {cf_rank_math_primary_product_cat} in query loop of my product archive to call on the Primary Category set with RankMath plugin, but it only returns the ID of the category. I want the name of the category instead. How do I do this?

Put this in your functions.php

/**
 * Fetched category by id
 */
function get_primary_rankmath_category_rh($rhid, $is_link = false)
{  
    $term = get_term_by( 'id', $rhid, 'category' );
    return $is_link ? get_term_link($term->slug, 'category') : $term->name;
}

add_filter('bricks/code/echo_function_names', function () {
  return [
    'get_primary_rankmath_category_rh',
  ];
});

Now, go to bricks and use text link element inside a query loop.

For name use {echo:get_primary_rankmath_category_rh({cf_rank_math_primary_category})}

For link select dynamic data and use {echo:get_primary_rankmath_category_rh({cf_rank_math_primary_category}, true)}