Add Product Brand in WooCommerce

Even though you can use product category feature of WooCommerce to organize your products, sorting products by brands was not there by default. Yes, there are few plugins out there that can get your job done but how about doing it by yourself without using any plugin? This is exactly what I did on one of my project.

The idea is fairly simple. All you need to do is to register a custom taxonomy that supports “product” post type. This is as simple as it can get. I won’t spend time explaining what is happening on the following snippet as in one of my previous post, I discussed on how to register a taxonomy for a default posts or a custom post type. So, here is the snippet.

// register product_brand taxonomy for woocommerce	
function add_product_brands(){
   register_taxonomy('product_brand',array('product'), array(
      'labels' => array(
         'name' => 'Brands',
	 'singular_name' => 'Brand',
	 'search_items' => 'Search Brands',
	 'all_items' => 'All Brands',
	 'parent_item' => 'Parent Brand',
	 'parent_item_colon' => 'Parent Brand:',
	 'edit_item' => 'Edit Brand', 
	 'update_item' => 'Update Brand',
	 'add_new_item' => 'Add New Brand',
	 'new_item_name' => 'New Brand',
	 'not_found' => 'No Brand Found',
	 'menu_name' => 'Brands'),
      'hierarchical' => true,
      'query_var' => true,
      'public' => true,
      'show_tagcloud' => true,
      'show_admin_column' => true,
      'show_in_nav_menus' => true,
      'sort' => '',
      'rewrite' => array('slug' => 'brand','with_front' => false),
      'show_ui' => true)); }
add_action('init','add_product_brands', 0);

Add this snippet on your current theme’s functions.php page and update it. Now you should see the “Brands” text sub menu item underneath the “Products” menu item.

Add Brands to WooCommerceAdding Brands to WooCommerce Products.

Now, you are ready to add as many brand as you want and associate them with your products.

At this point simply go ahead and try to add a product as you would used to do normally. Take a careful look on the right hand side of the screen. Right above the “Categories” (Product) widget, you should see the “Brands” widget that would allow you to select the brand associated with your products.

We are half way done and got few more things to cover before you can fully take the advantage of our works so far. Let’s move on and see what else we need to do.

List the Brands

Without displaying the list of Brands and their associated products, the whole effort would be useless. So, let’s display the list of Brands that has products associated with them. You should use the following snippet, wherever you think this list should be displayed.

// get all the brands with link
$brands = get_terms(array(
   'taxonomy' => 'product_brand',
   'hide_empty' => true)); 
echo '<ul>';
   foreach ($brands as $brand) { 
      echo '<li><a href="'.get_term_link($brand->slug, $brand->taxonomy).'">'.$brand->name.'</a></li>'; 
echo '</ul>';

Generally speaking though, this snippet should belong to somewhere in your template page. This is your turn to think and figure out where you should display this list. Also go ahead and use your CSS magic to style them.

Single Product Page

Now, when your potential customers are looking at the product (single product page), you may want to display the name of the the brand. This is one way to provide more information about your product. Here is the little snippet that you can add on your theme’s functions.php page and display the name of your product’s brand. This link on the brand names will take your visitor to the archive page of this particular brand.

// add single product brand with link
add_action('woocommerce_product_meta_start','display_brand_on_product_page', 10);
function display_brand_on_product_page(){
   global $product;
   echo '<span class="posted_in">'.get_the_term_list($product->get_id(),'product_brand','Brand: ','','','').'</span>';

You should be all set at this point.

I hope you would find this post to be very useful. Feel free to share this post and leave your questions(if any) from the comment section below. I will try to get back to you within the possible shortest time frame. Thank you.

Today In History




  1. Al aminPublished: 1 year ago

    How do I get the brands for filtering?

    • Iftekhar BhuiyanPublished: 6 months ago

      Similar to the idea of filtering products based on category. I am expecting to write on this regard at some point down the line. Thanks.

  2. Al aminPublished: 1 year ago

    It was really helpful. Thanks a lot.

    • Iftekhar BhuiyanPublished: 1 year ago

      You are Welcome.

  3. Richa AgrawalPublished: 3 years ago

    Thanks for the content. 🙂
    Really simple and easy to follow and works perfectly!

    • Iftekhar BhuiyanPublished: 3 years ago

      Really happy to know that you found this snippet useful. Thank you for stopping by.

  4. KarinePublished: 4 years ago


    Thanks for the code, it helped me a lot!
    While I’m on debug mode I get some errors :
    Notice: Undefined variable: wp_query
    Notice: Trying to get property ‘post’ of non-object
    Notice: Trying to get property ‘ID’ of non-object.
    But the brand still shows on the page… How can I make this right?

    Thanks again

  5. AleksandarPublished: 4 years ago

    Hi, The code works great. How can I add the brand link in the product page before title (or after title). Thanks

    • Iftekhar BhuiyanPublished: 4 years ago

      You can find various hooks used on single product page in WooCommerce. I could not find any specific hook that can manipulate contents exactly before or after the product title. The closest hook is woocommerce_single_product_summary which I assume is not what you are looking for. You can checkout the hooks from this page. Use the one that fits your requirements. Hope that helps. Thank you.

  6. PacificPublished: 4 years ago

    Thank you for share.
    I made the step config functions.php file and got the display in admin page and & single product page.
    But “List the Brands” is not currently displayed. What file do you put that code into? I want it to show on the sidebar page of the categories page and single product page.
    Thank you!

    • Iftekhar BhuiyanPublished: 4 years ago

      That should be on your “sidebar.php” page even though you can literally put that snippet anywhere you want. Hope that helps. Thanks.

  7. Jared JonesPublished: 4 years ago

    I was able to add the brands to my site but after adding the brands, I wanted to added collections. So I changed all words with Brands or brand for Collections or collection. I also input that in the functions.php file. Hoping you can tell me why it wouldn’t take. It actually took over for the brands code so I can’t have both codes in the functions.php file.

    • Iftekhar BhuiyanPublished: 4 years ago

      What I understand from your comment is that you want to have both the “Brand” and “Collection” taxonomy for your WooCommerce products. This is fairly easy and there are two methods how you can achieve that. I will show you the easies one. This should be useful.

      add_action('init','add_product_brand_and_collection', 0);
      function add_product_brand_and_collection(){
         register_taxonomy('product_brand','array('product')', array());
         register_taxonomy('product_collection','array('product')', array());

      Hope that helps. Thank you.

  8. Virgilio FloresPublished: 4 years ago

    Hello, thank you for the article. It worked great.
    But I have a question. I’m using ‘Product CSV Importer and Exporter’. How would you include this new brand taxonomy in the import/export file?

Leave a Reply

Note: Convet HTML, PHP, JavaScripts from HTMLify, before posting from comment section.
License: By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution. Please use your real name or a pseudonym (i.e., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.