WooCommerce: Get Product Info (ID, SKU, $) From $product Object

In WooCommerce, the $product object represents a single product, and it contains various information and methods that you can access to get details about the product. Here is a list of common product information that you can retrieve from the $product object:

1. Product ID: $product->get_id() – Returns the unique ID of the product.
2. Product Name: $product->get_name() – Returns the name/title of the product.
3. Product Type: $product->get_type() – Returns the product type (e.g., simple, variable, grouped, external).
4. Product SKU: $product->get_sku() – Returns the product SKU (Stock Keeping Unit).
5. Product Description: $product->get_description() – Returns the product description.
6. Product Short Description: $product->get_short_description() – Returns the short description of the product.
7. Product Regular Price: $product->get_regular_price() – Returns the regular price of the product.
8. Product Sale Price: $product->get_sale_price() – Returns the sale price of the product (if applicable).
9. Product Stock Quantity: $product->get_stock_quantity() – Returns the available stock quantity of the product.
10. Product Weight: $product->get_weight() – Returns the product weight.
11. Product Dimensions: $product->get_dimensions() – Returns the product dimensions (length, width, height).
12. Product Categories: $product->get_category_ids() – Returns an array of category IDs the product belongs to.
13. Product Tags: $product->get_tag_ids() – Returns an array of tag IDs assigned to the product.
14. Product Gallery Images: $product->get_gallery_image_ids() – Returns an array of gallery image IDs.
15. Product Featured Image: $product->get_image_id() – Returns the featured image ID.
16. Product Attributes: $product->get_attributes() – Returns an array of product attributes and their values.
17. Product Variations (for variable products): $product->get_available_variations() – Returns an array of available variations.
18. Product Rating: $product->get_average_rating() – Returns the average rating of the product.
19. Product Reviews Count: $product->get_review_count() – Returns the number of reviews for the product.
20. Product URL: $product->get_permalink() – Returns the URL of the product page.
21. Product Add to Cart URL: $product->add_to_cart_url() – Returns the URL to add the product to the cart.
22. Product Add to Cart Text: $product->add_to_cart_text() – Returns the text for the add to cart button.

These are just some of the commonly used properties and methods available in the $product object. Depending on the product type and installed plugins, there might be additional custom properties or methods specific to your setup. You can explore the complete list of available properties and methods in the official WooCommerce documentation or by using tools like var_dump() or print_r() to inspect the product object.

Leave a Comment

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