WooCommerce $product: Access Product Info with PHP

The $product object in WooCommerce provides developers access to all relevant product data. If you’re customizing WooCommerce templates or building advanced features, here’s a reference of what you can retrieve:

  1. ID: $product->get_id() – Get the product ID.
  2. Name: $product->get_name() – Title of the product.
  3. Type: $product->get_type() – Type (simple, variable, etc.).
  4. SKU: $product->get_sku()
  5. Description: $product->get_description()
  6. Short Desc: $product->get_short_description()
  7. Regular Price: $product->get_regular_price()
  8. Sale Price: $product->get_sale_price()
  9. Stock Qty: $product->get_stock_quantity()
  10. Weight: $product->get_weight()
  11. Dimensions: $product->get_dimensions()
  12. Categories: $product->get_category_ids()
  13. Tags: $product->get_tag_ids()
  14. Gallery: $product->get_gallery_image_ids()
  15. Featured Image: $product->get_image_id()
  16. Attributes: $product->get_attributes()
  17. Variations: $product->get_available_variations()
  18. Rating: $product->get_average_rating()
  19. Reviews: $product->get_review_count()
  20. Permalink: $product->get_permalink()
  21. Add to Cart URL: $product->add_to_cart_url()
  22. Cart Button Text: $product->add_to_cart_text()

These methods provide everything from basic details to advanced product metadata. If needed, inspect the full $product object using print_r() or var_dump(). This makes custom WooCommerce development more efficient and powerful.

 

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.