WooCommerce Code Reference

Search results

WC_Product extends WC_Abstract_Legacy_Product

Abstract Product Class

The WooCommerce product class handles individual product data.

Table of Contents

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

Properties

$object_type

This is the name of this object type.

protected string $object_type = 'product'

$data

Stores product data.

protected array $data = array('name' => '', 'slug' => '', 'date_created' => \null, 'date_modified' => \null, 'status' => \false, 'featured' => \false, 'catalog_visibility' => 'visible', 'description' => '', 'short_description' => '', 'sku' => '', 'price' => '', 'regular_price' => '', 'sale_price' => '', 'date_on_sale_from' => \null, 'date_on_sale_to' => \null, 'total_sales' => '0', 'tax_status' => 'taxable', 'tax_class' => '', 'manage_stock' => \false, 'stock_quantity' => \null, 'stock_status' => 'instock', 'backorders' => 'no', 'low_stock_amount' => '', 'sold_individually' => \false, 'weight' => '', 'length' => '', 'width' => '', 'height' => '', 'upsell_ids' => array(), 'cross_sell_ids' => array(), 'parent_id' => 0, 'reviews_allowed' => \true, 'purchase_note' => '', 'attributes' => array(), 'default_attributes' => array(), 'menu_order' => 0, 'post_password' => '', 'virtual' => \false, 'downloadable' => \false, 'category_ids' => array(), 'tag_ids' => array(), 'shipping_class_id' => 0, 'downloads' => array(), 'image_id' => '', 'gallery_image_ids' => array(), 'download_limit' => -1, 'download_expiry' => -1, 'rating_counts' => array(), 'average_rating' => 0, 'review_count' => 0)

$supports

Supported features such as 'ajax_add_to_cart'.

protected array $supports = array()

$data

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

protected array $data = array()

$changes

Core data changes for this object.

protected array $changes = array()

$object_read

This is false until the object is read from the DB.

protected bool $object_read = \false

$object_type

This is the name of this object type.

protected string $object_type = 'data'

$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.

$default_data

Set to _data on construct so we can track and reset data if needed.

protected array $default_data = array()

$data_store

Contains a reference to the data store for this class.

protected object $data_store

$cache_group

Stores meta in cache for future reads.

protected string $cache_group = ''
A group must be set to to enable caching.

$meta_data

Stores additional meta data.

protected array $meta_data = \null

Methods

__construct()

Get the product if ID is passed, otherwise the product is new and empty.

public __construct( $product : int|WC_Product|object ) : mixed

This class should NOT be instantiated, but the wc_get_product() function should be used. It is possible, but the wc_get_product() is preferred.

Parameters
$product : int|WC_Product|object

Product to init.

Return values
mixed

get_type()

Get internal type. Should return string and *should be overridden* by child classes.

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.

Tags
since
Return values
string

get_name()

Get product name.

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

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

Tags
since
Return values
string

get_slug()

Get product slug.

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

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

Tags
since
Return values
string

get_date_created()

Get product created date.

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

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

Tags
since
Return values
WC_DateTime|null

object if the date is set or null if there is no date.

get_date_modified()

Get product modified date.

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

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

Tags
since
Return values
WC_DateTime|null

object if the date is set or null if there is no date.

get_status()

Get product status.

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

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

Tags
since
Return values
string

get_featured()

If the product is featured.

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

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

Tags
since
Return values
bool

get_catalog_visibility()

Get catalog visibility.

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

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

Tags
since
Return values
string

get_description()

Get product description.

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

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

Tags
since
Return values
string

get_short_description()

Get product short description.

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

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

Tags
since
Return values
string

get_sku()

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

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

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

Return values
string

get_price()

Returns the product's active price.

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

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

Return values
string

price

get_regular_price()

Returns the product's regular price.

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

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

Return values
string

price

get_sale_price()

Returns the product's sale price.

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

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

Return values
string

price

get_date_on_sale_from()

Get date on sale from.

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

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

Tags
since
Return values
WC_DateTime|null

object 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( [ $context : string = 'view' ] ) : WC_DateTime|null
Parameters
$context : string = 'view'

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

Tags
since
Return values
WC_DateTime|null

object if the date is set or null if there is no date.

get_total_sales()

Get number total of sales.

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

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

Tags
since
Return values
int

get_tax_status()

Returns the tax status.

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

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

Return values
string

get_tax_class()

Returns the tax class.

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

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

Return values
string

get_manage_stock()

Return if product manage stock.

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

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

Tags
since
Return values
bool

get_stock_quantity()

Returns number of items available for sale.

public get_stock_quantity( [ $context : string = '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( [ $context : string = 'view' ] ) : string
Parameters
$context : string = 'view'

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

Tags
since
Return values
string

get_backorders()

Get backorders.

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

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

Tags
since
Return values
string

yes no or notify

get_low_stock_amount()

Get low stock amount.

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

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

Tags
since
Return values
int|string

Returns empty string if value not set

get_sold_individually()

Return if should be sold individually.

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

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

Tags
since
Return values
bool

get_weight()

Returns the product's weight.

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

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

Return values
string

get_length()

Returns the product length.

public get_length( [ $context : string = '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( [ $context : string = 'view' ] ) : string
Parameters
$context : string = 'view'

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

Return values
string

get_height()

Returns the product height.

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

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

Return values
string

get_dimensions()

Returns formatted dimensions.

public get_dimensions( [ $formatted : bool = 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_upsell_ids()

Get upsell IDs.

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

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

Tags
since
Return values
array

get_cross_sell_ids()

Get cross sell IDs.

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

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

Tags
since
Return values
array

get_parent_id()

Get parent ID.

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

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

Tags
since
Return values
int

get_reviews_allowed()

Return if reviews is allowed.

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

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

Tags
since
Return values
bool

get_purchase_note()

Get purchase note.

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

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

Tags
since
Return values
string

get_attributes()

Returns product attributes.

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

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

Return values
array

get_default_attributes()

Get default attributes.

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

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

Tags
since
Return values
array

get_menu_order()

Get menu order.

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

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

Tags
since
Return values
int

get_post_password()

Get post password.

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

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

Tags
since
Return values
int

get_category_ids()

Get category ids.

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

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

Tags
since
Return values
array

get_tag_ids()

Get tag ids.

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

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

Tags
since
Return values
array

get_virtual()

Get virtual.

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

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

Tags
since
Return values
bool

get_gallery_image_ids()

Returns the gallery attachment ids.

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

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

Return values
array

get_shipping_class_id()

Get shipping class ID.

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

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

Tags
since
Return values
int

get_downloads()

Get downloads.

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

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

Tags
since
Return values
array

get_download_expiry()

Get download expiry.

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

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

Tags
since
Return values
int

get_downloadable()

Get downloadable.

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

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

Tags
since
Return values
bool

get_download_limit()

Get download limit.

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

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

Tags
since
Return values
int

get_image_id()

Get main image ID.

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

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

Tags
since
Return values
string

get_rating_counts()

Get rating count.

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

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

Return values
array

of counts

get_average_rating()

Get average rating.

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

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

Return values
float

get_review_count()

Get review count.

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

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

Return values
int

set_name()

Set product name.

public set_name( $name : string ) : mixed
Parameters
$name : string

Product name.

Tags
since
Return values
mixed

set_slug()

Set product slug.

public set_slug( $slug : string ) : mixed
Parameters
$slug : string

Product slug.

Tags
since
Return values
mixed

set_date_created()

Set product created date.

public set_date_created( [ $date : string|int|null = 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
Return values
mixed

set_date_modified()

Set product modified date.

public set_date_modified( [ $date : string|int|null = 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
Return values
mixed

set_status()

Set product status.

public set_status( $status : string ) : mixed
Parameters
$status : string

Product status.

Tags
since
Return values
mixed

set_featured()

Set if the product is featured.

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

Whether the product is featured or not.

Tags
since
Return values
mixed

set_catalog_visibility()

Set catalog visibility.

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

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

Tags
since
throws

Throws exception when invalid data is found.

Return values
mixed

set_description()

Set product description.

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

Product description.

Tags
since
Return values
mixed

set_short_description()

Set product short description.

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

Product short description.

Tags
since
Return values
mixed

set_sku()

Set SKU.

public set_sku( $sku : string ) : mixed
Parameters
$sku : string

Product SKU.

Tags
since
throws

Throws exception when invalid data is found.

Return values
mixed

set_price()

Set the product's active price.

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

Price.

Return values
mixed

set_regular_price()

Set the product's regular price.

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

Regular price.

Tags
since
Return values
mixed

set_sale_price()

Set the product's sale price.

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

sale price.

Tags
since
Return values
mixed

set_date_on_sale_from()

Set date on sale from.

public set_date_on_sale_from( [ $date : string|int|null = 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
Return values
mixed

set_date_on_sale_to()

Set date on sale to.

public set_date_on_sale_to( [ $date : string|int|null = 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
Return values
mixed

set_total_sales()

Set number total of sales.

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

Total of sales.

Tags
since
Return values
mixed

set_tax_status()

Set the tax status.

public set_tax_status( $status : string ) : mixed
Parameters
$status : string

Tax status.

Tags
since
throws

Throws exception when invalid data is found.

Return values
mixed

set_tax_class()

Set the tax class.

public set_tax_class( $class : string ) : mixed
Parameters
$class : string

Tax class.

Tags
since
Return values
mixed

get_valid_tax_classes()

Return an array of valid tax classes

protected get_valid_tax_classes( ) : array
Return values
array

valid tax classes

set_manage_stock()

Set if product manage stock.

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

Whether or not manage stock is enabled.

Tags
since
Return values
mixed

set_stock_quantity()

Set number of items available for sale.

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

Stock quantity.

Tags
since
Return values
mixed

set_stock_status()

Set stock status.

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

New status.

Return values
mixed

set_backorders()

Set backorders.

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

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

Tags
since
Return values
mixed

set_low_stock_amount()

Set low stock amount.

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

Empty string if value not set.

Tags
since
Return values
mixed

set_sold_individually()

Set if should be sold individually.

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

Whether or not product is sold individually.

Tags
since
Return values
mixed

set_weight()

Set the product's weight.

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

Total weight.

Tags
since
Return values
mixed

set_length()

Set the product length.

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

Total length.

Tags
since
Return values
mixed

set_width()

Set the product width.

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

Total width.

Tags
since
Return values
mixed

set_height()

Set the product height.

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

Total height.

Tags
since
Return values
mixed

set_upsell_ids()

Set upsell IDs.

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

IDs from the up-sell products.

Tags
since
Return values
mixed

set_cross_sell_ids()

Set crosssell IDs.

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

IDs from the cross-sell products.

Tags
since
Return values
mixed

set_parent_id()

Set parent ID.

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

Product parent ID.

Tags
since
Return values
mixed

set_reviews_allowed()

Set if reviews is allowed.

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

Reviews allowed or not.

Tags
since
Return values
mixed

set_purchase_note()

Set purchase note.

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

Purchase note.

Tags
since
Return values
mixed

set_attributes()

Set product attributes.

public set_attributes( $raw_attributes : array ) : 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
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( $default_attributes : array ) : mixed
Parameters
$default_attributes : array

List of default attributes.

Tags
since
Return values
mixed

set_menu_order()

Set menu order.

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

Menu order.

Tags
since
Return values
mixed

set_post_password()

Set post password.

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

Post password.

Tags
since
Return values
mixed

set_category_ids()

Set the product categories.

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

List of terms IDs.

Tags
since
Return values
mixed

set_tag_ids()

Set the product tags.

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

List of terms IDs.

Tags
since
Return values
mixed

set_virtual()

Set if the product is virtual.

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

Whether product is virtual or not.

Tags
since
Return values
mixed

set_shipping_class_id()

Set shipping class ID.

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

Product shipping class id.

Tags
since
Return values
mixed

set_downloadable()

Set if the product is downloadable.

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

Whether product is downloadable or not.

Tags
since
Return values
mixed

set_downloads()

Set downloads.

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

Array of WC_Product_Download objects or arrays.

Tags
since
Return values
mixed

set_download_limit()

Set download limit.

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

Product download limit.

Tags
since
Return values
mixed

set_download_expiry()

Set download expiry.

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

Product download expiry.

Tags
since
Return values
mixed

set_gallery_image_ids()

Set gallery attachment ids.

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

List of image ids.

Tags
since
Return values
mixed

set_image_id()

Set main image ID.

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

Product image id.

Tags
since
Return values
mixed

set_rating_counts()

Set rating counts. Read only.

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

Product rating counts.

Return values
mixed

set_average_rating()

Set average rating. Read only.

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

Product average rating.

Return values
mixed

set_review_count()

Set review count. Read only.

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

Product review count.

Return values
mixed

validate_props()

Ensure properties are set correctly before save.

public validate_props( ) : mixed
Tags
since
Return values
mixed

save()

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

public save( ) : int
Tags
since
Return values
int

supports()

Check if a product supports a given feature.

public supports( $feature : string ) : 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
Return values
bool

True if the product supports the feature, false otherwise.

exists()

Returns whether or not the product post exists.

public exists( ) : bool
Return values
bool

is_type()

Checks the product type.

public is_type( $type : string|array ) : bool

Backwards compatibility with downloadable/virtual.

Parameters
$type : string|array

Array or string of types.

Return values
bool

is_downloadable()

Checks if a product is downloadable.

public is_downloadable( ) : bool
Return values
bool

is_virtual()

Checks if a product is virtual (has no shipping).

public is_virtual( ) : bool
Return values
bool

is_featured()

Returns whether or not the product is featured.

public is_featured( ) : bool
Return values
bool

is_sold_individually()

Check if a product is sold individually (no quantities).

public is_sold_individually( ) : bool
Return values
bool

is_visible()

Returns whether or not the product is visible in the catalog.

public is_visible( ) : bool
Return values
bool

is_purchasable()

Returns false if the product cannot be bought.

public is_purchasable( ) : bool
Return values
bool

is_on_sale()

Returns whether or not the product is on sale.

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

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

Return values
bool

has_dimensions()

Returns whether or not the product has dimensions set.

public has_dimensions( ) : bool
Return values
bool

has_weight()

Returns whether or not the product has weight set.

public has_weight( ) : bool
Return values
bool

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

needs_shipping()

Checks if a product needs shipping.

public needs_shipping( ) : bool
Return values
bool

is_taxable()

Returns whether or not the product is taxable.

public is_taxable( ) : bool
Return values
bool

is_shipping_taxable()

Returns whether or not the product shipping is taxable.

public is_shipping_taxable( ) : bool
Return values
bool

managing_stock()

Returns whether or not the product is stock managed.

public managing_stock( ) : bool
Return values
bool

backorders_allowed()

Returns whether or not the product can be backordered.

public backorders_allowed( ) : bool
Return values
bool

backorders_require_notification()

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

public backorders_require_notification( ) : bool
Return values
bool

is_on_backorder()

Check if a product is on backorder.

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

(default: 0).

Return values
bool

has_enough_stock()

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

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

Quantity of a product added to an order.

Return values
bool

has_attributes()

Returns whether or not the product has any visible attributes.

public has_attributes( ) : bool
Return values
bool

has_child()

Returns whether or not the product has any child product.

public has_child( ) : bool
Return values
bool

child_has_dimensions()

Does a child have dimensions?

public child_has_dimensions( ) : bool
Tags
since
Return values
bool

child_has_weight()

Does a child have a weight?

public child_has_weight( ) : bool
Tags
since
Return values
bool

has_file()

Check if downloadable product has a file attached.

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

file identifier.

Tags
since
Return values
bool

Whether 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
Return values
bool

get_title()

Get the product's title. For products this is the product name.

public get_title( ) : string
Return values
string

get_permalink()

Product permalink.

public get_permalink( ) : string
Return values
string

get_children()

Returns the children IDs if applicable. Overridden by child classes.

public get_children( ) : array
Return values
array

of IDs

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
Return values
int

get_price_html()

Returns the price in html format.

public get_price_html( [ $deprecated : string = '' ] ) : string
Parameters
$deprecated : string = ''

Deprecated param.

Return values
string

get_formatted_name()

Get product name with SKU or ID. Used within admin.

public get_formatted_name( ) : string
Return values
string

Formatted product name

get_min_purchase_quantity()

Get min quantity which can be purchased at once.

public get_min_purchase_quantity( ) : int
Tags
since
Return values
int

get_max_purchase_quantity()

Get max quantity which can be purchased at once.

public get_max_purchase_quantity( ) : int
Tags
since
Return values
int

Quantity or -1 if unlimited.

add_to_cart_url()

Get the add to url used mainly in loops.

public add_to_cart_url( ) : string
Return values
string

single_add_to_cart_text()

Get the add to cart button text for the single page.

public single_add_to_cart_text( ) : string
Return values
string

add_to_cart_text()

Get the add to cart button text.

public add_to_cart_text( ) : string
Return values
string

add_to_cart_description()

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

public add_to_cart_description( ) : string
Tags
since
Return values
string

get_image()

Returns the main product image.

public get_image( [ $size : string = 'woocommerce_thumbnail' ] [, $attr : array = array() ] [, $placeholder : bool = 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_shipping_class()

Returns the product shipping class SLUG.

public get_shipping_class( ) : string
Return values
string

get_attribute()

Returns a single product attribute as a string.

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

to get.

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( [ $value : int = 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_file()

Get a file by $download_id.

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

file identifier.

Return values
array|false

if not found

get_file_download_path()

Get file download path identified by $download_id.

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

file identifier.

Return values
string

get_price_suffix()

Get the suffix to display after prices > 0.

public get_price_suffix( [ $price : string = '' ] [, $qty : int = 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().

Return values
string

get_availability()

Returns the availability of the product.

public get_availability( ) : string[]
Return values
string[]

get_availability_text()

Get availability text based on stock status.

protected get_availability_text( ) : string
Return values
string

get_availability_class()

Get availability classname based on stock status.

protected get_availability_class( ) : string
Return values
string

__isset()

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

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

Key name.

Return values
bool

__get()

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

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

Key name.

Return values
mixed

get_variation_default_attributes()

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

public get_variation_default_attributes( ) : array
Tags
deprecated
Return values
array

get_gallery_attachment_ids()

Returns the gallery attachment ids.

public get_gallery_attachment_ids( ) : array
Tags
deprecated
Return values
array

set_stock()

Set stock level of the product.

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

reduce_stock()

Reduce stock level of the product.

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

Amount to reduce by. Default: 1

Tags
deprecated
Return values
int

new stock level

increase_stock()

Increase stock level of the product.

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

Amount to increase by. Default 1.

Tags
deprecated
Return values
int

new stock level

check_stock_status()

Check if the stock status needs changing.

public check_stock_status( ) : mixed
Tags
deprecated

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

Return values
mixed

get_related()

Get and return related products.

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

Use wc_get_related_products instead.

Return values
array

get_related_terms()

Retrieves related product terms.

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

Use wc_get_product_term_ids instead.

Return values
array

build_related_query()

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

Use Product Data Store get_related_products_query instead.

Return values
mixed

get_child()

Returns the child product.

public get_child( $child_id : mixed ) : WC_Product|WC_Product_variation
Parameters
$child_id : mixed
Tags
deprecated

Use wc_get_product instead.

Return values
WC_Product|WC_Product_variation

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
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( $from : string , $to : mixed ) : string
Parameters
$from : string

String or float to wrap with 'from' text

$to : mixed

String or float to wrap with 'to' text

Tags
deprecated

Use wc_format_sale_price instead.

Return values
string

list_attributes()

Lists a table of attributes for the product page.

public list_attributes( ) : mixed
Tags
deprecated

Use wc_display_product_attributes instead.

Return values
mixed

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( [ $qty : int = 1 ] [, $price : string = '' ] ) : string
Parameters
$qty : int = 1
$price : string = ''

to calculate, left blank to just use get_price()

Tags
deprecated

Use wc_get_price_including_tax instead.

Return values
string

get_display_price()

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

public get_display_price( [ $price : string = '' ] [, $qty : int = 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

Use wc_get_price_to_display instead.

Return values
string

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( [ $qty : int = 1 ] [, $price : string = '' ] ) : 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

Use wc_get_price_excluding_tax instead.

Return values
string

adjust_price()

Adjust a products price dynamically.

public adjust_price( $price : mixed ) : mixed
Parameters
$price : mixed
Tags
deprecated
Return values
mixed

get_categories()

Returns the product categories.

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

(default: ', ').

$before : string = ''

(default: '').

$after : string = ''

(default: '').

Tags
deprecated
Return values
string

get_tags()

Returns the product tags.

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

(default: ', ').

$before : string = ''

(default: '').

$after : string = ''

(default: '').

Tags
deprecated
Return values
array

get_post_data()

Get the product's post data.

public get_post_data( ) : WP_Post
Tags
deprecated
Return values
WP_Post

get_upsells()

Returns the upsell product ids.

public get_upsells( ) : array
Tags
deprecated
Return values
array

get_cross_sells()

Returns the cross sell product ids.

public get_cross_sells( ) : array
Tags
deprecated
Return values
array

has_default_attributes()

Check if variable product has default attributes set.

public has_default_attributes( ) : bool
Tags
deprecated
Return values
bool

get_variation_description()

Get product variation description.

public get_variation_description( ) : string
Tags
deprecated
Return values
string

has_all_attributes_set()

Check if all variation's attributes are set.

public has_all_attributes_set( ) : bool
Tags
deprecated
Return values
bool

parent_is_visible()

Returns whether or not the variations parent is visible.

public parent_is_visible( ) : bool
Tags
deprecated
Return values
bool

get_total_stock()

Get total stock - This is the stock of parent and children combined.

public get_total_stock( ) : int
Tags
deprecated
Return values
int

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( [ $flat : bool = false ] ) : string
Parameters
$flat : bool = false
Tags
deprecated
Return values
string

variable_product_sync()

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

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

not used in core.

Return values
mixed

sync_attributes()

Sync the variable product's attributes with the variations.

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

get_matching_variation()

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

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

in favour of Product data store's find_matching_product_variation.

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

Unused.

Return values
bool

get_rating_html()

Returns the product rating in html format.

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

(default: '')

Tags
deprecated
Return values
string

sync_average_rating()

Sync product rating. Can be called statically.

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

sync_rating_count()

Sync product rating count. Can be called statically.

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

grouped_product_sync()

public grouped_product_sync( ) : mixed
Tags
deprecated

Sync is taken care of during save - no need to call this directly.

Return values
mixed

__construct()

Default constructor.

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

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

Return values
mixed

__sleep()

Only store the object ID to avoid serializing the data object instance.

public __sleep( ) : array
Return values
array

__wakeup()

Re-run the constructor with the object ID.

public __wakeup( ) : mixed

If the object no longer exists, remove the ID.

Return values
mixed

__clone()

When the object is cloned, make sure meta is duplicated correctly.

public __clone( ) : mixed
Tags
since
Return values
mixed

get_data_store()

Get the data store.

public get_data_store( ) : object
Tags
since
Return values
object

get_id()

Returns the unique ID for this object.

public get_id( ) : int
Tags
since
Return values
int

delete()

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

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

Should the date be deleted permanently.

Tags
since
Return values
bool

result

save()

Save should create or update based on object existence.

public save( ) : int
Tags
since
Return values
int

__toString()

Change data to JSON format.

public __toString( ) : string
Tags
since
Return values
string

Data in JSON format.

get_data()

Returns all data for this object.

public get_data( ) : array
Tags
since
Return values
array

get_data_keys()

Returns array of expected data keys for this object.

public get_data_keys( ) : array
Tags
since
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
Return values
array

filter_null_meta()

Filter null meta values from array.

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

Meta value to check.

Tags
since
Return values
bool

get_meta_data()

Get All Meta Data.

public get_meta_data( ) : array
Tags
since
Return values
array

of objects.

is_internal_meta_key()

Check if the key is an internal one.

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

Key to check.

Tags
since
Return values
bool

true if it's an internal key, false otherwise

get_meta()

Get Meta Data by Key.

public get_meta( [ $key : string = '' ] [, $single : bool = true ] [, $context : string = '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
Return values
mixed

meta_exists()

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

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

Meta Key.

Tags
since
Return values
bool

set_meta_data()

Set all meta data from array.

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

Key/Value pairs.

Tags
since
Return values
mixed

add_meta_data()

Add meta data.

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

Meta key.

$value : string|array

Meta value.

$unique : bool = false

Should this be a unique key?.

Tags
since
Return values
mixed

update_meta_data()

Update meta data by key or ID, if provided.

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

Meta key.

$value : string|array

Meta value.

$meta_id : int

Meta ID.

Tags
since
Return values
mixed

delete_meta_data()

Delete meta data.

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

Meta key.

Tags
since
Return values
mixed

delete_meta_data_by_mid()

Delete meta data.

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

Meta ID.

Tags
since
Return values
mixed

maybe_read_meta_data()

Read meta data if null.

protected maybe_read_meta_data( ) : mixed
Tags
since
Return values
mixed

read_meta_data()

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

public read_meta_data( [ $force_read : bool = 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
Return values
mixed

save_meta_data()

Update Meta Data in the database.

public save_meta_data( ) : mixed
Tags
since
Return values
mixed

set_id()

Set ID.

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

ID.

Tags
since
Return values
mixed

set_defaults()

Set all props to default values.

public set_defaults( ) : mixed
Tags
since
Return values
mixed

set_object_read()

Set object read property.

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

Should read?.

Tags
since
Return values
mixed

get_object_read()

Get object read property.

public get_object_read( ) : bool
Tags
since
Return values
bool

set_props()

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

public set_props( $props : array [, $context : string = '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
Return values
bool|WP_Error

set_prop()

Sets a prop for a setter method.

protected set_prop( $prop : string , $value : mixed ) : 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
Return values
mixed

get_changes()

Return data changes only.

public get_changes( ) : array
Tags
since
Return values
array

apply_changes()

Merge changes with data and clear.

public apply_changes( ) : mixed
Tags
since
Return values
mixed

get_hook_prefix()

Prefix for action and filter hooks on data.

protected get_hook_prefix( ) : string
Tags
since
Return values
string

get_prop()

Gets a prop for a getter method.

protected get_prop( $prop : string [, $context : string = '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
Return values
mixed

set_date_prop()

Sets a date prop whilst handling formatting and datetime objects.

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

Name of prop to set.

$value : string|int

Value of the prop.

Tags
since
Return values
mixed

error()

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

protected error( $code : string , $message : string [, $http_status_code : int = 400 ] [, $data : array = 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

Data Exception.

since
Return values
mixed
Back to the top