The $product
object in WooCommerce is a powerful tool for developers, giving them access to a variety of product-related information. By using the methods available through the $product
object, you can fetch details such as the product ID, SKU, price, and much more.
Key Methods to Get Product Information
- Product ID:
$product->get_id()
– Get the unique ID of the product. - Product Name:
$product->get_name()
– Fetch the product’s name or title. - Product Type:
$product->get_type()
– Retrieve the type of product (simple, variable, etc.). - Product SKU:
$product->get_sku()
– Get the product’s unique SKU. - Product Description:
$product->get_description()
– Get the full description of the product. - Product Short Description:
$product->get_short_description()
– Get the short description of the product. - Product Regular Price:
$product->get_regular_price()
– Retrieve the product’s regular price. - Product Sale Price:
$product->get_sale_price()
– Retrieve the sale price if applicable. - Product Stock:
$product->get_stock_quantity()
– Retrieve the available stock quantity. - Product Weight:
$product->get_weight()
– Retrieve the weight of the product. - Product Dimensions:
$product->get_dimensions()
– Get the product’s dimensions (length, width, height). - Product Categories:
$product->get_category_ids()
– Retrieve category IDs associated with the product. - Product Tags:
$product->get_tag_ids()
– Get the tag IDs linked to the product. - Product Gallery:
$product->get_gallery_image_ids()
– Get the product’s gallery image IDs. - Product Featured Image:
$product->get_image_id()
– Retrieve the featured image ID. - Product Attributes:
$product->get_attributes()
– Get a list of attributes for the product. - Product Variations:
$product->get_available_variations()
– Fetch variations for variable products. - Product Rating:
$product->get_average_rating()
– Get the average rating of the product. - Product Reviews:
$product->get_review_count()
– Get the review count for the product. - Product URL:
$product->get_permalink()
– Retrieve the product page URL. - Product Add to Cart URL:
$product->add_to_cart_url()
– Get the add-to-cart URL for the product. - Product Add to Cart Text:
$product->add_to_cart_text()
– Get the add-to-cart button text.
Additional Resources
For a deeper dive into WooCommerce product information and advanced features, you can refer to the official WooCommerce Documentation.
Learn More
You can also explore the full WC_Product Class Reference to unlock more functionalities and details.