Retrieve Product Details from WooCommerce $product Object

In WooCommerce, the $product object holds all the essential details about a product. Whether you’re building a custom function or customizing templates, here’s a handy guide to the most commonly used properties and methods available from the $product object:

  1. Product ID: $product->get_id()
  2. Product Name: $product->get_name()
  3. Product Type: $product->get_type()
  4. Product SKU: $product->get_sku()
  5. Description: $product->get_description()
  6. Short Description: $product->get_short_description()
  7. Regular Price: $product->get_regular_price()
  8. Sale Price: $product->get_sale_price()
  9. Stock Quantity: $product->get_stock_quantity()
  10. Weight: $product->get_weight()
  11. Dimensions: $product->get_dimensions()
  12. Category IDs: $product->get_category_ids()
  13. Tag IDs: $product->get_tag_ids()
  14. Gallery Images: $product->get_gallery_image_ids()
  15. Featured Image: $product->get_image_id()
  16. Attributes: $product->get_attributes()
  17. Variations: $product->get_available_variations()
  18. Average Rating: $product->get_average_rating()
  19. Review Count: $product->get_review_count()
  20. Product URL: $product->get_permalink()
  21. Add to Cart URL: $product->add_to_cart_url()
  22. Add to Cart Text: $product->add_to_cart_text()

These methods help you retrieve just about any product-related data you need. You can inspect the full object using var_dump($product) or print_r($product) for custom debugging. Refer to the WooCommerce Developer Docs for more in-depth reference.

 

Leave a Comment

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

Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.