Posted on

WooCommerce – How to Get Product ID, SKU, Price from $product Object?

This article lists down some codes to get product ID, SKU, price, category and other product details in WooCommerce. And also how to manage all these WooCommerce products from one place.

Last updated on April 30, 2024

How to get the WooCommerce product ID? How to get the product SKU? Or how to get the product’s regular price, sale price, stock, shipping class, tax class, images, dimensions, attributes, categories and other product details?

If you are a techie, I will phrase it as “How to get ____ if I have the $product object/variable?”

You need to get the product ID and other details to accomplish various store operations like fetching which products were present in an order, applying advanced product filters, editing prices and description, etc.

This article lists down some codes you can use to get product by ID, product by category, product by price, and other details in WooCommerce to tick off your stock management tasks.

You will also learn how you can manage all your WooCommerce products, orders, coupons, any WordPress custom post type data from one place, thus increasing your store productivity 10x.

Getting product info from $product object via code

Not always do you have access to the $product object (I’m talking about WooCommerce hooks for example). Understand your case and see if you can “get” that $product object in another way.

In this case, you have to find a way to “get the $product object from $product_id”.

Other examples might be the order page or the cart page. Here you don’t really have a $product available, so you have to loop through the order/cart items and get it. After that, you can then calculate and get any piece of information you require out of $product.

You have access to $product variable

Hooks (do_action and apply_filters) use additional arguments which are passed on to the function. If they allow you to use the “$product” object, it’s great. Alternatively, you can declare the “global $product” inside your function.

In both cases, this is how you get all the product information:

// Get Product ID
// Get Product General Info
get_permalink( $product->get_id() );
// Get Product Prices
// Get Product Tax, Shipping & Stock
// Get Product Dimensions
// Get Linked Products
// Get Product Variations and Attributes
$product->get_children(); // get variations
$product->get_attribute( 'attributeid' ); //get specific attribute value
// Get Product Taxonomies
// Get Product Downloads
// Get Product Images
// Get Product Reviews

You have access to $product_id

If you have access to the product ID (once again, usually the do_action or apply_filters will make this possible for you), you have to get the product object first. Then, do the exact same things as above.

// Get $product object from product ID
$product = wc_get_product( $product_id );
// Now you have access to (see above)...
// etc.
// etc.

You have access to the Order object or Order ID

How to get the product information inside the order? In this case, you will need to loop through all the items present in the order and then apply the rules above.

// Get $product object from $order / $order_id
$order = wc_get_order( $order_id );
$items = $order->get_items();
foreach ( $items as $item ) {
    $product = $item->get_product();
    // Now you have access to (see above)...
    // etc.
    // etc.

Also read – How to get additional info out of the $order object.

You have access to the Cart object

How to get the product information inside the cart? In this case, once again, you will need to loop through all the items present in the cart and then apply the rules above. If you wish to expand your WooCommerce PHP knowledge, here’s another article on how to get additional info out of the $cart object.

// Get $product object from Cart object
$cart = WC()->cart->get_cart();
foreach( $cart as $cart_item_key => $cart_item ){
    $product = $cart_item['data'];
    // Now you have access to (see above)...
    // etc.
    // etc.

You have access to $post object

In certain cases (e.g. the WordPress admin side or backend) you can only get access to $post. So, how do we “calculate” $product from $post? Easy peasy:

// Get $product object from $post object
$product = wc_get_product( $post );
// Now you have access to (see above)...
// etc.
// etc.

How do I find product ID in WooCommerce without coding?

You can also get product ID in WooCommerce using three simple ways:

WordPress backend

  1. Log in to your WordPress Admin panel dashboard.
  2. Click on Products > All Products.
  3. Hover on each product row and you’ll get the product ID.
get product id from WordPress backend

Edit product URL

Open any product to edit. You’ll find the product ID in the URL as “post=X”.

product id in url

Smart Manager plugin

The first two ways are time-consuming as you need to open each product or search and hover over a product to get the ID.

But with Smart Manager, you get all your product information – ID, stock, price, additional details, SKU…tons of details in one place in an Excel-like sheet editor.

WooCommerce get product ID sku price category details at one place

How to better manage WooCommerce stock / inventory with Smart Manager?

Featured images for products, regular price, sale price, additional information, SKU, categories, attributes…you can manage and bulk edit product details using Smart Manager. Hours of tasks within minutes or seconds.

Simple products, variable products and variations, affiliate products…it works for all.

Here’s how Smart Manager plugin simplifies product management:

  • Add any number of new products to your stock database directly.
  • Enable or disable the ‘Manage stock’ for each product.
  • Manage and edit SKU, stock status, regular price, sale price for each.
  • Edit product description, tax status.
  • Add Tax status, Tax class, Shipping class, features images, product thumbnails for each product. Add attributes, edit categories and product status.
  • Increase or decrease sale price by X% or amount of regular price for all or selected stock
  • Bulk edit stock status, inventory, etc.
  • Set the sale price based on the product’s regular price using bulk edit.
  • Perform operations like append, prepend, increase, decrease, set to, copy from, etc. using bulk edit.
  • Add attributes to hundreds of products at once using bulk edit
  • Real-time stock updates – stock quantity updates automatically when sale is made.
  • Manage backorders.
  • Filter stock based on stock status, SKU, price, etc. Apply OR, AND or a combination of both conditions to fetch desired results amongst thousands of items.
  • Get predefined custom views. View only required stock-related data columns and hide all other columns to focus only on your stock or inventory-related metrics. Also sort products by name, SKU, price, etc. before making an export.
  • Export only those stock data as CSV which you need. Like the name and stock quantity. These will let people at your shop or warehouse know which product needs quick replenishment, which product stock is slow-moving, etc.
  • Delete individual stock, using filters and using bulk edit. Learn more about how to delete all products safely.
  • Manage stock fields added by custom plugins

Smart Manager is compatible with these top WooCommerce plugins – WooCommerce Subscriptions, Bookings, Memberships, Product Add-Ons, Cost of Goods.

You can easily manage all stock and product fields added by these plugins. Like products, you can also manage and bulk edit orders, coupons, posts, pages, users, any WordPress post type.

Try Smart Manager live demo


If you love coding and are well-versed with hooks and filters, you can take the coding approach to get product info as and when required.

To view and manage hundreds and thousands of products from a single place, do bulk edit, export, delete, duplicate and other store operations quickly, use Smart Manager plugin. You won’t regret your purchase.


How do I get the product by SKU in WooCommerce?
When you go to wp-admin→Products→Your Product and edit the product you will see its configuration. Once you click on the edit option, you find all the available settings for that individual product. Scroll down and click on the inventory and there will be the option to set a WooCommerce product SKU.

Can I find a product ID with SKU number?

Where I can find product ID in WooCommerce?
Product IDs can be found in the “All Products” section of the WooCommerce dashboard or in the product’s URL in the address bar when editing the product.

How do I get the product image from a product ID in WooCommerce?
All you need to do is use the WordPress wp_get_attachment_url() function. The wp_get_attachment_url() function accepts an attachment ID as its only parameter. So all you need to do is pass in the product ID, and you’ll be able to get the URL of the product image.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.