How to Find a WooCommerce Product ID (Step-by-Step)

Have you ever wanted to know a product ID in your WooCommerce store?

For every item you list in your WooCommerce shop, a unique identifier is assigned. This identifier often plays a critical role, especially when you want to feature a product or for other operational tasks.

This guide covers every way to find a WooCommerce product ID, including the WordPress admin UI, the URL, variation products, and PHP code for theme and plugin development.


What is a WooCommerce Product ID?

WooCommerce stores every product as a WordPress custom post type, which means each product gets a unique numeric ID assigned automatically (the same way every WordPress post or page does). The product ID is just the post ID for that product.

You’ll need to know a product’s ID for plenty of common WooCommerce tasks: passing it to a plugin shortcode that wants a specific product, hooking into a WooCommerce filter for one specific product, querying related orders, or grabbing it from a custom template you’re building.


How to Find a Product ID in WooCommerce

Finding a product ID in WooCommerce is straightforward.

First, navigate to the ‘Products’ section and select ‘All Products’. This area will display the recently added items in your store.

When you hover over a product title, a row of action links appears below it (Edit, Quick Edit, Trash, View). Right before those links, WooCommerce shows the product’s ID inline. For example, “ID: 26510” means 26510 is the product ID.

Product ID in WooCommerce

If your product list isn’t extensive, a quick scroll should reveal each product’s ID. For those with a more extensive inventory, the search feature will come in handy. You can also use the search in the product page to find an ID of a specific product.

You can also click the product’s Edit link. The URL of the edit screen contains the product ID as a post= query parameter, like /wp-admin/post.php?post=26510&action=edit.

Product ID in the admin dashboard URL

Finding a Product ID For a Variation Product in WooCommerce

Standard products have a singular ID, but what about products with multiple variations? In such cases, each variant carries its unique identifier.

Consider you’re offering a T-shirt in several shades: Red, Blue, Green. Each color variant will have a distinct ID.

variation IDs in WooCommerce

To find a variation’s ID: go to Products -> All Products, click Edit on the parent variable product, scroll to the Product Data section, and open the Variations tab. Each variation row has its ID displayed as a #NNNNN badge in the header.


Get Current Product ID (using PHP)

Several patterns depending on where you’re working in the WooCommerce code. Each one fits a different context.

In a Single-Product Template (the global $product object)

Inside any WooCommerce single-product template (single-product.php, content-single-product.php, or any template hooked into woocommerce_ actions on a product page), the global $product object is already populated:

global $product;
$product_id = $product->get_id();

If WordPress’s main loop has already started (the post is a product), get_the_ID() from WP core also returns the product ID since products are stored as posts:

$product_id = get_the_ID();

From Anywhere Using wc_get_product()

Outside the loop or in a custom plugin where you have an ID and want a fresh product object (or vice versa), use the modern WooCommerce CRUD helpers:

$product = wc_get_product( 26510 );

if ( $product ) {
    $product_id = $product->get_id();
    $product_name = $product->get_name();
    $product_price = $product->get_price();
}

Always check that wc_get_product() returned a product object before calling methods on it. It returns false if the ID doesn’t match any product (deleted, wrong post type, etc.) and calling methods on false will throw a fatal error.

By SKU: wc_get_product_id_by_sku()

If you have a SKU and need the product ID (common when integrating with an external inventory system or importing data), WooCommerce ships a built-in helper:

$product_id = wc_get_product_id_by_sku( 'TSHIRT-RED-LG' );

if ( $product_id ) {
    $product = wc_get_product( $product_id );
    // ...do something with the product
}

Returns 0 if no product matches the SKU. SKUs must be unique across the store for this to work reliably.

From an Order’s Line Items

When you have an order object and need the product IDs of every item in it (for analytics, inventory updates, or fulfillment scripts):

$order = wc_get_order( $order_id );

foreach ( $order->get_items() as $item_id => $item ) {
    $product_id = $item->get_product_id();
    $variation_id = $item->get_variation_id(); // 0 if not a variation
    $quantity = $item->get_quantity();
}

This pattern works the same whether your store uses the legacy post-meta order storage or High-Performance Order Storage (HPOS, default since WC 8.2). The CRUD methods abstract away the underlying table structure.

From the Current Cart

To grab product IDs from whatever’s in the customer’s cart right now (useful for upsells, conditional fees, abandoned-cart logic):

foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
    $product_id = $cart_item['product_id'];
    $variation_id = $cart_item['variation_id']; // 0 if not a variation
    $quantity = $cart_item['quantity'];
}

All Product IDs (Bulk Query)

For a one-off script or migration where you need every product ID in the store, query the products post type directly. Skip WP_Query here, the lighter get_posts() wrapper is faster for ID-only queries:

$product_ids = get_posts( array(
    'post_type'      => 'product',
    'post_status'    => 'publish',
    'posts_per_page' => -1,
    'fields'         => 'ids',
) );

The 'fields' => 'ids' argument is what makes this efficient. WordPress skips loading the full post objects and just returns an array of IDs. On a store with 5,000 products this is the difference between a 200ms query and a 5-second one.


Product ID vs SKU: What’s the Difference?

You’ll also notice that the UI in WooCommerce has an option to use a SKU. This is different than the product ID.

SKU stands for Stock Keeping Unit. It’s a merchant-defined identifier you set yourself for inventory or barcode management. Unlike the product ID (which WooCommerce assigns automatically when you create a product), the SKU only exists if you fill it in.

SKU in WooCommerce

Not every product needs an SKU, and many stores leave the field empty. Every product always has a unique product ID, whether you set anything else or not.


Frequently Asked Questions

Where is the WooCommerce product ID stored in the database?

It’s the ID column of the wp_posts table where the row’s post_type is product (or product_variation for individual variants). WooCommerce doesn’t have a separate products table; products are WordPress custom post types.

Can the product ID change?

No. Once WordPress assigns a product ID it stays the same for the life of the product, even if you change the product name, slug, SKU, price, or variations. The only way to “change” it is to delete the product and re-create it (which gives the new product a fresh ID).

Why does my variation ID differ from the parent product ID?

Each variation is stored as its own post with the product_variation post type, linked to the parent variable product. The variation gets its own unique ID. The parent variable product also has its own ID. Inside the order or cart, get_product_id() returns the parent ID and get_variation_id() returns the specific variation.

Does HPOS (High-Performance Order Storage) change how I get product IDs?

No, as long as you use the WooCommerce CRUD methods ($item->get_product_id(), $order->get_items(), etc.) instead of querying postmeta directly. HPOS changes the underlying storage but the CRUD API is stable across both. Direct postmeta queries against orders will break on HPOS-enabled stores.


That covers every common way to find a WooCommerce product ID. For more WooCommerce dev snippets, see our guides on get_post_meta() and WordPress hooks.

Picture of Andy Feliciotti

Andy Feliciotti

Andy has been a full time WordPress developer for over 15 years. Through his years of experience has built 100s of sites and learned plenty of tricks along the way. Found this article helpful? Buy Me A Coffee

Leave a Reply

Your email address will not be published. Required fields are marked *

WordPress Tips Monthly
Get the latest from SmartWP to your inbox.