WooCommerce Code Reference

WC_Product_Variable extends WC_Product

Variable product class.

The WooCommerce product class handles individual product data.

Table of Contents

$cache_group  : string
Stores meta in cache for future reads.
$changes  : array
Core data changes for this object.
$children  : array
Array of children variation IDs. Determined by children.
$data  : array
Core data for this object. Name value pairs (name + default value).
$data_store  : object
Contains a reference to the data store for this class.
$default_data  : array
Set to _data on construct so we can track and reset data if needed.
$extra_data  : array
Extra data for this object. Name value pairs (name + default value).
$id  : int
ID for this object.
$meta_data  : array
Stores additional meta data.
$object_read  : bool
This is false until the object is read from the DB.
$object_type  : string
This is the name of this object type.
$post_type  : string
Post type.
$supports  : array
Supported features such as 'ajax_add_to_cart'.
$variation_attributes  : array
Array of variation attributes IDs. Determined by children.
$visible_children  : array
Array of visible children variation IDs. Determined by children.
__clone()  : mixed
When the object is cloned, make sure meta is duplicated correctly.
__construct()  : mixed
Default constructor.
__get()  : mixed
Magic __get method for backwards compatibility. Maps legacy vars to new getters.
__isset()  : bool
Magic __isset method for backwards compatibility. Legacy properties which could be accessed directly in the past.
__sleep()  : array
Only store the object ID to avoid serializing the data object instance.
__toString()  : string
Change data to JSON format.
__wakeup()  : mixed
Re-run the constructor with the object ID.
add_meta_data()  : mixed
Add meta data.
add_to_cart_description()  : string
Get the add to cart button text description - used in aria tags.
add_to_cart_text()  : string
Get the add to cart button text.
add_to_cart_url()  : string
Get the add to url used mainly in loops.
adjust_price()  : mixed
Adjust a products price dynamically.
apply_changes()  : mixed
Merge changes with data and clear.
backorders_allowed()  : bool
Returns whether or not the product can be backordered.
backorders_require_notification()  : bool
Returns whether or not the product needs to notify the customer on backorder.
check_stock_status()  : mixed
Check if the stock status needs changing.
child_has_dimensions()  : bool
Does a child have dimensions set?
child_has_weight()  : bool
Does a child have a weight set?
child_is_in_stock()  : bool
Is a child in stock?
child_is_on_backorder()  : bool
Is a child on backorder?
delete()  : bool
Delete an object, set the ID to 0, and return result.
delete_meta_data()  : mixed
Delete meta data.
delete_meta_data_by_mid()  : mixed
Delete meta data.
enable_dimensions_display()  : bool
Returns whether or not we are showing dimensions on the product page.
exists()  : bool
Returns whether or not the product post exists.
get_attribute()  : string
Returns a single product attribute as a string.
get_attributes()  : array
Returns product attributes.
get_availability()  : string[]
Returns the availability of the product.
get_available_variation()  : array|bool
Returns an array of data for a variation. Used in the add to cart form.
get_available_variations()  : array[]|\WC_Product_Variation[]
Get an array of available variations for the current product.
get_average_rating()  : float
Get average rating.
get_backorders()  : string
Get backorders.
get_catalog_visibility()  : string
Get catalog visibility.
get_categories()  : string
Returns the product categories.
get_category_ids()  : array
Get category ids.
get_changes()  : array
Return data changes only.
get_child()  : WC_Product|WC_Product_variation
Returns the child product.
get_children()  : array
Return a products child ids.
get_cross_sell_ids()  : array
Get cross sell IDs.
get_cross_sells()  : array
Returns the cross sell product ids.
get_data()  : array
Returns all data for this object.
get_data_keys()  : array
Returns array of expected data keys for this object.
get_data_store()  : object
Get the data store.
get_date_created()  : WC_DateTime|null
Get product created date.
get_date_modified()  : WC_DateTime|null
Get product modified date.
get_date_on_sale_from()  : WC_DateTime|null
Get date on sale from.
get_date_on_sale_to()  : WC_DateTime|null
Get date on sale to.
get_default_attributes()  : array
Get default attributes.
get_description()  : string
Get product description.
get_dimensions()  : string|array
Returns formatted dimensions.
get_display_price()  : string
Returns the price including or excluding tax, based on the 'woocommerce_tax_display_shop' setting.
get_download_expiry()  : int
Get download expiry.
get_download_limit()  : int
Get download limit.
get_downloadable()  : bool
Variable products themselves cannot be downloadable.
get_downloads()  : array
Get downloads.
get_extra_data_keys()  : array
Returns all "extra" data keys for an object (for sub objects like product types).
get_featured()  : bool
If the product is featured.
get_file()  : array|false
Get a file by $download_id.
get_file_download_path()  : string
Get file download path identified by $download_id.
get_files()  : array
Same as get_downloads in CRUD.
get_formatted_name()  : string
Get product name with SKU or ID. Used within admin.
get_formatted_variation_attributes()  : string
Get formatted variation data with WC < 2.4 back compat and proper formatting of text-based attribute names.
get_gallery_attachment_ids()  : array
Returns the gallery attachment ids.
get_gallery_image_ids()  : array
Returns the gallery attachment ids.
get_height()  : string
Returns the product height.
get_id()  : int
Returns the unique ID for this object.
get_image()  : string
Returns the main product image.
get_image_id()  : string
Get main image ID.
get_length()  : string
Returns the product length.
get_low_stock_amount()  : int|string
Get low stock amount.
get_manage_stock()  : bool
Return if product manage stock.
get_matching_variation()  : mixed
Match a variation to a given set of attributes using a WP_Query.
get_max_purchase_quantity()  : int
Get max quantity which can be purchased at once.
get_menu_order()  : int
Get menu order.
get_meta()  : mixed
Get Meta Data by Key.
get_meta_data()  : array
Get All Meta Data.
get_min_purchase_quantity()  : int
Get min quantity which can be purchased at once.
get_name()  : string
Get product name.
get_object_read()  : bool
Get object read property.
get_parent()  : int
Get the parent of the post.
get_parent_id()  : int
Get parent ID.
get_permalink()  : string
Product permalink.
get_post_data()  : WP_Post
Get the product's post data.
get_post_password()  : int
Get post password.
get_price()  : string
Returns the product's active price.
get_price_excluding_tax()  : string
Returns the price (excluding tax) - ignores tax_class filters since the price may *include* tax and thus needs subtracting.
get_price_html()  : string
Returns the price in html format.
get_price_html_from_text()  : string
Functions for getting parts of a price, in html, used by get_price_html.
get_price_html_from_to()  : string
Functions for getting parts of a price, in html, used by get_price_html.
get_price_including_tax()  : string
Returns the price (including tax). Uses customer tax rates. Can work for a specific $qty for more accurate taxes.
get_price_suffix()  : string
Get the suffix to display after prices > 0.
get_purchase_note()  : string
Get purchase note.
get_rating_count()  : int
Get the total amount (COUNT) of ratings, or just the count for one rating e.g. number of 5 star ratings.
get_rating_counts()  : array
Get rating count.
get_rating_html()  : string
Returns the product rating in html format.
get_regular_price()  : string
Returns the product's regular price.
get_related()  : array
Get and return related products.
get_review_count()  : int
Get review count.
get_reviews_allowed()  : bool
Return if reviews is allowed.
get_sale_price()  : string
Returns the product's sale price.
get_shipping_class()  : string
Returns the product shipping class SLUG.
get_shipping_class_id()  : int
Get shipping class ID.
get_short_description()  : string
Get product short description.
get_sku()  : string
Get SKU (Stock-keeping unit) - product unique ID.
get_slug()  : string
Get product slug.
get_sold_individually()  : bool
Return if should be sold individually.
get_status()  : string
Get product status.
get_stock_managed_by_id()  : int
If the stock level comes from another product ID, this should be modified.
get_stock_quantity()  : int|null
Returns number of items available for sale.
get_stock_status()  : string
Return the stock status.
get_tag_ids()  : array
Get tag ids.
get_tags()  : array
Returns the product tags.
get_tax_class()  : string
Returns the tax class.
get_tax_status()  : string
Returns the tax status.
get_title()  : string
Get the product's title. For products this is the product name.
get_total_sales()  : int
Get number total of sales.
get_total_stock()  : int
Get total stock - This is the stock of parent and children combined.
get_type()  : string
Get internal type.
get_upsell_ids()  : array
Get upsell IDs.
get_upsells()  : array
Returns the upsell product ids.
get_variation_attributes()  : array
Return an array of attributes used for variations, as well as their possible values.
get_variation_default_attribute()  : string
If set, get the default attributes for a variable product.
get_variation_default_attributes()  : array
If set, get the default attributes for a variable product.
get_variation_description()  : string
Get product variation description.
get_variation_id()  : int
Get variation ID.
get_variation_price()  : string
Get the min or max variation (active) price.
get_variation_prices()  : array
Get an array of all sale and regular prices from all variations. This is used for example when displaying the price range at variable product level or seeing if the variable product is on sale.
get_variation_regular_price()  : string
Get the min or max variation regular price.
get_variation_sale_price()  : string
Get the min or max variation sale price.
get_virtual()  : bool
Variable products themselves cannot be virtual.
get_visible_children()  : array
Return a products child ids - visible only.
get_weight()  : string
Returns the product's weight.
get_width()  : string
Returns the product width.
grouped_product_sync()  : mixed
has_all_attributes_set()  : bool
Check if all variation's attributes are set.
has_attributes()  : bool
Returns whether or not the product has any visible attributes.
has_child()  : bool
Returns whether or not the product has any child product.
has_default_attributes()  : bool
Check if variable product has default attributes set.
has_dimensions()  : bool
Returns whether or not the product has dimensions set.
has_enough_stock()  : bool
Returns whether or not the product has enough stock for the order.
has_file()  : bool
Check if downloadable product has a file attached.
has_options()  : bool
Returns whether or not the product has additional options that need selecting before adding to cart.
has_weight()  : bool
Returns whether or not the product has weight set.
increase_stock()  : int
Increase stock level of the product.
is_downloadable()  : bool
Checks if a product is downloadable.
is_featured()  : bool
Returns whether or not the product is featured.
is_in_stock()  : bool
Returns whether or not the product can be purchased.
is_on_backorder()  : bool
Check if a product is on backorder.
is_on_sale()  : bool
Returns whether or not the product is on sale.
is_purchasable()  : bool
Returns false if the product cannot be bought.
is_shipping_taxable()  : bool
Returns whether or not the product shipping is taxable.
is_sold_individually()  : bool
Check if a product is sold individually (no quantities).
is_taxable()  : bool
Returns whether or not the product is taxable.
is_type()  : bool
Checks the product type.
is_virtual()  : bool
Checks if a product is virtual (has no shipping).
is_visible()  : bool
Returns whether or not the product is visible in the catalog.
list_attributes()  : mixed
Lists a table of attributes for the product page.
managing_stock()  : bool
Returns whether or not the product is stock managed.
meta_exists()  : bool
See if meta data exists, since get_meta always returns a '' or array().
needs_shipping()  : bool
Checks if a product needs shipping.
parent_is_visible()  : bool
Returns whether or not the variations parent is visible.
read_meta_data()  : mixed
Read Meta Data from the database. Ignore any internal properties.
reduce_stock()  : int
Reduce stock level of the product.
save()  : int
Save data (either create or update depending on if we are working on an existing product).
save_meta_data()  : mixed
Update Meta Data in the database.
set_attributes()  : mixed
Set product attributes.
set_average_rating()  : mixed
Set average rating. Read only.
set_backorders()  : mixed
Set backorders.
set_catalog_visibility()  : mixed
Set catalog visibility.
set_category_ids()  : mixed
Set the product categories.
set_children()  : mixed
Sets an array of children for the product.
set_cross_sell_ids()  : mixed
Set crosssell IDs.
set_date_created()  : mixed
Set product created date.
set_date_modified()  : mixed
Set product modified date.
set_date_on_sale_from()  : mixed
Set date on sale from.
set_date_on_sale_to()  : mixed
Set date on sale to.
set_default_attributes()  : mixed
Set default attributes. These will be saved as strings and should map to attribute values.
set_defaults()  : mixed
Set all props to default values.
set_description()  : mixed
Set product description.
set_download_expiry()  : mixed
Set download expiry.
set_download_limit()  : mixed
Set download limit.
set_downloadable()  : mixed
Set if the product is downloadable.
set_downloads()  : mixed
Set downloads.
set_featured()  : mixed
Set if the product is featured.
set_gallery_image_ids()  : mixed
Set gallery attachment ids.
set_height()  : mixed
Set the product height.
set_id()  : mixed
Set ID.
set_image_id()  : mixed
Set main image ID.
set_length()  : mixed
Set the product length.
set_low_stock_amount()  : mixed
Set low stock amount.
set_manage_stock()  : mixed
Set if product manage stock.
set_menu_order()  : mixed
Set menu order.
set_meta_data()  : mixed
Set all meta data from array.
set_name()  : mixed
Set product name.
set_object_read()  : mixed
Set object read property.
set_parent_id()  : mixed
Set parent ID.
set_post_password()  : mixed
Set post password.
set_price()  : mixed
Set the product's active price.
set_props()  : bool|WP_Error
Set a collection of props in one go, collect any errors, and return the result.
set_purchase_note()  : mixed
Set purchase note.
set_rating_counts()  : mixed
Set rating counts. Read only.
set_regular_price()  : mixed
Set the product's regular price.
set_review_count()  : mixed
Set review count. Read only.
set_reviews_allowed()  : mixed
Set if reviews is allowed.
set_sale_price()  : mixed
Set the product's sale price.
set_shipping_class_id()  : mixed
Set shipping class ID.
set_short_description()  : mixed
Set product short description.
set_sku()  : mixed
Set SKU.
set_slug()  : mixed
Set product slug.
set_sold_individually()  : mixed
Set if should be sold individually.
set_status()  : mixed
Set product status.
set_stock()  : int
Set stock level of the product.
set_stock_quantity()  : mixed
Set number of items available for sale.
set_stock_status()  : mixed
Set stock status.
set_tag_ids()  : mixed
Set the product tags.
set_tax_class()  : mixed
Set the tax class.
set_tax_status()  : mixed
Set the tax status.
set_total_sales()  : mixed
Set number total of sales.
set_upsell_ids()  : mixed
Set upsell IDs.
set_variation_attributes()  : mixed
Sets an array of variation attributes.
set_virtual()  : mixed
Set if the product is virtual.
set_visible_children()  : mixed
Sets an array of visible children only.
set_weight()  : mixed
Set the product's weight.
set_width()  : mixed
Set the product width.
single_add_to_cart_text()  : string
Get the add to cart button text for the single page.
supports()  : bool
Check if a product supports a given feature.
sync()  : WC_Product
Sync a variable product with it's children. These sync functions sync upwards (from child to parent) when the variation is saved.
sync_attributes()  : mixed
Sync the variable product's attributes with the variations.
sync_average_rating()  : mixed
Sync product rating. Can be called statically.
sync_rating_count()  : mixed
Sync product rating count. Can be called statically.
sync_stock_status()  : WC_Product
Sync parent stock status with the status of all children and save.
update_meta_data()  : mixed
Update meta data by key or ID, if provided.
validate_props()  : mixed
Ensure properties are set correctly before save.
variable_product_sync()  : mixed
Sync variable product prices with the children lowest/highest prices.
build_related_query()  : mixed
Builds the related posts query.
error()  : mixed
When invalid data is found, throw an exception unless reading from the DB.
filter_null_meta()  : bool
Filter null meta values from array.
get_availability_class()  : string
Get availability classname based on stock status.
get_availability_text()  : string
Get availability text based on stock status.
get_hook_prefix()  : string
Prefix for action and filter hooks on data.
get_prop()  : mixed
Gets a prop for a getter method.
get_related_terms()  : array
Retrieves related product terms.
get_valid_tax_classes()  : array
Return an array of valid tax classes
is_internal_meta_key()  : bool
Check if the key is an internal one.
is_visible_core()  : bool
Returns whether or not the product is visible in the catalog (doesn't trigger filters).
maybe_defer_product_sync()  : mixed
If this is a child product, queue its parent for syncing at the end of the request.
maybe_read_meta_data()  : mixed
Read meta data if null.
set_date_prop()  : mixed
Sets a date prop whilst handling formatting and datetime objects.
set_prop()  : mixed
Sets a prop for a setter method.
sort_variation_prices()  : array
Sort an associativate array of $variation_id => $price pairs in order of min and max prices.
variation_is_available()  : bool
Check if a given variation is currently available.

Properties

$extra_data

Extra data for this object. Name value pairs (name + default value).

protected array $extra_data = array()

Used as a standard way for sub classes (like product types) to add additional information to an inherited class.

Tags
since
3.0.0

Methods

__construct()

Default constructor.

public __construct(int|object|array $read) : mixed
Parameters
$read : int|object|array

ID to load from the DB (optional) or already queried data.

Return values
mixed

__get()

Magic __get method for backwards compatibility. Maps legacy vars to new getters.

public __get(string $key) : mixed
Parameters
$key : string

Key name.

Return values
mixed

__isset()

Magic __isset method for backwards compatibility. Legacy properties which could be accessed directly in the past.

public __isset(string $key) : bool
Parameters
$key : string

Key name.

Return values
bool

add_meta_data()

Add meta data.

public add_meta_data(string $key, string|array $value[, bool $unique = false ]) : mixed
Parameters
$key : string

Meta key.

$value : string|array

Meta value.

$unique : bool = false

Should this be a unique key?.

Tags
since
2.6.0
Return values
mixed

add_to_cart_description()

Get the add to cart button text description - used in aria tags.

public add_to_cart_description() : string
Tags
since
3.3.0
Return values
string

backorders_require_notification()

Returns whether or not the product needs to notify the customer on backorder.

public backorders_require_notification() : bool
Return values
bool

check_stock_status()

Check if the stock status needs changing.

public check_stock_status() : mixed
Tags
deprecated
3.0.0

Sync is done automatically on read/save, so calling this should not be needed any more.

Return values
mixed

delete()

Delete an object, set the ID to 0, and return result.

public delete([bool $force_delete = false ]) : bool
Parameters
$force_delete : bool = false

Should the date be deleted permanently.

Tags
since
2.6.0
Return values
boolresult

delete_meta_data()

Delete meta data.

public delete_meta_data(string $key) : mixed
Parameters
$key : string

Meta key.

Tags
since
2.6.0
Return values
mixed

delete_meta_data_by_mid()

Delete meta data.

public delete_meta_data_by_mid(int $mid) : mixed
Parameters
$mid : int

Meta ID.

Tags
since
2.6.0
Return values
mixed

enable_dimensions_display()

Returns whether or not we are showing dimensions on the product page.

public enable_dimensions_display() : bool
Tags
deprecated
3.0.0

Unused.

Return values
bool

get_attribute()

Returns a single product attribute as a string.

public get_attribute(string $attribute) : string
Parameters
$attribute : string

to get.

Return values
string

get_attributes()

Returns product attributes.

public get_attributes([string $context = 'view' ]) : array
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Return values
array

get_available_variation()

Returns an array of data for a variation. Used in the add to cart form.

public get_available_variation(WC_Product $variation) : array|bool
Parameters
$variation : WC_Product

Variation product object or ID.

Tags
since
2.4.0
Return values
array|bool

get_available_variations()

Get an array of available variations for the current product.

public get_available_variations([string $return = 'array' ]) : array[]|\WC_Product_Variation[]
Parameters
$return : string = 'array'

Optional. The format to return the results in. Can be 'array' to return an array of variation data or 'objects' for the product objects. Default 'array'.

Return values
array[]|\WC_Product_Variation[]

get_average_rating()

Get average rating.

public get_average_rating([string $context = 'view' ]) : float
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Return values
float

get_backorders()

Get backorders.

public get_backorders([string $context = 'view' ]) : string
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
stringyes no or notify

get_catalog_visibility()

Get catalog visibility.

public get_catalog_visibility([string $context = 'view' ]) : string
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
string

get_categories()

Returns the product categories.

public get_categories([string $sep = ', ' ][, string $before = '' ][, string $after = '' ]) : string
Parameters
$sep : string = ', '

(default: ', ').

$before : string = ''

(default: '').

$after : string = ''

(default: '').

Tags
deprecated
3.0.0
Return values
string

get_category_ids()

Get category ids.

public get_category_ids([string $context = 'view' ]) : array
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
array

get_children()

Return a products child ids.

public get_children([bool|string $visible_only = '' ]) : array

This is lazy loaded as it's not used often and does require several queries.

Parameters
$visible_only : bool|string = ''

Visible only.

Return values
arrayChildren ids

get_cross_sell_ids()

Get cross sell IDs.

public get_cross_sell_ids([string $context = 'view' ]) : array
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
array

get_date_created()

Get product created date.

public get_date_created([string $context = 'view' ]) : WC_DateTime|null
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
WC_DateTime|nullobject if the date is set or null if there is no date.

get_date_modified()

Get product modified date.

public get_date_modified([string $context = 'view' ]) : WC_DateTime|null
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
WC_DateTime|nullobject if the date is set or null if there is no date.

get_date_on_sale_from()

Get date on sale from.

public get_date_on_sale_from([string $context = 'view' ]) : WC_DateTime|null
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
WC_DateTime|nullobject if the date is set or null if there is no date.

get_date_on_sale_to()

Get date on sale to.

public get_date_on_sale_to([string $context = 'view' ]) : WC_DateTime|null
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
WC_DateTime|nullobject if the date is set or null if there is no date.

get_default_attributes()

Get default attributes.

public get_default_attributes([string $context = 'view' ]) : array
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
array

get_description()

Get product description.

public get_description([string $context = 'view' ]) : string
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
string

get_dimensions()

Returns formatted dimensions.

public get_dimensions([bool $formatted = true ]) : string|array
Parameters
$formatted : bool = true

True by default for legacy support - will be false/not set in future versions to return the array only. Use wc_format_dimensions for formatted versions instead.

Return values
string|array

get_display_price()

Returns the price including or excluding tax, based on the 'woocommerce_tax_display_shop' setting.

public get_display_price([string $price = '' ][, int $qty = 1 ]) : string
Parameters
$price : string = ''

to calculate, left blank to just use get_price()

$qty : int = 1

passed on to get_price_including_tax() or get_price_excluding_tax()

Tags
deprecated
3.0.0

Use wc_get_price_to_display instead.

Return values
string

get_download_expiry()

Get download expiry.

public get_download_expiry([string $context = 'view' ]) : int
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
int

get_download_limit()

Get download limit.

public get_download_limit([string $context = 'view' ]) : int
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
int

get_downloadable()

Variable products themselves cannot be downloadable.

public get_downloadable([string $context = 'view' ]) : bool
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Return values
bool

get_downloads()

Get downloads.

public get_downloads([string $context = 'view' ]) : array
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
array

get_extra_data_keys()

Returns all "extra" data keys for an object (for sub objects like product types).

public get_extra_data_keys() : array
Tags
since
3.0.0
Return values
array

If the product is featured.

public get_featured([string $context = 'view' ]) : bool
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
bool

get_file()

Get a file by $download_id.

public get_file([string $download_id = '' ]) : array|false
Parameters
$download_id : string = ''

file identifier.

Return values
array|falseif not found

get_file_download_path()

Get file download path identified by $download_id.

public get_file_download_path(string $download_id) : string
Parameters
$download_id : string

file identifier.

Return values
string

get_formatted_variation_attributes()

Get formatted variation data with WC < 2.4 back compat and proper formatting of text-based attribute names.

public get_formatted_variation_attributes([bool $flat = false ]) : string
Parameters
$flat : bool = false
Tags
deprecated
3.0.0
Return values
string

Returns the gallery attachment ids.

public get_gallery_image_ids([string $context = 'view' ]) : array
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Return values
array

get_height()

Returns the product height.

public get_height([string $context = 'view' ]) : string
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Return values
string

get_image()

Returns the main product image.

public get_image([string $size = 'woocommerce_thumbnail' ][, array $attr = array() ][, bool $placeholder = true ]) : string
Parameters
$size : string = 'woocommerce_thumbnail'

(default: 'woocommerce_thumbnail').

$attr : array = array()

Image attributes.

$placeholder : bool = true

True to return $placeholder if no image is found, or false to return an empty string.

Return values
string

get_image_id()

Get main image ID.

public get_image_id([string $context = 'view' ]) : string
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
string

get_length()

Returns the product length.

public get_length([string $context = 'view' ]) : string
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Return values
string

get_low_stock_amount()

Get low stock amount.

public get_low_stock_amount([string $context = 'view' ]) : int|string
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.5.0
Return values
int|stringReturns empty string if value not set

get_manage_stock()

Return if product manage stock.

public get_manage_stock([string $context = 'view' ]) : bool
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
bool

get_matching_variation()

Match a variation to a given set of attributes using a WP_Query.

public get_matching_variation([array $match_attributes = array() ]) : mixed
Parameters
$match_attributes : array = array()
Tags
deprecated
3.0.0

in favour of Product data store's find_matching_product_variation.

Return values
mixed

get_max_purchase_quantity()

Get max quantity which can be purchased at once.

public get_max_purchase_quantity() : int
Tags
since
3.0.0
Return values
intQuantity or -1 if unlimited.

get_menu_order()

Get menu order.

public get_menu_order([string $context = 'view' ]) : int
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
int

get_meta()

Get Meta Data by Key.

public get_meta([string $key = '' ][, bool $single = true ][, string $context = 'view' ]) : mixed
Parameters
$key : string = ''

Meta Key.

$single : bool = true

return first found meta with key, or all with $key.

$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
2.6.0
Return values
mixed

get_name()

Get product name.

public get_name([string $context = 'view' ]) : string
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
string

get_parent_id()

Get parent ID.

public get_parent_id([string $context = 'view' ]) : int
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
int

get_post_password()

Get post password.

public get_post_password([string $context = 'view' ]) : int
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.6.0
Return values
int

get_price()

Returns the product's active price.

public get_price([string $context = 'view' ]) : string
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Return values
stringprice

get_price_excluding_tax()

Returns the price (excluding tax) - ignores tax_class filters since the price may *include* tax and thus needs subtracting.

public get_price_excluding_tax([int $qty = 1 ][, string $price = '' ]) : string

Uses store base tax rates. Can work for a specific $qty for more accurate taxes.

Parameters
$qty : int = 1
$price : string = ''

to calculate, left blank to just use get_price()

Tags
deprecated
3.0.0

Use wc_get_price_excluding_tax instead.

Return values
string

get_price_html()

Returns the price in html format.

public get_price_html([string $price = '' ]) : string

Note: Variable prices do not show suffixes like other product types. This is due to some things like tax classes being set at variation level which could differ from the parent price. The only way to show accurate prices would be to load the variation and get IT's price, which adds extra overhead and still has edge cases where the values would be inaccurate.

Additionally, ranges of prices no longer show 'striked out' sale prices due to the strings being very long and unclear/confusing. A single range is shown instead.

Parameters
$price : string = ''

Price (default: '').

Return values
string

get_price_html_from_text()

Functions for getting parts of a price, in html, used by get_price_html.

public get_price_html_from_text() : string
Tags
deprecated
3.0.0
Return values
string

get_price_html_from_to()

Functions for getting parts of a price, in html, used by get_price_html.

public get_price_html_from_to(string $from, mixed $to) : string
Parameters
$from : string

String or float to wrap with 'from' text

$to : mixed

String or float to wrap with 'to' text

Tags
deprecated
3.0.0

Use wc_format_sale_price instead.

Return values
string

get_price_including_tax()

Returns the price (including tax). Uses customer tax rates. Can work for a specific $qty for more accurate taxes.

public get_price_including_tax([int $qty = 1 ][, string $price = '' ]) : string
Parameters
$qty : int = 1
$price : string = ''

to calculate, left blank to just use get_price()

Tags
deprecated
3.0.0

Use wc_get_price_including_tax instead.

Return values
string

get_price_suffix()

Get the suffix to display after prices > 0.

public get_price_suffix([string $price = '' ][, int $qty = 1 ]) : string

This is skipped if the suffix has dynamic values such as {price_excluding_tax} for variable products.

Parameters
$price : string = ''

Price to calculate, left blank to just use get_price().

$qty : int = 1

Quantity passed on to get_price_including_tax() or get_price_excluding_tax().

Tags
see
get_price_html

for an explanation as to why.

Return values
string

get_purchase_note()

Get purchase note.

public get_purchase_note([string $context = 'view' ]) : string
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
string

get_rating_count()

Get the total amount (COUNT) of ratings, or just the count for one rating e.g. number of 5 star ratings.

public get_rating_count([int $value = null ]) : int
Parameters
$value : int = null

Optional. Rating value to get the count for. By default returns the count of all rating values.

Return values
int

get_rating_counts()

Get rating count.

public get_rating_counts([string $context = 'view' ]) : array
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Return values
arrayof counts

get_rating_html()

Returns the product rating in html format.

public get_rating_html([string $rating = null ]) : string
Parameters
$rating : string = null

(default: '')

Tags
deprecated
3.0.0
Return values
string

get_regular_price()

Returns the product's regular price.

public get_regular_price([string $context = 'view' ]) : string
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Return values
stringprice

Get and return related products.

public get_related([int $limit = 5 ]) : array
Parameters
$limit : int = 5
Tags
deprecated
3.0.0

Use wc_get_related_products instead.

Return values
array

get_review_count()

Get review count.

public get_review_count([string $context = 'view' ]) : int
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Return values
int

get_reviews_allowed()

Return if reviews is allowed.

public get_reviews_allowed([string $context = 'view' ]) : bool
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
bool

get_sale_price()

Returns the product's sale price.

public get_sale_price([string $context = 'view' ]) : string
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Return values
stringprice

get_shipping_class_id()

Get shipping class ID.

public get_shipping_class_id([string $context = 'view' ]) : int
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
int

get_short_description()

Get product short description.

public get_short_description([string $context = 'view' ]) : string
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
string

get_sku()

Get SKU (Stock-keeping unit) - product unique ID.

public get_sku([string $context = 'view' ]) : string
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Return values
string

get_slug()

Get product slug.

public get_slug([string $context = 'view' ]) : string
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
string

get_sold_individually()

Return if should be sold individually.

public get_sold_individually([string $context = 'view' ]) : bool
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
bool

get_status()

Get product status.

public get_status([string $context = 'view' ]) : string
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
string

get_stock_managed_by_id()

If the stock level comes from another product ID, this should be modified.

public get_stock_managed_by_id() : int
Tags
since
3.0.0
Return values
int

get_stock_quantity()

Returns number of items available for sale.

public get_stock_quantity([string $context = 'view' ]) : int|null
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Return values
int|null

get_stock_status()

Return the stock status.

public get_stock_status([string $context = 'view' ]) : string
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
string

get_tag_ids()

Get tag ids.

public get_tag_ids([string $context = 'view' ]) : array
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
array

get_tags()

Returns the product tags.

public get_tags([string $sep = ', ' ][, string $before = '' ][, string $after = '' ]) : array
Parameters
$sep : string = ', '

(default: ', ').

$before : string = ''

(default: '').

$after : string = ''

(default: '').

Tags
deprecated
3.0.0
Return values
array

get_tax_class()

Returns the tax class.

public get_tax_class([string $context = 'view' ]) : string
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Return values
string

get_tax_status()

Returns the tax status.

public get_tax_status([string $context = 'view' ]) : string
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Return values
string

get_total_sales()

Get number total of sales.

public get_total_sales([string $context = 'view' ]) : int
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
int

get_type()

Get internal type.

public get_type() : string

The product_type property is deprecated but is used here for BW compatibility with child classes which may be defining product_type and not have a get_type method.

Return values
string

get_upsell_ids()

Get upsell IDs.

public get_upsell_ids([string $context = 'view' ]) : array
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
array

get_variation_attributes()

Return an array of attributes used for variations, as well as their possible values.

public get_variation_attributes() : array

This is lazy loaded as it's not used often and does require several queries.

Return values
arrayAttributes and their available values

get_variation_default_attribute()

If set, get the default attributes for a variable product.

public get_variation_default_attribute(string $attribute_name) : string
Parameters
$attribute_name : string

Attribute name.

Return values
string

get_variation_default_attributes()

If set, get the default attributes for a variable product.

public get_variation_default_attributes() : array
Tags
deprecated
3.0.0
Return values
array

get_variation_price()

Get the min or max variation (active) price.

public get_variation_price([string $min_or_max = 'min' ][, bool $for_display = false ]) : string
Parameters
$min_or_max : string = 'min'

Min or max price.

$for_display : bool = false

If true, prices will be adapted for display based on the woocommerce_tax_display_shop setting (including or excluding taxes).

Return values
string

get_variation_prices()

Get an array of all sale and regular prices from all variations. This is used for example when displaying the price range at variable product level or seeing if the variable product is on sale.

public get_variation_prices([bool $for_display = false ]) : array
Parameters
$for_display : bool = false

If true, prices will be adapted for display based on the woocommerce_tax_display_shop setting (including or excluding taxes).

Return values
arrayArray of RAW prices, regular prices, and sale prices with keys set to variation ID.

get_variation_regular_price()

Get the min or max variation regular price.

public get_variation_regular_price([string $min_or_max = 'min' ][, bool $for_display = false ]) : string
Parameters
$min_or_max : string = 'min'

Min or max price.

$for_display : bool = false

If true, prices will be adapted for display based on the woocommerce_tax_display_shop setting (including or excluding taxes).

Return values
string

get_variation_sale_price()

Get the min or max variation sale price.

public get_variation_sale_price([string $min_or_max = 'min' ][, bool $for_display = false ]) : string
Parameters
$min_or_max : string = 'min'

Min or max price.

$for_display : bool = false

If true, prices will be adapted for display based on the woocommerce_tax_display_shop setting (including or excluding taxes).

Return values
string

get_virtual()

Variable products themselves cannot be virtual.

public get_virtual([string $context = 'view' ]) : bool
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Return values
bool

get_visible_children()

Return a products child ids - visible only.

public get_visible_children() : array

This is lazy loaded as it's not used often and does require several queries.

Tags
since
3.0.0
Return values
arrayChildren ids

get_weight()

Returns the product's weight.

public get_weight([string $context = 'view' ]) : string
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Return values
string

get_width()

Returns the product width.

public get_width([string $context = 'view' ]) : string
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit.

Return values
string

has_enough_stock()

Returns whether or not the product has enough stock for the order.

public has_enough_stock(mixed $quantity) : bool
Parameters
$quantity : mixed

Quantity of a product added to an order.

Return values
bool

has_file()

Check if downloadable product has a file attached.

public has_file([string $download_id = '' ]) : bool
Parameters
$download_id : string = ''

file identifier.

Tags
since
1.6.2
Return values
boolWhether downloadable product has a file attached.

has_options()

Returns whether or not the product has additional options that need selecting before adding to cart.

public has_options() : bool
Tags
since
3.0.0
Return values
bool

increase_stock()

Increase stock level of the product.

public increase_stock([int $amount = 1 ]) : int
Parameters
$amount : int = 1

Amount to increase by. Default 1.

Tags
deprecated
3.0.0
Return values
intnew stock level

is_in_stock()

Returns whether or not the product can be purchased.

public is_in_stock() : bool

This returns true for 'instock' and 'onbackorder' stock statuses.

Return values
bool

is_on_backorder()

Check if a product is on backorder.

public is_on_backorder(int $qty_in_cart) : bool
Parameters
$qty_in_cart : int

(default: 0).

Return values
bool

is_on_sale()

Returns whether or not the product is on sale.

public is_on_sale([string $context = 'view' ]) : bool
Parameters
$context : string = 'view'

What the value is for. Valid values are view and edit. What the value is for. Valid values are view and edit.

Return values
bool

is_type()

Checks the product type.

public is_type(string|array $type) : bool

Backwards compatibility with downloadable/virtual.

Parameters
$type : string|array

Array or string of types.

Return values
bool

list_attributes()

Lists a table of attributes for the product page.

public list_attributes() : mixed
Tags
deprecated
3.0.0

Use wc_display_product_attributes instead.

Return values
mixed

meta_exists()

See if meta data exists, since get_meta always returns a '' or array().

public meta_exists([string $key = '' ]) : bool
Parameters
$key : string = ''

Meta Key.

Tags
since
3.0.0
Return values
bool

read_meta_data()

Read Meta Data from the database. Ignore any internal properties.

public read_meta_data([bool $force_read = false ]) : mixed

Uses it's own caches because get_metadata does not provide meta_ids.

Parameters
$force_read : bool = false

True to force a new DB read (and update cache).

Tags
since
2.6.0
Return values
mixed

reduce_stock()

Reduce stock level of the product.

public reduce_stock([int $amount = 1 ]) : int
Parameters
$amount : int = 1

Amount to reduce by. Default: 1

Tags
deprecated
3.0.0
Return values
intnew stock level

save()

Save data (either create or update depending on if we are working on an existing product).

public save() : int
Tags
since
3.0.0
Return values
int

set_attributes()

Set product attributes.

public set_attributes(array $raw_attributes) : mixed

Attributes are made up of: id - 0 for product level attributes. ID for global attributes. name - Attribute name. options - attribute value or array of term ids/names. position - integer sort order. visible - If visible on frontend. variation - If used for variations. Indexed by unqiue key to allow clearing old ones after a set.

Parameters
$raw_attributes : array

Array of WC_Product_Attribute objects.

Tags
since
3.0.0
Return values
mixed

set_average_rating()

Set average rating. Read only.

public set_average_rating(float $average) : mixed
Parameters
$average : float

Product average rating.

Return values
mixed

set_backorders()

Set backorders.

public set_backorders(string $backorders) : mixed
Parameters
$backorders : string

Options: 'yes', 'no' or 'notify'.

Tags
since
3.0.0
Return values
mixed

set_catalog_visibility()

Set catalog visibility.

public set_catalog_visibility(string $visibility) : mixed
Parameters
$visibility : string

Options: 'hidden', 'visible', 'search' and 'catalog'.

Tags
since
3.0.0
throws
WC_Data_Exception

Throws exception when invalid data is found.

Return values
mixed

set_category_ids()

Set the product categories.

public set_category_ids(array $term_ids) : mixed
Parameters
$term_ids : array

List of terms IDs.

Tags
since
3.0.0
Return values
mixed

set_children()

Sets an array of children for the product.

public set_children(array $children) : mixed
Parameters
$children : array

Childre products.

Tags
since
3.0.0
Return values
mixed

set_cross_sell_ids()

Set crosssell IDs.

public set_cross_sell_ids(array $cross_sell_ids) : mixed
Parameters
$cross_sell_ids : array

IDs from the cross-sell products.

Tags
since
3.0.0
Return values
mixed

set_date_created()

Set product created date.

public set_date_created([string|int|null $date = null ]) : mixed
Parameters
$date : string|int|null = null

UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.

Tags
since
3.0.0
Return values
mixed

set_date_modified()

Set product modified date.

public set_date_modified([string|int|null $date = null ]) : mixed
Parameters
$date : string|int|null = null

UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.

Tags
since
3.0.0
Return values
mixed

set_date_on_sale_from()

Set date on sale from.

public set_date_on_sale_from([string|int|null $date = null ]) : mixed
Parameters
$date : string|int|null = null

UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.

Tags
since
3.0.0
Return values
mixed

set_date_on_sale_to()

Set date on sale to.

public set_date_on_sale_to([string|int|null $date = null ]) : mixed
Parameters
$date : string|int|null = null

UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.

Tags
since
3.0.0
Return values
mixed

set_default_attributes()

Set default attributes. These will be saved as strings and should map to attribute values.

public set_default_attributes(array $default_attributes) : mixed
Parameters
$default_attributes : array

List of default attributes.

Tags
since
3.0.0
Return values
mixed

set_description()

Set product description.

public set_description(string $description) : mixed
Parameters
$description : string

Product description.

Tags
since
3.0.0
Return values
mixed

set_download_expiry()

Set download expiry.

public set_download_expiry(int|string $download_expiry) : mixed
Parameters
$download_expiry : int|string

Product download expiry.

Tags
since
3.0.0
Return values
mixed

set_download_limit()

Set download limit.

public set_download_limit(int|string $download_limit) : mixed
Parameters
$download_limit : int|string

Product download limit.

Tags
since
3.0.0
Return values
mixed

set_downloadable()

Set if the product is downloadable.

public set_downloadable(bool|string $downloadable) : mixed
Parameters
$downloadable : bool|string

Whether product is downloadable or not.

Tags
since
3.0.0
Return values
mixed

set_downloads()

Set downloads.

public set_downloads(array $downloads_array) : mixed
Parameters
$downloads_array : array

Array of WC_Product_Download objects or arrays.

Tags
since
3.0.0
Return values
mixed

Set if the product is featured.

public set_featured(bool|string $featured) : mixed
Parameters
$featured : bool|string

Whether the product is featured or not.

Tags
since
3.0.0
Return values
mixed

Set gallery attachment ids.

public set_gallery_image_ids(array $image_ids) : mixed
Parameters
$image_ids : array

List of image ids.

Tags
since
3.0.0
Return values
mixed

set_height()

Set the product height.

public set_height(float|string $height) : mixed
Parameters
$height : float|string

Total height.

Tags
since
3.0.0
Return values
mixed

set_image_id()

Set main image ID.

public set_image_id([int|string $image_id = '' ]) : mixed
Parameters
$image_id : int|string = ''

Product image id.

Tags
since
3.0.0
Return values
mixed

set_length()

Set the product length.

public set_length(float|string $length) : mixed
Parameters
$length : float|string

Total length.

Tags
since
3.0.0
Return values
mixed

set_low_stock_amount()

Set low stock amount.

public set_low_stock_amount(int|string $amount) : mixed
Parameters
$amount : int|string

Empty string if value not set.

Tags
since
3.5.0
Return values
mixed

set_manage_stock()

Set if product manage stock.

public set_manage_stock(bool $manage_stock) : mixed
Parameters
$manage_stock : bool

Whether or not manage stock is enabled.

Tags
since
3.0.0
Return values
mixed

set_menu_order()

Set menu order.

public set_menu_order(int $menu_order) : mixed
Parameters
$menu_order : int

Menu order.

Tags
since
3.0.0
Return values
mixed

set_meta_data()

Set all meta data from array.

public set_meta_data(array $data) : mixed
Parameters
$data : array

Key/Value pairs.

Tags
since
2.6.0
Return values
mixed

set_object_read()

Set object read property.

public set_object_read([bool $read = true ]) : mixed
Parameters
$read : bool = true

Should read?.

Tags
since
3.0.0
Return values
mixed

set_parent_id()

Set parent ID.

public set_parent_id(int $parent_id) : mixed
Parameters
$parent_id : int

Product parent ID.

Tags
since
3.0.0
Return values
mixed

set_post_password()

Set post password.

public set_post_password(int $post_password) : mixed
Parameters
$post_password : int

Post password.

Tags
since
3.6.0
Return values
mixed

set_props()

Set a collection of props in one go, collect any errors, and return the result.

public set_props(array $props[, string $context = 'set' ]) : bool|WP_Error

Only sets using public methods.

Parameters
$props : array

Key value pairs to set. Key is the prop and should map to a setter function name.

$context : string = 'set'

In what context to run this.

Tags
since
3.0.0
Return values
bool|WP_Error

set_purchase_note()

Set purchase note.

public set_purchase_note(string $purchase_note) : mixed
Parameters
$purchase_note : string

Purchase note.

Tags
since
3.0.0
Return values
mixed

set_rating_counts()

Set rating counts. Read only.

public set_rating_counts(array $counts) : mixed
Parameters
$counts : array

Product rating counts.

Return values
mixed

set_regular_price()

Set the product's regular price.

public set_regular_price(string $price) : mixed
Parameters
$price : string

Regular price.

Tags
since
3.0.0
Return values
mixed

set_review_count()

Set review count. Read only.

public set_review_count(int $count) : mixed
Parameters
$count : int

Product review count.

Return values
mixed

set_reviews_allowed()

Set if reviews is allowed.

public set_reviews_allowed(bool $reviews_allowed) : mixed
Parameters
$reviews_allowed : bool

Reviews allowed or not.

Tags
since
3.0.0
Return values
mixed

set_sale_price()

Set the product's sale price.

public set_sale_price(string $price) : mixed
Parameters
$price : string

sale price.

Tags
since
3.0.0
Return values
mixed

set_shipping_class_id()

Set shipping class ID.

public set_shipping_class_id(int $id) : mixed
Parameters
$id : int

Product shipping class id.

Tags
since
3.0.0
Return values
mixed

set_short_description()

Set product short description.

public set_short_description(string $short_description) : mixed
Parameters
$short_description : string

Product short description.

Tags
since
3.0.0
Return values
mixed

set_sold_individually()

Set if should be sold individually.

public set_sold_individually(bool $sold_individually) : mixed
Parameters
$sold_individually : bool

Whether or not product is sold individually.

Tags
since
3.0.0
Return values
mixed

set_stock()

Set stock level of the product.

public set_stock([int $amount = null ][, string $mode = 'set' ]) : int
Parameters
$amount : int = null
$mode : string = 'set'
Tags
deprecated
3.0.0
Return values
int

set_stock_quantity()

Set number of items available for sale.

public set_stock_quantity(float|null $quantity) : mixed
Parameters
$quantity : float|null

Stock quantity.

Tags
since
3.0.0
Return values
mixed

set_stock_status()

Set stock status.

public set_stock_status([string $status = 'instock' ]) : mixed
Parameters
$status : string = 'instock'

New status.

Return values
mixed

set_tag_ids()

Set the product tags.

public set_tag_ids(array $term_ids) : mixed
Parameters
$term_ids : array

List of terms IDs.

Tags
since
3.0.0
Return values
mixed

set_total_sales()

Set number total of sales.

public set_total_sales(int $total) : mixed
Parameters
$total : int

Total of sales.

Tags
since
3.0.0
Return values
mixed

set_upsell_ids()

Set upsell IDs.

public set_upsell_ids(array $upsell_ids) : mixed
Parameters
$upsell_ids : array

IDs from the up-sell products.

Tags
since
3.0.0
Return values
mixed

set_variation_attributes()

Sets an array of variation attributes.

public set_variation_attributes(array $variation_attributes) : mixed
Parameters
$variation_attributes : array

Attributes list.

Tags
since
3.0.0
Return values
mixed

set_virtual()

Set if the product is virtual.

public set_virtual(bool|string $virtual) : mixed
Parameters
$virtual : bool|string

Whether product is virtual or not.

Tags
since
3.0.0
Return values
mixed

set_visible_children()

Sets an array of visible children only.

public set_visible_children(array $visible_children) : mixed
Parameters
$visible_children : array

List of visible children products.

Tags
since
3.0.0
Return values
mixed

set_weight()

Set the product's weight.

public set_weight(float|string $weight) : mixed
Parameters
$weight : float|string

Total weight.

Tags
since
3.0.0
Return values
mixed

set_width()

Set the product width.

public set_width(float|string $width) : mixed
Parameters
$width : float|string

Total width.

Tags
since
3.0.0
Return values
mixed

supports()

Check if a product supports a given feature.

public supports(string $feature) : bool

Product classes should override this to declare support (or lack of support) for a feature.

Parameters
$feature : string

string The name of a feature to test support for.

Tags
since
2.5.0
Return values
boolTrue if the product supports the feature, false otherwise.

sync()

Sync a variable product with it's children. These sync functions sync upwards (from child to parent) when the variation is saved.

public static sync(WC_Product|int $product[, bool $save = true ]) : WC_Product
Parameters
$product : WC_Product|int

Product object or ID for which you wish to sync.

$save : bool = true

If true, the product object will be saved to the DB before returning it.

Return values
WC_ProductSynced product object.

sync_attributes()

Sync the variable product's attributes with the variations.

public static sync_attributes( $product[, bool $children = false ]) : mixed
Parameters
$product :
$children : bool = false
Return values
mixed

sync_average_rating()

Sync product rating. Can be called statically.

public static sync_average_rating(int $post_id) : mixed
Parameters
$post_id : int
Tags
deprecated
3.0.0
Return values
mixed

sync_rating_count()

Sync product rating count. Can be called statically.

public static sync_rating_count(int $post_id) : mixed
Parameters
$post_id : int
Tags
deprecated
3.0.0
Return values
mixed

sync_stock_status()

Sync parent stock status with the status of all children and save.

public static sync_stock_status(WC_Product|int $product[, bool $save = true ]) : WC_Product
Parameters
$product : WC_Product|int

Product object or ID for which you wish to sync.

$save : bool = true

If true, the product object will be saved to the DB before returning it.

Return values
WC_ProductSynced product object.

update_meta_data()

Update meta data by key or ID, if provided.

public update_meta_data(string $key, string|array $value, int $meta_id) : mixed
Parameters
$key : string

Meta key.

$value : string|array

Meta value.

$meta_id : int

Meta ID.

Tags
since
2.6.0
Return values
mixed

variable_product_sync()

Sync variable product prices with the children lowest/highest prices.

public variable_product_sync(int $product_id) : mixed
Parameters
$product_id : int
Tags
deprecated
3.0.0

not used in core.

Return values
mixed

Builds the related posts query.

protected build_related_query( $cats_array,  $tags_array,  $exclude_ids,  $limit) : mixed
Parameters
$cats_array :
$tags_array :
$exclude_ids :
$limit :
Tags
deprecated
3.0.0

Use Product Data Store get_related_products_query instead.

Return values
mixed

error()

When invalid data is found, throw an exception unless reading from the DB.

protected error(string $code, string $message[, int $http_status_code = 400 ][, array $data = array() ]) : mixed
Parameters
$code : string

Error code.

$message : string

Error message.

$http_status_code : int = 400

HTTP status code.

$data : array = array()

Extra error data.

Tags
throws
WC_Data_Exception

Data Exception.

since
3.0.0
Return values
mixed

filter_null_meta()

Filter null meta values from array.

protected filter_null_meta(mixed $meta) : bool
Parameters
$meta : mixed

Meta value to check.

Tags
since
3.0.0
Return values
bool

get_prop()

Gets a prop for a getter method.

protected get_prop(string $prop[, string $context = 'view' ]) : mixed

Gets the value from either current pending changes, or the data itself. Context controls what happens to the value before it's returned.

Parameters
$prop : string

Name of prop to get.

$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
mixed

Retrieves related product terms.

protected get_related_terms( $term) : array
Parameters
$term :
Tags
deprecated
3.0.0

Use wc_get_product_term_ids instead.

Return values
array

is_internal_meta_key()

Check if the key is an internal one.

protected is_internal_meta_key(string $key) : bool
Parameters
$key : string

Key to check.

Tags
since
3.2.0
Return values
booltrue if it's an internal key, false otherwise

is_visible_core()

Returns whether or not the product is visible in the catalog (doesn't trigger filters).

protected is_visible_core() : bool
Return values
bool

maybe_defer_product_sync()

If this is a child product, queue its parent for syncing at the end of the request.

protected maybe_defer_product_sync() : mixed
Return values
mixed

set_date_prop()

Sets a date prop whilst handling formatting and datetime objects.

protected set_date_prop(string $prop, string|int $value) : mixed
Parameters
$prop : string

Name of prop to set.

$value : string|int

Value of the prop.

Tags
since
3.0.0
Return values
mixed

set_prop()

Sets a prop for a setter method.

protected set_prop(string $prop, mixed $value) : mixed

This stores changes in a special array so we can track what needs saving the the DB later.

Parameters
$prop : string

Name of prop to set.

$value : mixed

Value of the prop.

Tags
since
3.0.0
Return values
mixed

sort_variation_prices()

Sort an associativate array of $variation_id => $price pairs in order of min and max prices.

protected sort_variation_prices(array $prices) : array
Parameters
$prices : array

Associativate array of $variation_id => $price pairs.

Return values
array