Your Dedicated Partner for All Things WordPress

How to Get WooCommerce Category ID

Table of Contents

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!

How to get started?

Learn more

WooCommerce Maintenance

Save 33% with our Annual pricing plan.

Get Started

Looking for help? Chat with us.

Are you in need of assistance or guidance? Look no further! Our dedicated team is here and ready to help. Chat with us today and let’s work together to find the perfect solution for your needs.

Our support team will get you:

I believe every website owner deserves a reliable professional support always by their side.

Alexey Seryapin
Founder of WPServices

Having Troubles With WordPress?

Claim Your Free WordPress Maintenance

In today’s fast-paced digital landscape, every website deserves the care and expertise of a professional maintenance team, ensuring optimal performance, enhanced security, and seamless user experiences, so you can focus on growing your business with peace of mind.

Alexey Seryapin
Founder of WPServices

Coupon Code Applied!

Take your time and continue browsing our services.

Alexey Seryapin
Founder of WPServices