PHP Class WC_Product_Variable

The WooCommerce product class handles individual product data.
Author: WooThemes
Inheritance: extends WC_Product
显示文件 Open project: woocommerce/woocommerce Class Usage Examples

Protected Properties

Property Type Description
$extra_data array Stores product data.

Public Methods

Method Description
__construct ( integer | WC_Product | object $product ) Merges variable product data into the parent object.
add_to_cart_text ( ) : string Get the add to cart button text.
child_has_dimensions ( ) : boolean Does a child have dimensions set?
child_has_weight ( ) : boolean Does a child have a weight set?
child_is_in_stock ( ) : boolean Is a child in stock?
get_available_variation ( WC_Product $variation ) : array Returns an array of data for a variation. Used in the add to cart form.
get_available_variations ( ) : array Get an array of available variations for the current product.
get_children ( string $context = 'view' ) : array Return a products child ids.
get_downloadable ( $context = 'view' ) Variable products themselves cannot be downloadable.
get_price_html ( string $price = '' ) : string Returns the price in html format.
get_type ( ) : string Get internal type.
get_variation_attributes ( string $context = 'view' ) : array Return an array of attributes used for variations, as well as their possible values.
get_variation_default_attribute ( string $attribute_name ) : string If set, get the default attributes for a variable product.
get_variation_price ( string $min_or_max = 'min', boolean $include_taxes = false ) : string Get the min or max variation (active) price.
get_variation_prices ( string $context = 'view' ) : array() Get an array of all sale and regular prices from all variations. This is used for example when displaying the price range at variable product level or seeing if the variable product is on sale.
get_variation_prices_including_taxes ( string $context = 'view' ) : array() Get an array of all sale and regular prices from all variations, includes taxes.
get_variation_regular_price ( string $min_or_max = 'min', boolean $include_taxes = false ) : string Get the min or max variation regular price.
get_variation_sale_price ( string $min_or_max = 'min', boolean $include_taxes = false ) : string Get the min or max variation sale price.
get_virtual ( $context = 'view' ) Variable products themselves cannot be virtual.
get_visible_children ( string $context = 'view' ) : array Return a products child ids - visible only.
has_dimensions ( ) : boolean Returns whether or not the product has dimensions set.
has_weight ( ) : boolean Returns whether or not the product has weight set.
is_on_sale ( ) : boolean Returns whether or not the product is on sale.
save ( ) Save data (either create or update depending on if we are working on an existing product).
set_children ( $children ) Sets an array of children for the product.
set_variation_attributes ( $variation_attributes ) Sets an array of variation attributes
set_variation_prices ( $variation_prices ) Sets an array of variation prices.
set_variation_prices_including_taxes ( $variation_prices_including_taxes ) Sets an array of variation prices, including taxes.
set_visible_children ( $visible_children ) Sets an array of visible children only.
sync ( WC_Product | integer $product, boolean $save = true ) : WC_Product Sync a variable product with it's children. These sync functions sync upwards (from child to parent) when the variation is saved.
sync_stock_status ( WC_Product | integer $product, boolean $save = true ) : WC_Product Sync parent stock status with the status of all children and save.
validate_props ( ) Ensure properties are set correctly before save.

Method Details

__construct() public method

Merges variable product data into the parent object.
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

child_has_dimensions() public method

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

child_has_weight() public method

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

child_is_in_stock() public method

Is a child in stock?
public child_is_in_stock ( ) : boolean
return boolean

get_available_variation() public method

Returns an array of data for a variation. Used in the add to cart form.
Since: 2.4.0
public get_available_variation ( WC_Product $variation ) : array
$variation WC_Product Variation product object or ID
return array

get_available_variations() public method

Get an array of available variations for the current product.
public get_available_variations ( ) : array
return array

get_children() public method

Return a products child ids.
public get_children ( string $context = 'view' ) : array
$context string
return array Children ids

get_downloadable() public method

Variable products themselves cannot be downloadable.
public get_downloadable ( $context = 'view' )

get_price_html() public method

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

get_type() public method

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

get_variation_attributes() public method

Return an array of attributes used for variations, as well as their possible values.
public get_variation_attributes ( string $context = 'view' ) : array
$context string
return array Attributes and their available values

get_variation_default_attribute() public method

If set, get the default attributes for a variable product.
public get_variation_default_attribute ( string $attribute_name ) : string
$attribute_name string
return string

get_variation_price() public method

Get the min or max variation (active) price.
public get_variation_price ( string $min_or_max = 'min', boolean $include_taxes = false ) : string
$min_or_max string Min or max price.
$include_taxes boolean Should the price include taxes?
return string

get_variation_prices() public method

Get an array of all sale and regular prices from all variations. This is used for example when displaying the price range at variable product level or seeing if the variable product is on sale.
public get_variation_prices ( string $context = 'view' ) : array()
$context string
return array()

get_variation_prices_including_taxes() public method

Get an array of all sale and regular prices from all variations, includes taxes.
Since: 2.7.0
public get_variation_prices_including_taxes ( string $context = 'view' ) : array()
$context string
return array()

get_variation_regular_price() public method

Get the min or max variation regular price.
public get_variation_regular_price ( string $min_or_max = 'min', boolean $include_taxes = false ) : string
$min_or_max string Min or max price.
$include_taxes boolean Should the price include taxes?
return string

get_variation_sale_price() public method

Get the min or max variation sale price.
public get_variation_sale_price ( string $min_or_max = 'min', boolean $include_taxes = false ) : string
$min_or_max string Min or max price.
$include_taxes boolean Should the price include taxes?
return string

get_virtual() public method

Variable products themselves cannot be virtual.
public get_virtual ( $context = 'view' )

get_visible_children() public method

Return a products child ids - visible only.
Since: 2.7.0
public get_visible_children ( string $context = 'view' ) : array
$context string
return array Children ids

has_dimensions() public method

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

has_weight() public method

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

is_on_sale() public method

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

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_children() public method

Sets an array of children for the product.
Since: 2.7.0
public set_children ( $children )

set_variation_attributes() public method

Sets an array of variation attributes
Since: 2.7.0
public set_variation_attributes ( $variation_attributes )

set_variation_prices() public method

Sets an array of variation prices.
Since: 2.7.0
public set_variation_prices ( $variation_prices )

set_variation_prices_including_taxes() public method

Sets an array of variation prices, including taxes.
Since: 2.7.0
public set_variation_prices_including_taxes ( $variation_prices_including_taxes )

set_visible_children() public method

Sets an array of visible children only.
Since: 2.7.0
public set_visible_children ( $visible_children )

sync() public static method

Sync a variable product with it's children. These sync functions sync upwards (from child to parent) when the variation is saved.
public static sync ( WC_Product | integer $product, boolean $save = true ) : WC_Product
$product WC_Product | integer Product object or ID for which you wish to sync.
$save boolean If true, the prouduct object will be saved to the DB before returning it.
return WC_Product Synced product object.

sync_stock_status() public static method

Sync parent stock status with the status of all children and save.
public static sync_stock_status ( WC_Product | integer $product, boolean $save = true ) : WC_Product
$product WC_Product | integer Product object or ID for which you wish to sync.
$save boolean If true, the prouduct object will be saved to the DB before returning it.
return WC_Product Synced product object.

validate_props() public method

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

Property Details

$extra_data protected_oe property

Stores product data.
protected array $extra_data
return array