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:
- Product ID:
$product->get_id()
- Product Name:
$product->get_name()
- Product Type:
$product->get_type()
- Product SKU:
$product->get_sku()
- Description:
$product->get_description()
- Short Description:
$product->get_short_description()
- Regular Price:
$product->get_regular_price()
- Sale Price:
$product->get_sale_price()
- Stock Quantity:
$product->get_stock_quantity()
- Weight:
$product->get_weight()
- Dimensions:
$product->get_dimensions()
- Category IDs:
$product->get_category_ids()
- Tag IDs:
$product->get_tag_ids()
- Gallery Images:
$product->get_gallery_image_ids()
- Featured Image:
$product->get_image_id()
- Attributes:
$product->get_attributes()
- Variations:
$product->get_available_variations()
- Average Rating:
$product->get_average_rating()
- Review Count:
$product->get_review_count()
- Product URL:
$product->get_permalink()
- Add to Cart URL:
$product->add_to_cart_url()
- 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.