Overview
TheWC_Product class is the foundation for all product types in WooCommerce. It provides methods to get and set product data, manage inventory, handle pricing, and more.
Always use
wc_get_product() to instantiate products rather than creating WC_Product objects directly.Getting a Product
Product Data Structure
TheWC_Product class stores product data in a protected $data array:
Basic Information
string
Product name/title
string
Product URL slug
string
Product status:
publish, draft, pending, privateboolean
Whether product is featured
string
Catalog visibility:
visible, catalog, search, hiddenstring
Full product description (HTML allowed)
string
Short product description
string
Stock keeping unit (unique identifier)
Pricing
string
Active price (regular or sale price)
string
Regular price
string
Sale price (if on sale)
WC_DateTime|null
Sale start date
WC_DateTime|null
Sale end date
Inventory
boolean
Whether stock is managed at product level
int|null
Current stock quantity
string
Stock status:
instock, outofstock, onbackorderstring
Backorder setting:
no, notify, yesboolean
Whether only one can be purchased per order
Physical Properties
string
Product weight
string
Product length
string
Product width
string
Product height
boolean
Whether product is virtual (no shipping)
boolean
Whether product is downloadable
Common Methods
Getting Product Data
Setting Product Data
Creating a New Product
Product Types
WooCommerce supports multiple product types:Simple Product
Variable Product
Grouped Product
External Product
Working with Metadata
Stock Management
Reducing Stock
Increasing Stock
Stock Status
Product Images
Product Attributes
Helper Functions
Get Product by SKU
Check if Product Exists
Delete Product
Hooks
Product Save Hooks
Product Data Filters
Best Practices
Use wc_get_product()
Always use
wc_get_product() to get products instead of directly instantiating.Save Changes
Always call
$product->save() after modifying product data.Check Product Exists
Verify
$product is not false before using it.Use Setters/Getters
Use getter/setter methods instead of accessing
$product->data directly.