Format Brand value in Category view [closed]

I was managed to add “Brand name” to the category view list in the spot between image and category name (or product name). The code I have used is below.

The problem:

  1. How can I remove the link from the brand (href part), so it is not clickable? Only product title should be clickable to open product details.
  2. How can I apply a style to the Brand value? Ideally I want to use
    same style/color used for the category label in the category view.

The code:

function pwb_show_brands_in_loop(){
 global $product;
 $product_id = $product->id;
 $product_brands =  wp_get_post_terms($product_id, 'pwb-brand');
 if(!empty($product_brands)){
      echo '<div class="custom-loop-brands">';
      foreach ($product_brands as $brand) {
           echo '<a href="'.get_term_link($brand->term_id).'">'.$brand->name.'</a>';
      }
      echo '</div>';
 }

}
add_action(‘woocommerce_before_shop_loop_item_title’, ‘pwb_show_brands_in_loop’,1);

1 Answer
1

If i’m understood properly, you just have to remove the anchor from your code. Simply use:

echo $brand->name;

Instead of:

echo '<a href="'.get_term_link($brand->term_id).'">'.$brand->name.'</a>';

This will just echo the name of your brand. If you want to style it, you can add a class to it as the following:

echo '<span class="my-brand">'.$brand->name.'</span>';

And then use the proper style in your CSS file to style it. Such as:

.my-brand {
    color:#ddd;
}

Leave a Comment