PHP Class WC_Product_Variation

The WooCommerce product variation class handles product variation data.
Author: WooThemes
Inheritance: extends WC_Product
Show file Open project: woocommerce/woocommerce Class Usage Examples

Public Properties

Property Type Description
$post_type string Post type.

Protected Properties

Property Type Description
$parent_data array Parent data.

Public Methods

Method Description
add_to_cart_url ( ) : string Get the add to url used mainly in loops.
get_attributes ( string $context = 'view' ) : array Returns array of attribute name value pairs. Keys are prefixed with attribute_, as stored.
get_backorders ( string $context = 'view' ) : string Get backorders.
get_height ( string $context = 'view' ) : string Returns the product height.
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 | string Return if product manage stock.
get_permalink ( $item_object = null ) : string Wrapper for get_permalink. Adds this variations attributes to the URL.
get_sku ( string $context = 'view' ) : string Get SKU (Stock-keeping unit) - product unique ID.
get_stock_managed_by_id ( ) : integer If the stock level comes from another product ID.
get_stock_quantity ( string $context = 'view' ) : integer | null Returns number of items available for sale.
get_tax_class ( string $context = 'view' ) : string Returns the tax class.
get_title ( ) : string Get the product's title. For variations this is the parent product name.
get_type ( ) : string Get internal type.
get_variation_attributes ( ) : array Get variation attribute values. Keys are prefixed with attribute_, as stored.
get_weight ( string $context = 'view' ) : string Returns the product's weight.
get_width ( string $context = 'view' ) : string Returns the product width.
is_purchasable ( ) : boolean Returns false if the product cannot be bought.
set_attributes ( array $raw_attributes ) Set attributes. Unlike the parent product which uses terms, variations are assigned specific attributes using name value pairs.
set_parent_data ( $parent_data ) Set the parent data array for this variation.
variation_is_active ( ) : boolean Controls whether this particular variation will appear greyed-out (inactive) or not (active).
variation_is_visible ( ) : boolean Checks if this particular variation is visible. Invisible variations are enabled and can be selected, but no price / stock info is displayed.

Protected Methods

Method Description
get_hook_prefix ( ) : string Prefix for action and filter hooks on data.

Method Details

add_to_cart_url() public method

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

get_attributes() public method

Returns array of attribute name value pairs. Keys are prefixed with attribute_, as stored.
public get_attributes ( string $context = 'view' ) : array
$context string
return array

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_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_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 | string
$context string
return boolean | string true, false, or parent.

get_sku() public method

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

get_stock_managed_by_id() public method

If the stock level comes from another product ID.
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_tax_class() public method

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

get_title() public method

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

get_type() public method

Get internal type.
public get_type ( ) : string
return string

get_variation_attributes() public method

Get variation attribute values. Keys are prefixed with attribute_, as stored.
public get_variation_attributes ( ) : array
return array of attributes and their values for this variation

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

is_purchasable() public method

Override abstract method so that: i) Disabled variations are not be purchasable by admins. ii) Enabled variations are not purchasable if the parent product is not purchasable.
public is_purchasable ( ) : boolean
return boolean

set_attributes() public method

Set attributes. Unlike the parent product which uses terms, variations are assigned specific attributes using name value pairs.
public set_attributes ( array $raw_attributes )
$raw_attributes array

set_parent_data() public method

Set the parent data array for this variation.
Since: 2.7.0
public set_parent_data ( $parent_data )

variation_is_active() public method

Used by extensions to make incompatible variations appear greyed-out, etc. Other possible uses: prevent out-of-stock variations from being selected.
public variation_is_active ( ) : boolean
return boolean

variation_is_visible() public method

Instead, a suitable 'unavailable' message is displayed. Invisible by default: Disabled variations and variations with an empty price.
public variation_is_visible ( ) : boolean
return boolean

Property Details

$parent_data protected property

Parent data.
protected array $parent_data
return array

$post_type public property

Post type.
public string $post_type
return string