Get product information in woocommerce (Product name, type, id, price, sku etc..)

In day to day development tasks we need specific product information to do some operations on it or else we have to show this information somewhere. But every time it take much time to find its functions and utilize it in our code. So this post is for you guys, if you have product id or object id then you can use below function list to get information according to it.

For example you can get product name, sku, description, price, quantity, downloads etc. Please go through below list of functions.

Product general information functions

$product = wc_get_product( $product_id );

get_permalink( $product->get_id() );

Product price related functions


Product stock and shipping related functions


Product link products and dimentions related functions



Product downloads, taxonomy and variations related functions




Product reviews and images related functions


get_the_post_thumbnail_url( $product->get_id(), 'full' );

Source :

How to use this functions :

To use this function you should have product id or order id or cart id. Using this id you can make object of product and then you can use above functions to perform operations as you want. Check below code to access these functions in a proper way.

// pass product id to wc_get_product() function to make product object
$product = wc_get_product( $product_id );

// by this $product object you can use its functions
//... and so on...

In order and cart it has many products collection will be there. so to get each product information we have to loop through access information of product. So we have to use WC_Order() to make object of order to get products first. Check below code :

// make order object first from order id
$order_object = new WC_Order( $order_id );

// get products from order object
$order_items = $order_object->get_items();

// loop through access order items and make product object to acess its functions
foreach ( $order_items as $order_item) {
    $product = wc_get_product( $order_item['product_id'] );
    // here you can get all information of each product
    //... and so on...

In a same way of order object we can get products from cart object. But this time we will get products from wc()->cart. Check below code :

// make cart object first from current cart data
$cart_data = WC()->cart->get_cart();
foreach( $cart_data as $cart_item ){
    $product = wc_get_product( $cart_item['product_id'] );
    // here you can get all information of each product
    //... and so on...

You can use this functions in your parent or child theme functions.php and other templates also. you can also use it in your wordpress plugin.

Conclusion :

As you can see, these functions are very help full to make customization in woo-commerce related functionality. It saves my time a lot to get all functions at one place and i hope it will save your time also. To make this article i followed some sources like You can also check this links to get more information related to woocommerce. I hope this information is useful to you. In future post we will see some more articles and features provided by woocommerce that saves our time. So stay connected with my blog to get useful stuff in simple way, and i will be more happy to get some feedback from you in comment section, and also share this post if you like and if it is useful for others. Thanks.

Related Posts

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.