Class WC_Product_Variation

Product Variation Class

The WooCommerce product variation class handles product variation data.

WC_Product
Extended by WC_Product_Variation
Package: WooCommerce\Classes
Category: Class
Author: WooThemes
Version: 2.1.0
Class: WC_Product_Variation
Located at includes/class-wc-product-variation.php

Methods summary

public
# __construct( integer $variation, array $args = array() )

Loads all product data from custom fields

Loads all product data from custom fields

Parameters

$variation
integer
$variation_id ID of the variation to load
$args
array
$args Array of the arguments containing parent product data

Overrides

WC_Product::__construct
public boolean
# exists( )

Returns whether or not the product post exists.

Returns whether or not the product post exists.

Returns

boolean

Overrides

WC_Product::exists
public string
# get_permalink( )

Wrapper for get_permalink. Adds this variations attributes to the URL.

Wrapper for get_permalink. Adds this variations attributes to the URL.

Returns

string

Overrides

WC_Product::get_permalink
public string
# add_to_cart_url( )

Get the add to url used mainly in loops.

Get the add to url used mainly in loops.

Returns

string

Overrides

WC_Product::add_to_cart_url
public string
# add_to_cart_text( )

Get the add to cart button text

Get the add to cart button text

Returns

string

Overrides

WC_Product::add_to_cart_text
public boolean
# variation_is_visible( )

Checks if this particular variation is visible (variations with no price, or out of stock, can be hidden)

Checks if this particular variation is visible (variations with no price, or out of stock, can be hidden)

Returns

boolean
public boolean
# is_purchasable( )

Returns false if the product cannot be bought.

Returns false if the product cannot be bought.

Returns

boolean

Overrides

WC_Product::is_purchasable
public boolean
# parent_is_visible( )

Returns whether or not the variations parent is visible.

Returns whether or not the variations parent is visible.

Returns

boolean
public integer
# get_variation_id( )

Get variation ID

Get variation ID

Returns

integer
public array
# get_variation_attributes( )

Get variation attribute values

Get variation attribute values

Returns

array
of attributes and their values for this variation
public string
# get_price_html( string $price = '' )

Get variation price HTML. Prices are not inherited from parents.

Get variation price HTML. Prices are not inherited from parents.

Parameters

$price
string
$price (default: '')

Returns

string
containing the formatted price

Overrides

WC_Product::get_price_html
public integer
# get_image_id( )

Gets the main product image ID.

Gets the main product image ID.

Returns

integer

Overrides

WC_Product::get_image_id
public string
# get_image( string $size = 'shop_thumbnail', mixed $attr = array() )

Gets the main product image.

Gets the main product image.

Parameters

$size
string
$size (default: 'shop_thumbnail')
$attr

Returns

string

Overrides

WC_Product::get_image
public integer
# set_stock( integer $amount = null, boolean $force_variation_stock = false )

Set stock level of the product variation.

Set stock level of the product variation.

Parameters

$amount
integer
$amount
$force_variation_stock
boolean
$force_variation_stock If true, the variation's stock will be updated and not the parents.

Returns

integer

Overrides

WC_Product::set_stock
public integer
# reduce_stock( integer $by = 1 )

Reduce stock level of the product.

Reduce stock level of the product.

Parameters

$by
integer
$by (default: 1) Amount to reduce by

Returns

integer
stock level

Overrides

WC_Product::reduce_stock
public integer
# increase_stock( integer $by = 1 )

Increase stock level of the product.

Increase stock level of the product.

Parameters

$by
integer
$by (default: 1) Amount to increase by

Returns

integer
stock level

Overrides

WC_Product::increase_stock
public string
# get_shipping_class( )

Get the shipping class, and if not set, get the shipping class of the parent.

Get the shipping class, and if not set, get the shipping class of the parent.

Returns

string

Overrides

WC_Product::get_shipping_class
public integer
# get_shipping_class_id( )

Returns the product shipping class ID.

Returns the product shipping class ID.

Returns

integer

Overrides

WC_Product::get_shipping_class_id
public string
# get_formatted_name( )

Get product name with extra details such as SKU, price and attributes. Used within admin.

Get product name with extra details such as SKU, price and attributes. Used within admin.

Returns

string
Formatted product name, including attributes and price

Overrides

WC_Product::get_formatted_name

Methods inherited from WC_Product

__get(), __isset(), adjust_price(), backorders_allowed(), backorders_require_notification(), enable_dimensions_display(), get_attribute(), get_attributes(), get_availability(), get_average_rating(), get_categories(), get_children(), get_cross_sells(), get_dimensions(), get_file(), get_file_download_path(), get_files(), get_gallery_attachment_ids(), get_parent(), get_post_data(), get_price(), get_price_excluding_tax(), get_price_html_from_text(), get_price_html_from_to(), get_price_including_tax(), get_price_suffix(), get_rating_count(), get_rating_html(), get_regular_price(), get_related(), get_sale_price(), get_sku(), get_stock_quantity(), get_tags(), get_tax_class(), get_tax_status(), get_title(), get_total_stock(), get_upsells(), get_weight(), has_attributes(), has_child(), has_dimensions(), has_enough_stock(), has_file(), has_weight(), is_downloadable(), is_featured(), is_in_stock(), is_on_backorder(), is_on_sale(), is_shipping_taxable(), is_sold_individually(), is_taxable(), is_type(), is_virtual(), is_visible(), list_attributes(), managing_stock(), needs_shipping(), set_price(), set_stock_status(), single_add_to_cart_text()

Magic methods summary

Properties summary

public mixed $variation_id
#

Public

int ID of the variable product.
public mixed $parent
#

Public

object Parent Variable product object.
public array $variation_data
#

Public

array Stores variation data (attributes) for the current variation.
public boolean $variation_has_length
#

Public

bool True if the variation has a length.
public boolean $variation_has_width
#

Public

bool True if the variation has a width.
public boolean $variation_has_height
#

Public

bool True if the variation has a height.
public boolean $variation_has_weight
#

Public

bool True if the variation has a weight.
public boolean $variation_has_stock
#

Public

bool True if the variation has stock and is managing stock.
public boolean $variation_has_sku
#

Public

bool True if the variation has a sku.
public boolean $variation_shipping_class
#

Public

string Stores the shipping class of the variation.
public boolean $variation_shipping_class_id
#

Public

int Stores the shipping class ID of the variation.
public boolean $variation_has_tax_class
#

Public

bool True if the variation has a tax class.
public boolean $variation_has_downloadable_files
#

Public

bool True if the variation has file paths.

Properties inherited from WC_Product

$id, $post, $product_type

WooCommerce API documentation generated by ApiGen 2.8.0