3 minutes

How to Get WooCommerce Category ID

Let us take a look at how to find the WooCommerce category ID. In web development, you might want to display your products category on the front-end via a shortcode or just highlight a specific cluster of goods, so it is important to understand how to identify the ID posthaste. Thankfully, finding the WooCommerce category ID is rather straightforward. We will have a look at the most common methods for accomplishing this task.

WooCommerce Category ID via URL

The simplest approach to identify the ID is from your WordPress dashboard URL. Start with locating the Products tab in your dashboard, click on it and open the Categories window.

products categories woocommerce id

Now, pick a category from your list and open it.

edit woocommerce category

Have a glance at the URL in your web browsers tab. Identify a string like this one: tag_ID=21. In our case, the WooCommerce category ID is 21.

WooCommerce category id url

That is it, look how easy it was. Indeed, there is no need to involve coding if the number of categories is small or if you do not need to extract additional data from categories.

WooCommerce Category IDs via PHP Query

As we mentioned before, you might want to get all WooCommerce category IDs with a single action. With knowledge in coding and PHP queries, you can obtain this information by calling upon a function to display this information. Start with locating the Theme File Editor under the Appearance tab in your dashboard.

theme file editor functions.php

Always use the child theme for your modification purposes. It is a necessary practice to avoid conflicts within the code and keep the main themes files safe. Now, open the functions.php file and paste the following code.

// Get Current Category ID WooCommerce
add_action('wp_head', 'get_current_category_id');
function get_current_category_id(){
$current_category_object = get_queried_object();
echo $current_category_object->term_id;

The PHP query will display the category ID on top of the page. You will be able to see the particular category the specific product has.

Final Words

Even though there are various ways of finding the WooCommerce category ID that involve coding, in most cases, it is not necessary. With a few simple clicks of a button, you will be able to get the category ID almost instantly. If you do decide to implement solutions that involve tinkering with theme files, then keep in mind to take precautions against possible code conflicts. We wish you a bug-free journey through the world of eCommerce, and stay tuned for more articles!


(0 Reviews)

Alexey Seryapin

Alexey is a WordPress wizard with 10+ years of experience as a lead developer, He has launched 500+ WordPress websites and 100+ WooCommerce shops.

KEEP YOUR ONLINE SHOP SAFE WooCommerce Maintenance Service

Save 17% with our Annual pricing plan.

Has your website been hacked?

WordPress Malware Removal Service

We will fix any WordPress hack and make your website hackproof.

Related Posts


How to Add Keywords to Your WordPress Website


How to Track Visitors on Your WordPress Site


How to Find Out What WordPress Template You’re Using


Uninstalling Jetpack from WordPress: Step-by-Step Guide