2

I want to call product category name

when i tried this code

$product->get_categories(), 

it is calling categry name + link, can anyone help me to call only category name

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
CJ Junior
  • 31
  • 3

1 Answers1

0

Just add the follows code snippet in your active theme's functions.php to achieve the above -

function modify_porduct_cat_link( $links ) {
    if ( $links ) :
        $only_names = array();
        foreach ( $links as $link ) {
            $only_names[] = preg_replace( '#<a.*?>([^>]*)</a>#i', '$1', $link );
        }
        $links = $only_names;
    endif;
    return $links;
}
add_filter( 'term_links-product_cat', 'modify_porduct_cat_link', 99 );
itzmekhokan
  • 2,597
  • 2
  • 9
  • 9
  • this removes link from very category, what i need is in brand tag i want to show onyl category name. But adding this to function it removed links of categories everywhere. – CJ Junior Aug 19 '19 at 11:31
  • Then you have to do a condition check, if product belongs to brand tags only then it will enter into `if` condition else just return actual `$links` within the above function. – itzmekhokan Aug 19 '19 at 12:01