In WooCommerce, the $product
object allows you to retrieve various product details such as product ID, SKU, price, and more. Below is a comprehensive list of common methods to get essential product information:
Methods to Retrieve Product Information
- Product ID:
$product->get_id()
– Returns the unique product ID. - Product Name:
$product->get_name()
– Fetches the name/title of the product. - Product Type:
$product->get_type()
– Returns the product type (simple, variable, external, etc.). - Product SKU:
$product->get_sku()
– Retrieves the product’s SKU (Stock Keeping Unit). - Product Description:
$product->get_description()
– Fetches the full description of the product. - Product Short Description:
$product->get_short_description()
– Gets the short description for the product. - Product Regular Price:
$product->get_regular_price()
– Retrieves the regular price of the product. - Product Sale Price:
$product->get_sale_price()
– Fetches the sale price if the product is on sale. - Product Stock:
$product->get_stock_quantity()
– Returns the available stock quantity. - Product Weight:
$product->get_weight()
– Fetches the product’s weight. - Product Dimensions:
$product->get_dimensions()
– Retrieves the dimensions (length, width, height) of the product. - Product Categories:
$product->get_category_ids()
– Fetches a list of category IDs the product belongs to. - Product Tags:
$product->get_tag_ids()
– Returns a list of tag IDs associated with the product. - Product Images:
$product->get_gallery_image_ids()
– Retrieves the gallery image IDs for the product. - Product Featured Image:
$product->get_image_id()
– Gets the ID of the featured image for the product. - Product Attributes:
$product->get_attributes()
– Returns an array of the product’s attributes. - Product Variations:
$product->get_available_variations()
– Fetches available variations for variable products. - Product Rating:
$product->get_average_rating()
– Retrieves the product’s average rating. - Product Review Count:
$product->get_review_count()
– Returns the number of reviews the product has. - Product URL:
$product->get_permalink()
– Retrieves the product’s page URL. - Product Add to Cart URL:
$product->add_to_cart_url()
– Gets the URL to add the product to the cart. - Product Add to Cart Text:
$product->add_to_cart_text()
– Retrieves the “Add to Cart” button text.
Explore Further
For additional advanced features and functions, visit the official WooCommerce Documentation.
For a deeper dive into the $product object, use var_dump()
or print_r()
to examine all available properties and methods.