Skip to main content

Overview

The WC_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

The WC_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, private
Whether product is featured
string
Catalog visibility: visible, catalog, search, hidden
string
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, onbackorder
string
Backorder setting: no, notify, yes
boolean
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

Always call $product->save() after making changes to persist them to the database.

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.

Additional Resources