PHP Класс WC_Product_Variable

The WooCommerce product class handles individual product data.
Автор: WooThemes
Наследование: extends WC_Product
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$extra_data array Stores product data.

Открытые методы

Метод Описание
__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.

Описание методов

__construct() публичный Метод

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() публичный Метод

Get the add to cart button text.
public add_to_cart_text ( ) : string
Результат string

child_has_dimensions() публичный Метод

Does a child have dimensions set?
public child_has_dimensions ( ) : boolean
Результат boolean

child_has_weight() публичный Метод

Does a child have a weight set?
public child_has_weight ( ) : boolean
Результат boolean

child_is_in_stock() публичный Метод

Is a child in stock?
public child_is_in_stock ( ) : boolean
Результат boolean

get_available_variation() публичный Метод

Returns an array of data for a variation. Used in the add to cart form.
С версии: 2.4.0
public get_available_variation ( WC_Product $variation ) : array
$variation WC_Product Variation product object or ID
Результат array

get_available_variations() публичный Метод

Get an array of available variations for the current product.
public get_available_variations ( ) : array
Результат array

get_children() публичный Метод

Return a products child ids.
public get_children ( string $context = 'view' ) : array
$context string
Результат array Children ids

get_downloadable() публичный Метод

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

get_price_html() публичный Метод

Returns the price in html format.
public get_price_html ( string $price = '' ) : string
$price string (default: '')
Результат string

get_type() публичный Метод

Get internal type.
public get_type ( ) : string
Результат string

get_variation_attributes() публичный Метод

Return an array of attributes used for variations, as well as their possible values.
public get_variation_attributes ( string $context = 'view' ) : array
$context string
Результат array Attributes and their available values

get_variation_default_attribute() публичный Метод

If set, get the default attributes for a variable product.
public get_variation_default_attribute ( string $attribute_name ) : string
$attribute_name string
Результат string

get_variation_price() публичный Метод

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?
Результат string

get_variation_prices() публичный Метод

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

get_variation_prices_including_taxes() публичный Метод

Get an array of all sale and regular prices from all variations, includes taxes.
С версии: 2.7.0
public get_variation_prices_including_taxes ( string $context = 'view' ) : array()
$context string
Результат array()

get_variation_regular_price() публичный Метод

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?
Результат string

get_variation_sale_price() публичный Метод

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?
Результат string

get_virtual() публичный Метод

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

get_visible_children() публичный Метод

Return a products child ids - visible only.
С версии: 2.7.0
public get_visible_children ( string $context = 'view' ) : array
$context string
Результат array Children ids

has_dimensions() публичный Метод

Returns whether or not the product has dimensions set.
public has_dimensions ( ) : boolean
Результат boolean

has_weight() публичный Метод

Returns whether or not the product has weight set.
public has_weight ( ) : boolean
Результат boolean

is_on_sale() публичный Метод

Returns whether or not the product is on sale.
public is_on_sale ( ) : boolean
Результат boolean

save() публичный Метод

Save data (either create or update depending on if we are working on an existing product).
С версии: 2.7.0
public save ( )

set_children() публичный Метод

Sets an array of children for the product.
С версии: 2.7.0
public set_children ( $children )

set_variation_attributes() публичный Метод

Sets an array of variation attributes
С версии: 2.7.0
public set_variation_attributes ( $variation_attributes )

set_variation_prices() публичный Метод

Sets an array of variation prices.
С версии: 2.7.0
public set_variation_prices ( $variation_prices )

set_variation_prices_including_taxes() публичный Метод

Sets an array of variation prices, including taxes.
С версии: 2.7.0
public set_variation_prices_including_taxes ( $variation_prices_including_taxes )

set_visible_children() публичный Метод

Sets an array of visible children only.
С версии: 2.7.0
public set_visible_children ( $visible_children )

sync() публичный статический Метод

Sync a variable product with it's children. These sync functions sync upwards (from child to parent) when the variation is saved.
public static sync ( WC_Product | 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.
Результат WC_Product Synced product object.

sync_stock_status() публичный статический Метод

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.
Результат WC_Product Synced product object.

validate_props() публичный Метод

Ensure properties are set correctly before save.
С версии: 2.7.0
public validate_props ( )

Описание свойств

$extra_data защищенное свойство

Stores product data.
protected array $extra_data
Результат array