WooCommerce: Easily Get Product Info (ID, SKU, $) from $product Object

I’ve been wanting to publish this guide for a long while. As a freelancer, every day I repeat many operations that make me waste time – and one of them is indeed “How to get ____ if I have the $product variable/object?”.

For example, “How can I get the product SKU”? Or “How can I get the product short description”? Or maybe the product stock level, shipping class, tax class, price, regular price, sale price, and so on… hopefully this article will save you time 🙂

1. You have access to $product

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 you’re in business. Alternatively, you can declare the “global $product” inside your function.

In both cases, here’s how to get all the product information:

// Get Product ID

$product->get_id(); (fixes the error: "Notice: id was called incorrectly. Product properties should not be accessed directly")

// 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


// Get Product Taxonomies


// Get Product Downloads


// Get Product Images


// Get Product Reviews


2. 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 to 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.

3. 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 = new WC_Order( $order_id );
$items = $order->get_items();

foreach ( $items as $item ) {

    $product = wc_get_product( $item['product_id'] );

    // Now you have access to (see above)...

    // etc.
    // etc.


4. 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.

// Get $product object from Cart object

$cart = WC()->cart->get_cart();

foreach( $cart as $cart_item ){

    $product = wc_get_product( $cart_item['product_id'] );

    // Now you have access to (see above)...

    // etc.
    // etc.


Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7+.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce Customization?

Check out these free video tutorials!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP

Rodolfo Melogli

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as a WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

39 thoughts on “WooCommerce: Easily Get Product Info (ID, SKU, $) from $product Object

  1. Super Hiflreich! Great Resource, thanks for sharing!!

    1. Great!

      1. WC()->cart->get_cart();

        in my website seems not being recognized.

        1. WooCommerce version?

  2. Not working anymore.
    I suppose they changed sintax with latest version.

    1. What’s not working Salvatore?

  3. how can i get total no of products which i have set initially..
    eg: i have set 100 in stock
    after each order it gets decreasing but i need initial total value of the product as i want to show it like this..
    x/y left
    x=remaining products
    y=total products
    please help

    1. Hi Tanish, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid this is custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  4. Variation and Simple:

    if( $cart_item['variation_id'] ){
    	$product = wc_get_product($cart_item['variation_id']);
    	$product = wc_get_product($cart_item['product_id']);	
    1. Thank you!

  5. Brilliant article, addresses all the core issues I’ve been searching for, for days! Thank you**********

    1. Excellent!

  6. Hi,

    How can I get product terms (category name only)?


    1. Hi Giang, thanks for your comment! You could use $product->get_category_ids() and then turn IDs into names 🙂

  7. Superb article. 🙂

    1. Thank you!

  8. Is it possible to get currency symbol in this way ? I’m using $product->get_price() but it return price without symbol, how can I pull Symbol. I use currency switcher and try to automated short description for each product. Your post helped me a lot. I just missing this currency symbol to be pulled automatically.

    1. Hey Przemyslaw, thanks for your comment! Try using get_woocommerce_currency_symbol(), this will give you what you want 🙂

  9. Is that okay if I get all the data separately (Title, Thumbnail, Price etc) and create my own template for WP template with WC?

    1. Of course Thas 🙂 Good luck!

  10. Hero!

    1. Thank you 🙂

  11. How can i get $product->get_categories(); without link only name?

    1. Hello Saagar – thanks so much for your comment! Once you get the categories, you can use something similar to this https://developer.wordpress.org/reference/functions/get_categories/#comment-333 to loop through the categories and just echo the name. Hope this helps

  12. While I install some plugin, it shows “post was called incorrectly. Product properties should not be accessed directly” error.
    May I ask where I should put “$product->get_id()” code?

    1. Hey Robin, thanks so much for your comment! It could be a plugin that is out of date, try disabling them one at a time to see which one is causing the error. Hope this helps!

  13. Number 3 was what I needed. Perfect!

    Thank You

  14. Nice Cheat Sheet…
    I think there are different method to make the list more complete, like getting categories linkes with

    let’s make the list more complete.. 😀

    1. Awesome, thanks Viktor 🙂

  15. Great article!

    smth function from me:

    $product->get_variation_price( 'min', true )
    $product->get_variation_price( 'max', true )
    $product->get_variation_regular_price( 'min', true )
    $product->get_variation_regular_price( 'max', true )
    $product->is_type( $type ) //checks the product type, string/array $type ( 'simple', 'grouped', 'variable', 'external' ), returns boolean
    1. also `$p->is_type(‘variation’)` is useful for iterating through product variations.

  16. Hi, im trying to do the next snippet:

    function ventascruzadas(){
      $cart = WC()->cart->get_cart();
      global $product;
    foreach( $cart as $cart_item ){
        $product = wc_get_product( $cart_item['product_id'] );
        // Now you have access to (see above)...
        $cross = $product->get_cross_sell_ids();
        // etc.
        // etc.
      echo "<h2>Puede que estés interesado en...</h2>";
      foreach($cross as $key => $value){
    	echo $value."<br>";

    but isn’t working, i don’t know if it fails because its cart page or i can’t use this variables here.
    Thanks for the help and sorry for my bad english (:

    1. Hola Sergi, thanks so much for your comment! Unfortunately this looks like custom troubleshooting work and I cannot help here via the blog comments. Thanks a lot for your understanding! ~R

  17. Number 1 & 2 broke but #3 worked for me using the StoreFront template.

    Thanks for all your help!!!!

    1. Uhm, ok, these are independent from the theme, but thank you for your feedback anyway Steve 🙂

Questions? Feedback? Support? Leave your Comment Now!

If you are writing code, please wrap it between: [php]code_here[/php]. Failure to complying with this (as well as going off topic) will result in comment deletion. You should expect a reply in about a week - this is a popular blog but I need to get paid work done first. Please consider joining #BloomerArmada to ask me 1-to-1 WooCommerce questions. Thank you :)

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.