PHP Class WC_Product

The WooCommerce product class handles individual product data.
Author: WooThemes
Mostra file Open project: woocommerce/woocommerce Class Usage Examples

Protected Properties

Property Type Description
$cache_group string Cache group.
$data array Stores product data.
$post_type string Post type.
$supports array Supported features such as 'ajax_add_to_cart'.

Public Methods

Method Description
__construct ( integer | WC_Product | object $product ) Get the product if ID is passed, otherwise the product is new and empty.
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.
backorders_allowed ( ) : boolean Returns whether or not the product can be backordered.
backorders_require_notification ( ) : boolean Returns whether or not the product needs to notify the customer on backorder.
child_has_dimensions ( ) : boolean Does a child have dimensions?
child_has_weight ( ) : boolean Does a child have a weight?
exists ( ) : boolean Returns whether or not the product post exists.
get_attribute ( string $attribute ) : string Returns a single product attribute as a string.
get_attributes ( string $context = 'view' ) : array Returns product attributes.
get_average_rating ( string $context = 'view' ) : float Get average rating.
get_backorders ( string $context = 'view' ) : string Get backorders.
get_catalog_visibility ( string $context = 'view' ) : string Get catalog visibility.
get_category_ids ( string $context = 'view' ) : array Get category ids.
get_children ( ) : array Returns the children IDs if applicable. Overridden by child classes.
get_cross_sell_ids ( string $context = 'view' ) : array Get cross sell IDs.
get_data ( ) : array Get all class data in array format.
get_date_created ( string $context = 'view' ) : string Get product created date.
get_date_modified ( string $context = 'view' ) : string Get product modified date.
get_date_on_sale_from ( string $context = 'view' ) : string Get date on sale from.
get_date_on_sale_to ( string $context = 'view' ) : string Get date on sale to.
get_default_attributes ( string $context = 'view' ) : array Get default attributes.
get_description ( string $context = 'view' ) : string Get product description.
get_dimensions ( $formatted = true ) : string | array Returns formatted dimensions.
get_download_expiry ( string $context = 'view' ) : integer Get download expiry.
get_download_limit ( string $context = 'view' ) : integer Get download limit.
get_downloadable ( string $context = 'view' ) : boolean Get downloadable.
get_downloads ( string $context = 'view' ) : array Get downloads.
get_featured ( string $context = 'view' ) : boolean If the product is featured.
get_file ( string $download_id = '' ) : array | false Get a file by $download_id.
get_file_download_path ( string $download_id ) : string Get file download path identified by $download_id.
get_formatted_name ( ) : string Get product name with SKU or ID. Used within admin.
get_gallery_image_ids ( string $context = 'view' ) : array Returns the gallery attachment ids.
get_height ( string $context = 'view' ) : string Returns the product height.
get_image ( string $size = 'shop_thumbnail', array $attr = [], $placeholder = true ) : string Returns the main product image.
get_image_id ( string $context = 'view' ) : string Get main image ID.
get_length ( string $context = 'view' ) : string Returns the product length.
get_manage_stock ( string $context = 'view' ) : boolean Return if product manage stock.
get_menu_order ( string $context = 'view' ) : integer Get menu order.
get_name ( string $context = 'view' ) : string Get product name.
get_parent_id ( string $context = 'view' ) : integer Get parent ID.
get_permalink ( ) : string Product permalink.
get_price ( string $context = 'view' ) : string Returns the product's active price.
get_price_html ( $deprecated = '' ) : string Returns the price in html format.
get_purchase_note ( string $context = 'view' ) : string Get purchase note.
get_rating_count ( integer $value = null ) : integer Get the total amount (COUNT) of ratings, or just the count for one rating e.g. number of 5 star ratings.
get_rating_counts ( string $context = 'view' ) : array Get rating count.
get_regular_price ( string $context = 'view' ) : string Returns the product's regular price.
get_review_count ( string $context = 'view' ) : integer Get review count.
get_reviews_allowed ( string $context = 'view' ) : boolean Return if reviews is allowed.
get_sale_price ( string $context = 'view' ) : string Returns the product's sale price.
get_shipping_class ( ) : string Returns the product shipping class SLUG.
get_shipping_class_id ( string $context = 'view' ) : integer Get shipping class ID.
get_short_description ( string $context = 'view' ) : string Get product short description.
get_sku ( string $context = 'view' ) : string Get SKU (Stock-keeping unit) - product unique ID.
get_slug ( string $context = 'view' ) : string Get product slug.
get_sold_individually ( string $context = 'view' ) : boolean Return if should be sold individually.
get_status ( string $context = 'view' ) : string Get product status.
get_stock_managed_by_id ( ) : integer If the stock level comes from another product ID, this should be modified.
get_stock_quantity ( string $context = 'view' ) : integer | null Returns number of items available for sale.
get_stock_status ( string $context = 'view' ) : string Return the stock status.
get_tag_ids ( string $context = 'view' ) : array Get tag ids.
get_tax_class ( string $context = 'view' ) : string Returns the tax class.
get_tax_status ( string $context = 'view' ) : string Returns the tax status.
get_title ( ) : string Get the product's title. For products this is the product name.
get_total_sales ( string $context = 'view' ) : integer Get number total of sales.
get_type ( ) : string Get internal type. Should return string and *should be overridden* by child classes.
get_upsell_ids ( string $context = 'view' ) : array Get upsel IDs.
get_virtual ( string $context = 'view' ) : boolean Get virtual.
get_weight ( string $context = 'view' ) : string Returns the product's weight.
get_width ( string $context = 'view' ) : string Returns the product width.
has_attributes ( ) : boolean Returns whether or not the product has any visible attributes.
has_child ( ) : boolean Returns whether or not the product has any child product.
has_dimensions ( ) : boolean Returns whether or not the product has dimensions set.
has_enough_stock ( mixed $quantity ) : boolean Returns whether or not the product has enough stock for the order.
has_file ( string $download_id = '' ) : boolean Check if downloadable product has a file attached.
has_weight ( ) : boolean Returns whether or not the product has weight set.
is_downloadable ( ) : boolean Checks if a product is downloadable.
is_featured ( ) : boolean Returns whether or not the product is featured.
is_in_stock ( ) : boolean Returns whether or not the product is in stock.
is_on_backorder ( integer $qty_in_cart ) : boolean Check if a product is on backorder.
is_on_sale ( ) : boolean Returns whether or not the product is on sale.
is_purchasable ( ) : boolean Returns false if the product cannot be bought.
is_shipping_taxable ( ) : boolean Returns whether or not the product shipping is taxable.
is_sold_individually ( ) : boolean Check if a product is sold individually (no quantities).
is_taxable ( ) : boolean Returns whether or not the product is taxable.
is_type ( string $type ) : boolean Checks the product type.
is_virtual ( ) : boolean Checks if a product is virtual (has no shipping).
is_visible ( ) : boolean Returns whether or not the product is visible in the catalog.
managing_stock ( ) : boolean Returns whether or not the product is stock managed.
needs_shipping ( ) : boolean Checks if a product needs shipping.
save ( ) Save data (either create or update depending on if we are working on an existing product).
set_attributes ( array $raw_attributes ) Set product attributes.
set_average_rating ( float $average ) Set average rating. Read only.
set_backorders ( string $backorders ) Set backorders.
set_catalog_visibility ( string $visibility ) Set catalog visibility.
set_category_ids ( array $term_ids ) Set the product categories.
set_cross_sell_ids ( array $cross_sell_ids ) Set crosssell IDs.
set_date_created ( string $timestamp ) Set product created date.
set_date_modified ( string $timestamp ) Set product modified date.
set_date_on_sale_from ( string $timestamp ) Set date on sale from.
set_date_on_sale_to ( string $timestamp ) Set date on sale to.
set_default_attributes ( array $default_attributes ) Set default attributes.
set_description ( string $description ) Set product description.
set_download_expiry ( integer $download_expiry ) Set download expiry.
set_download_limit ( integer $download_limit ) Set download limit.
set_downloadable ( $downloadable ) Set if the product is downloadable.
set_downloads ( $downloads_array ) Set downloads.
set_featured ( $featured ) Set if the product is featured.
set_gallery_image_ids ( array $image_ids ) Set gallery attachment ids.
set_height ( float | string $height ) Set the product height.
set_image_id ( integer $image_id = '' ) Set main image ID.
set_length ( float | string $length ) Set the product length.
set_manage_stock ( $manage_stock ) Set if product manage stock.
set_menu_order ( integer $menu_order ) Set menu order.
set_name ( string $name ) Set product name.
set_parent_id ( integer $parent_id ) Set parent ID.
set_price ( string $price ) Set the product's active price.
set_purchase_note ( string $purchase_note ) Set purchase note.
set_rating_counts ( array $counts ) Set rating counts. Read only.
set_regular_price ( string $price ) Set the product's regular price.
set_review_count ( integer $count ) Set review count. Read only.
set_reviews_allowed ( boolean $reviews_allowed ) Set if reviews is allowed.
set_sale_price ( string $price ) Set the product's sale price.
set_shipping_class_id ( $id ) Set shipping class ID.
set_short_description ( string $short_description ) Set product short description.
set_sku ( string $sku ) Set SKU.
set_slug ( string $slug ) Set product slug.
set_sold_individually ( $sold_individually ) Set if should be sold individually.
set_status ( string $status ) Set product status.
set_stock_quantity ( float | null $quantity ) Set number of items available for sale.
set_stock_status ( string $status = '' ) Set stock status.
set_tag_ids ( array $term_ids ) Set the product tags.
set_tax_class ( string $class ) Set the tax class.
set_tax_status ( string $status ) Set the tax status.
set_total_sales ( integer $total ) Set number total of sales.
set_upsell_ids ( array $upsell_ids ) Set upsell IDs.
set_virtual ( $virtual ) Set if the product is virtual.
set_weight ( float | string $weight ) Set the product's weight.
set_width ( float | string $width ) Set the product width.
single_add_to_cart_text ( ) : string Get the add to cart button text for the single page.
supports ( string $feature ) : boolean Check if a product supports a given feature.
validate_props ( ) Ensure properties are set correctly before save.

Protected Methods

Method Description
get_hook_prefix ( ) : string Prefix for action and filter hooks on data.
sanitize_term_ids ( array $terms, string $taxonomy ) Get term ids from either a list of names, ids, or terms.

Method Details

__construct() public method

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.
public __construct ( integer | WC_Product | object $product )
$product integer | WC_Product | object Product to init.

add_to_cart_text() public method

Get the add to cart button text.
public add_to_cart_text ( ) : string
return string

add_to_cart_url() public method

Get the add to url used mainly in loops.
public add_to_cart_url ( ) : string
return string

backorders_allowed() public method

Returns whether or not the product can be backordered.
public backorders_allowed ( ) : boolean
return boolean

backorders_require_notification() public method

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

child_has_dimensions() public method

Does a child have dimensions?
Since: 2.7.0
public child_has_dimensions ( ) : boolean
return boolean

child_has_weight() public method

Does a child have a weight?
Since: 2.7.0
public child_has_weight ( ) : boolean
return boolean

exists() public method

Returns whether or not the product post exists.
public exists ( ) : boolean
return boolean

get_attribute() public method

Returns a single product attribute as a string.
public get_attribute ( string $attribute ) : string
$attribute string to get.
return string

get_attributes() public method

Returns product attributes.
public get_attributes ( string $context = 'view' ) : array
$context string
return array

get_average_rating() public method

Get average rating.
public get_average_rating ( string $context = 'view' ) : float
$context string
return float

get_backorders() public method

Get backorders.
Since: 2.7.0
public get_backorders ( string $context = 'view' ) : string
$context string
return string yes no or notify

get_catalog_visibility() public method

Get catalog visibility.
Since: 2.7.0
public get_catalog_visibility ( string $context = 'view' ) : string
$context string
return string

get_category_ids() public method

Get category ids.
Since: 2.7.0
public get_category_ids ( string $context = 'view' ) : array
$context string
return array

get_children() public method

Returns the children IDs if applicable. Overridden by child classes.
public get_children ( ) : array
return array of IDs

get_cross_sell_ids() public method

Get cross sell IDs.
Since: 2.7.0
public get_cross_sell_ids ( string $context = 'view' ) : array
$context string
return array

get_data() public method

Get all class data in array format.
Since: 2.7.0
public get_data ( ) : array
return array

get_date_created() public method

Get product created date.
Since: 2.7.0
public get_date_created ( string $context = 'view' ) : string
$context string
return string Timestamp.

get_date_modified() public method

Get product modified date.
Since: 2.7.0
public get_date_modified ( string $context = 'view' ) : string
$context string
return string Timestamp.

get_date_on_sale_from() public method

Get date on sale from.
Since: 2.7.0
public get_date_on_sale_from ( string $context = 'view' ) : string
$context string
return string

get_date_on_sale_to() public method

Get date on sale to.
Since: 2.7.0
public get_date_on_sale_to ( string $context = 'view' ) : string
$context string
return string

get_default_attributes() public method

Get default attributes.
Since: 2.7.0
public get_default_attributes ( string $context = 'view' ) : array
$context string
return array

get_description() public method

Get product description.
Since: 2.7.0
public get_description ( string $context = 'view' ) : string
$context string
return string

get_dimensions() public method

Returns formatted dimensions.
public get_dimensions ( $formatted = true ) : string | array
$formatted 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 string | array

get_download_expiry() public method

Get download expiry.
Since: 2.7.0
public get_download_expiry ( string $context = 'view' ) : integer
$context string
return integer

get_download_limit() public method

Get download limit.
Since: 2.7.0
public get_download_limit ( string $context = 'view' ) : integer
$context string
return integer

get_downloadable() public method

Get downloadable.
Since: 2.7.0
public get_downloadable ( string $context = 'view' ) : boolean
$context string
return boolean

get_downloads() public method

Get downloads.
Since: 2.7.0
public get_downloads ( string $context = 'view' ) : array
$context string
return array

get_file() public method

Get a file by $download_id.
public get_file ( string $download_id = '' ) : array | false
$download_id string file identifier
return array | false if not found

get_file_download_path() public method

Get file download path identified by $download_id.
public get_file_download_path ( string $download_id ) : string
$download_id string file identifier
return string

get_formatted_name() public method

Get product name with SKU or ID. Used within admin.
public get_formatted_name ( ) : string
return string Formatted product name

get_height() public method

Returns the product height.
public get_height ( string $context = 'view' ) : string
$context string
return string

get_hook_prefix() protected method

Prefix for action and filter hooks on data.
Since: 2.7.0
protected get_hook_prefix ( ) : string
return string

get_image() public method

Returns the main product image.
public get_image ( string $size = 'shop_thumbnail', array $attr = [], $placeholder = true ) : string
$size string (default: 'shop_thumbnail')
$attr array
return string

get_image_id() public method

Get main image ID.
Since: 2.7.0
public get_image_id ( string $context = 'view' ) : string
$context string
return string

get_length() public method

Returns the product length.
public get_length ( string $context = 'view' ) : string
$context string
return string

get_manage_stock() public method

Return if product manage stock.
Since: 2.7.0
public get_manage_stock ( string $context = 'view' ) : boolean
$context string
return boolean

get_menu_order() public method

Get menu order.
Since: 2.7.0
public get_menu_order ( string $context = 'view' ) : integer
$context string
return integer

get_name() public method

Get product name.
Since: 2.7.0
public get_name ( string $context = 'view' ) : string
$context string
return string

get_parent_id() public method

Get parent ID.
Since: 2.7.0
public get_parent_id ( string $context = 'view' ) : integer
$context string
return integer

get_price() public method

Returns the product's active price.
public get_price ( string $context = 'view' ) : string
$context string
return string price

get_price_html() public method

Returns the price in html format.
public get_price_html ( $deprecated = '' ) : string
return string

get_purchase_note() public method

Get purchase note.
Since: 2.7.0
public get_purchase_note ( string $context = 'view' ) : string
$context string
return string

get_rating_count() public method

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 ( integer $value = null ) : integer
$value integer Optional. Rating value to get the count for. By default returns the count of all rating values.
return integer

get_rating_counts() public method

Get rating count.
public get_rating_counts ( string $context = 'view' ) : array
$context string
return array of counts

get_regular_price() public method

Returns the product's regular price.
public get_regular_price ( string $context = 'view' ) : string
$context string
return string price

get_review_count() public method

Get review count.
public get_review_count ( string $context = 'view' ) : integer
$context string
return integer

get_reviews_allowed() public method

Return if reviews is allowed.
Since: 2.7.0
public get_reviews_allowed ( string $context = 'view' ) : boolean
$context string
return boolean

get_sale_price() public method

Returns the product's sale price.
public get_sale_price ( string $context = 'view' ) : string
$context string
return string price

get_shipping_class() public method

Returns the product shipping class SLUG.
public get_shipping_class ( ) : string
return string

get_shipping_class_id() public method

Get shipping class ID.
Since: 2.7.0
public get_shipping_class_id ( string $context = 'view' ) : integer
$context string
return integer

get_short_description() public method

Get product short description.
Since: 2.7.0
public get_short_description ( string $context = 'view' ) : string
$context string
return string

get_sku() public method

Get SKU (Stock-keeping unit) - product unique ID.
public get_sku ( string $context = 'view' ) : string
$context string
return string

get_slug() public method

Get product slug.
Since: 2.7.0
public get_slug ( string $context = 'view' ) : string
$context string
return string

get_sold_individually() public method

Return if should be sold individually.
Since: 2.7.0
public get_sold_individually ( string $context = 'view' ) : boolean
$context string
return boolean

get_status() public method

Get product status.
Since: 2.7.0
public get_status ( string $context = 'view' ) : string
$context string
return string

get_stock_managed_by_id() public method

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

get_stock_quantity() public method

Returns number of items available for sale.
public get_stock_quantity ( string $context = 'view' ) : integer | null
$context string
return integer | null

get_stock_status() public method

Return the stock status.
Since: 2.7.0
public get_stock_status ( string $context = 'view' ) : string
$context string
return string

get_tag_ids() public method

Get tag ids.
Since: 2.7.0
public get_tag_ids ( string $context = 'view' ) : array
$context string
return array

get_tax_class() public method

Returns the tax class.
public get_tax_class ( string $context = 'view' ) : string
$context string
return string

get_tax_status() public method

Returns the tax status.
public get_tax_status ( string $context = 'view' ) : string
$context string
return string

get_title() public method

Get the product's title. For products this is the product name.
public get_title ( ) : string
return string

get_total_sales() public method

Get number total of sales.
Since: 2.7.0
public get_total_sales ( string $context = 'view' ) : integer
$context string
return integer

get_type() public method

Get internal type. Should return string and *should be overridden* by child classes.
Since: 2.7.0
public get_type ( ) : string
return string

get_upsell_ids() public method

Get upsel IDs.
Since: 2.7.0
public get_upsell_ids ( string $context = 'view' ) : array
$context string
return array

get_virtual() public method

Get virtual.
Since: 2.7.0
public get_virtual ( string $context = 'view' ) : boolean
$context string
return boolean

get_weight() public method

Returns the product's weight.
public get_weight ( string $context = 'view' ) : string
$context string
return string

get_width() public method

Returns the product width.
public get_width ( string $context = 'view' ) : string
$context string
return string

has_attributes() public method

Returns whether or not the product has any visible attributes.
public has_attributes ( ) : boolean
return boolean

has_child() public method

Returns whether or not the product has any child product.
public has_child ( ) : boolean
return boolean

has_dimensions() public method

Returns whether or not the product has dimensions set.
public has_dimensions ( ) : boolean
return boolean

has_enough_stock() public method

Returns whether or not the product has enough stock for the order.
public has_enough_stock ( mixed $quantity ) : boolean
$quantity mixed
return boolean

has_file() public method

Check if downloadable product has a file attached.
Since: 1.6.2
public has_file ( string $download_id = '' ) : boolean
$download_id string file identifier
return boolean Whether downloadable product has a file attached.

has_weight() public method

Returns whether or not the product has weight set.
public has_weight ( ) : boolean
return boolean

is_downloadable() public method

Checks if a product is downloadable.
public is_downloadable ( ) : boolean
return boolean

is_in_stock() public method

Returns whether or not the product is in stock.
public is_in_stock ( ) : boolean
return boolean

is_on_backorder() public method

Check if a product is on backorder.
public is_on_backorder ( integer $qty_in_cart ) : boolean
$qty_in_cart integer (default: 0)
return boolean

is_on_sale() public method

Returns whether or not the product is on sale.
public is_on_sale ( ) : boolean
return boolean

is_purchasable() public method

Returns false if the product cannot be bought.
public is_purchasable ( ) : boolean
return boolean

is_shipping_taxable() public method

Returns whether or not the product shipping is taxable.
public is_shipping_taxable ( ) : boolean
return boolean

is_sold_individually() public method

Check if a product is sold individually (no quantities).
public is_sold_individually ( ) : boolean
return boolean

is_taxable() public method

Returns whether or not the product is taxable.
public is_taxable ( ) : boolean
return boolean

is_type() public method

Backwards compat with downloadable/virtual.
public is_type ( string $type ) : boolean
$type string Array or string of types
return boolean

is_virtual() public method

Checks if a product is virtual (has no shipping).
public is_virtual ( ) : boolean
return boolean

is_visible() public method

Returns whether or not the product is visible in the catalog.
public is_visible ( ) : boolean
return boolean

managing_stock() public method

Returns whether or not the product is stock managed.
public managing_stock ( ) : boolean
return boolean

needs_shipping() public method

Checks if a product needs shipping.
public needs_shipping ( ) : boolean
return boolean

sanitize_term_ids() protected method

Get term ids from either a list of names, ids, or terms.
Since: 2.7.0
protected sanitize_term_ids ( array $terms, string $taxonomy )
$terms array
$taxonomy string

save() public method

Save data (either create or update depending on if we are working on an existing product).
Since: 2.7.0
public save ( )

set_attributes() public method

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.
Since: 2.7.0
public set_attributes ( array $raw_attributes )
$raw_attributes array Array of WC_Product_Attribute objects.

set_average_rating() public method

Set average rating. Read only.
public set_average_rating ( float $average )
$average float

set_backorders() public method

Set backorders.
Since: 2.7.0
public set_backorders ( string $backorders )
$backorders string Options: 'yes', 'no' or 'notify'.

set_catalog_visibility() public method

Set catalog visibility.
Since: 2.7.0
public set_catalog_visibility ( string $visibility )
$visibility string Options: 'hidden', 'visible', 'search' and 'catalog'.

set_category_ids() public method

Set the product categories.
Since: 2.7.0
public set_category_ids ( array $term_ids )
$term_ids array List of terms IDs.

set_cross_sell_ids() public method

Set crosssell IDs.
Since: 2.7.0
public set_cross_sell_ids ( array $cross_sell_ids )
$cross_sell_ids array IDs from the cross-sell products.

set_date_created() public method

Set product created date.
Since: 2.7.0
public set_date_created ( string $timestamp )
$timestamp string Timestamp.

set_date_modified() public method

Set product modified date.
Since: 2.7.0
public set_date_modified ( string $timestamp )
$timestamp string Timestamp.

set_date_on_sale_from() public method

Set date on sale from.
Since: 2.7.0
public set_date_on_sale_from ( string $timestamp )
$timestamp string Sale from date.

set_date_on_sale_to() public method

Set date on sale to.
Since: 2.7.0
public set_date_on_sale_to ( string $timestamp )
$timestamp string Sale to date.

set_default_attributes() public method

Set default attributes.
Since: 2.7.0
public set_default_attributes ( array $default_attributes )
$default_attributes array List of default attributes.

set_description() public method

Set product description.
Since: 2.7.0
public set_description ( string $description )
$description string Product description.

set_download_expiry() public method

Set download expiry.
Since: 2.7.0
public set_download_expiry ( integer $download_expiry )
$download_expiry integer

set_download_limit() public method

Set download limit.
Since: 2.7.0
public set_download_limit ( integer $download_limit )
$download_limit integer

set_downloadable() public method

Set if the product is downloadable.
Since: 2.7.0
public set_downloadable ( $downloadable )

set_downloads() public method

Set downloads.
Since: 2.7.0
public set_downloads ( $downloads_array )
$downloads_array array of WC_Product_Download objects or arrays.

set_height() public method

Set the product height.
Since: 2.7.0
public set_height ( float | string $height )
$height float | string Total height.

set_image_id() public method

Set main image ID.
Since: 2.7.0
public set_image_id ( integer $image_id = '' )
$image_id integer

set_length() public method

Set the product length.
Since: 2.7.0
public set_length ( float | string $length )
$length float | string Total length.

set_manage_stock() public method

Set if product manage stock.
Since: 2.7.0
public set_manage_stock ( $manage_stock )

set_menu_order() public method

Set menu order.
Since: 2.7.0
public set_menu_order ( integer $menu_order )
$menu_order integer Menu order.

set_name() public method

Set product name.
Since: 2.7.0
public set_name ( string $name )
$name string Product name.

set_parent_id() public method

Set parent ID.
Since: 2.7.0
public set_parent_id ( integer $parent_id )
$parent_id integer Product parent ID.

set_price() public method

Set the product's active price.
public set_price ( string $price )
$price string Price.

set_purchase_note() public method

Set purchase note.
Since: 2.7.0
public set_purchase_note ( string $purchase_note )
$purchase_note string Purchase note.

set_rating_counts() public method

Set rating counts. Read only.
public set_rating_counts ( array $counts )
$counts array

set_regular_price() public method

Set the product's regular price.
Since: 2.7.0
public set_regular_price ( string $price )
$price string Regular price.

set_review_count() public method

Set review count. Read only.
public set_review_count ( integer $count )
$count integer

set_reviews_allowed() public method

Set if reviews is allowed.
Since: 2.7.0
public set_reviews_allowed ( boolean $reviews_allowed )
$reviews_allowed boolean Reviews allowed or not.

set_sale_price() public method

Set the product's sale price.
Since: 2.7.0
public set_sale_price ( string $price )
$price string sale price.

set_shipping_class_id() public method

Set shipping class ID.
Since: 2.7.0
public set_shipping_class_id ( $id )

set_short_description() public method

Set product short description.
Since: 2.7.0
public set_short_description ( string $short_description )
$short_description string Product short description.

set_sku() public method

Set SKU.
Since: 2.7.0
public set_sku ( string $sku )
$sku string Product SKU.

set_slug() public method

Set product slug.
Since: 2.7.0
public set_slug ( string $slug )
$slug string Product slug.

set_sold_individually() public method

Set if should be sold individually.
Since: 2.7.0
public set_sold_individually ( $sold_individually )

set_status() public method

Set product status.
Since: 2.7.0
public set_status ( string $status )
$status string Product status.

set_stock_quantity() public method

Set number of items available for sale.
Since: 2.7.0
public set_stock_quantity ( float | null $quantity )
$quantity float | null Stock quantity.

set_stock_status() public method

Set stock status.
public set_stock_status ( string $status = '' )
$status string New status.

set_tag_ids() public method

Set the product tags.
Since: 2.7.0
public set_tag_ids ( array $term_ids )
$term_ids array List of terms IDs.

set_tax_class() public method

Set the tax class.
Since: 2.7.0
public set_tax_class ( string $class )
$class string Tax class.

set_tax_status() public method

Set the tax status.
Since: 2.7.0
public set_tax_status ( string $status )
$status string Tax status.

set_total_sales() public method

Set number total of sales.
Since: 2.7.0
public set_total_sales ( integer $total )
$total integer Total of sales.

set_upsell_ids() public method

Set upsell IDs.
Since: 2.7.0
public set_upsell_ids ( array $upsell_ids )
$upsell_ids array IDs from the up-sell products.

set_virtual() public method

Set if the product is virtual.
Since: 2.7.0
public set_virtual ( $virtual )

set_weight() public method

Set the product's weight.
Since: 2.7.0
public set_weight ( float | string $weight )
$weight float | string Total weight.

set_width() public method

Set the product width.
Since: 2.7.0
public set_width ( float | string $width )
$width float | string Total width.

single_add_to_cart_text() public method

Get the add to cart button text for the single page.
public single_add_to_cart_text ( ) : string
return string

supports() public method

Product classes should override this to declare support (or lack of support) for a feature.
Since: 2.5.0
public supports ( string $feature ) : boolean
$feature string string The name of a feature to test support for.
return boolean True if the product supports the feature, false otherwise.

validate_props() public method

Ensure properties are set correctly before save.
Since: 2.7.0
public validate_props ( )

Property Details

$cache_group protected_oe property

Cache group.
protected string $cache_group
return string

$data protected_oe property

Stores product data.
protected array $data
return array

$post_type protected_oe property

Post type.
protected string $post_type
return string

$supports protected_oe property

Supported features such as 'ajax_add_to_cart'.
protected array $supports
return array