How to Add Custom Taxonomy To WooCommerce Products

Add Custom Taxonomy To WooCommerce Products

Do you want to add a custom taxonomy to your WooCommerce products programmatically?

In this post, we will look at how you can create WooCommerce custom taxonomies using a code snippet we made specifically for this purpose.

WooCommerce, by default, comes with various fields for storing product data.

These fields include product name, long and short description, price, images, stock, weight, dimensions, and many more.

However, there is no way to store and display extra product data, such as WooCommerce custom taxonomies.

It is worth mentioning that ‘custom fields’ and ‘custom taxonomies’ are often mentioned, but many people do not know exactly the difference.

WooCommerce custom fields are used to store arbitrary, one-off information about a product. On the other hand, a custom taxonomy is used for grouping things together.

In the WordPress admin, custom fields appear in the main column of the Add/Edit Product screen.

However, custom taxonomies appear in the right-hand column under product categories and tags.

Add Custom Taxonomy To WooCommerce Products

By the end of this post, you will be able to create a custom taxonomy in your WooCommerce store.

This means that we will edit some of WooCommerce’s core files to achieve the desired result.

This means that you need to install or create a child theme. It will ensure that your changes are not lost during an update. You can also track all the changes you make easily.

Let us get right into it.

Steps to Add Custom Taxonomy To WooCommerce Products

Here are the simple steps you need to follow:

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file to add the function to add a custom taxonomy to WooCommerce products.
  3. Add the following code to the PHP file:
// Register Custom Taxonomy
function njengah_custom_taxonomy_Item() {
$labels = array(
'name' => 'Brands',
'singular_name' => 'Brand',
'menu_name' => 'Brands',
'all_items' => 'All Brands',
'parent_item' => 'Parent Brand',
'parent_item_colon' => 'Parent Brand:',
'new_item_name' => 'New Brand Name',
'add_new_item' => 'Add New Brand',
'edit_item' => 'Edit Brand',
'update_item' => 'Update Brand',
'separate_items_with_commas' => 'Separate Brand with commas',
'search_items' => 'Search Brands',
'add_or_remove_items' => 'Add or remove Brands',
'choose_from_most_used' => 'Choose from the most used Brands',
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
);
register_taxonomy( 'item', 'product', $args );
}
add_action( 'init', 'njengah_custom_taxonomy_item', 0 );

 

  1. This is the outcome:brands

Conclusion

In summary, we have shared a custom code snippet we created to add a custom taxonomy in WooCommerce. This is a great way to display extra product data making it easier for customers to find your products.

However, if you are unfamiliar with coding, we recommend using a plugin like WooCommerce Product Table.

This will ensure that you do not break your site. If you make any mistake, a critical error will be displayed on your site.

We hope that this post helped you to learn more about editing the Edit product page.

Similar Articles