How to Get Product Info (Price, ID, Name, Etc) from WooCommerce $product Object

You are currently viewing How to Get Product Info (Price, ID, Name, Etc) from WooCommerce $product Object

The WooCommerce $product object holds every piece of data that we need to work with products.

If you’re a WooCommerce developer, you’ll need to access some or all of that information at some point or another.

Whether you’re developing a plugin, theme, or just a code snippet, knowing how to get the relevant product information is the key to success.

Once you access the $product variable, you can use any class object method.

Some of the product data you can get from the $product object is the item name, order, ID, SKU, price, stock level, order notes, etc. We can retrieve complete information about the item simply by getting the $product object.

For example, when a customer asks us to create a code snippet to disable a payment method for a specific product, we need to check if the item exists on the cart page and conditionally execute the function based on true or false.

This was just one scenario out of many possibilities, and you can find many more in some of the most useful WooCommerce functions.

Now that we know how essential the product object is let’s discover how to get the data from it.

Get Data from the $product Variable

Some additional arguments are passed through the function when working with WooCommerce hooks (actions and filters).

If you can use the $product object as an argument in the function, you’re golden. However, if the process doesn’t accept it as an argument, you’ll need to define the ‘global $product’ inside it to access all the object’s methods.

Once you’re ‘in,’ here is the product’s data you can get.

Get Product ID:


Get Product General Info:

get_permalink( $product->get_id() );

Get Product Prices:

WooCommerce extensions


Get Tax, Shipping, and Stock:


Get Product Dimensions:


Get Similar / Linked Products:


Get Variations and Attributes:

$product->get_children(); // get variations
$product->get_attribute( 'attributeid' );

Get Product Taxonomies:


Get Product Downloads:


Get Product Images:


Get Product Reviews:


No $product Variable? No Worries!

If the hooks don’t accept the $product variable as is, you can still get to the object by adding another step.

The following sections will show how to retrieve the $product object from different variables and objects.

Access the $product Object from the $product_id

$product = wc_get_product( $product_id );
// etc.

Access the $product Object from the $order_id

$order = wc_get_order( $order_id );
$items = $order->get_items();
foreach ( $items as $item ) {
    $product = $item->get_product();
    // etc.

Access the $product Object from the Cart Object

$cart = WC()->cart->get_cart();
foreach( $cart as $cart_item_key => $cart_item ){
    $product = $cart_item['data'];
    // etc.

Access the $product Object from the $post Object

$product = wc_get_product( $post );
// etc.

Once you get into the $product object, you can use any of its methods from the first section.

Related Articles

  1. How to set a default variation in WooCommerce
  2. How to reorder products in WooCommerce
  3. How to hide the WooCommerce additional information tab
  4. WooCommerce: add back in stock notifications
  5. Best name your price plugins for WooCommerce
  6. How to change store currency in WooCommerce
  7. Add additional variation images in WooCommerce
  8. How to change the sale badge in WooCommerce


This article showed you how to access the WooCommerce $product object and use its data to expand the functionality of the WooCommerce plugin.

You can use it to develop a new plugin, theme, extension, or simple function.

Leave a comment and tell us what you use the $product object for or if you need further help.

Also, make sure to subscribe to our YouTube channel and like our page on Facebook.


PluginsForWP is a website specializing in redistributing WordPress plugins and themes with a variety of knowledge about WordPress, internet marketing, and blogging.

Leave a Reply