PHP Class WC_Abstract_Legacy_Product

Legacy and deprecated functions are here to keep the WC_Abstract_Product clean. This class will be removed in future versions.
Author: WooThemes
Inheritance: extends WC_Data
Show file Open project: woocommerce/woocommerce Class Usage Examples

Public Properties

Property Type Description
$product_type string The product's type (simple, variable etc).

Public Methods

Method Description
__get ( string $key ) : mixed Magic __get method for backwards compatibility. Maps legacy vars to new getters.
__isset ( string $key ) : boolean Magic __isset method for backwards compatibility. Legacy properties which could be accessed directly in the past.
adjust_price ( mixed $price ) Adjust a products price dynamically.
check_stock_status ( ) Check if the stock status needs changing.
enable_dimensions_display ( ) : boolean Returns whether or not we are showing dimensions on the product page.
get_availability ( ) : string Returns the availability of the product.
get_categories ( string $sep = ', ', string $before = '', string $after = '' ) : string Returns the product categories.
get_child ( mixed $child_id ) : WC_Product | WC_Product_variation Returns the child product.
get_cross_sells ( ) : array Returns the cross sell product ids.
get_display_price ( string $price = '', integer $qty = 1 ) : string Returns the price including or excluding tax, based on the 'woocommerce_tax_display_shop' setting.
get_files ( ) : array Same as get_downloads in CRUD.
get_formatted_variation_attributes ( $flat = false ) : string Get formatted variation data with WC < 2.4 back compat and proper formatting of text-based attribute names.
get_gallery_attachment_ids ( ) : array Returns the gallery attachment ids.
get_matching_variation ( $match_attributes = [] ) Match a variation to a given set of attributes using a WP_Query.
get_parent ( ) : integer Get the parent of the post.
get_post_data ( ) : WP_Post Get the product's post data.
get_price_excluding_tax ( integer $qty = 1, string $price = '' ) : string Returns the price (excluding tax) - ignores tax_class filters since the price may *include* tax and thus needs subtracting.
get_price_html_from_text ( ) : string Functions for getting parts of a price, in html, used by get_price_html.
get_price_html_from_to ( string $from, mixed $to ) : string Functions for getting parts of a price, in html, used by get_price_html.
get_price_including_tax ( integer $qty = 1, string $price = '' ) : string Returns the price (including tax). Uses customer tax rates. Can work for a specific $qty for more accurate taxes.
get_price_suffix ( string $price = '', integer $qty = 1 ) : string Get the suffix to display after prices > 0.
get_rating_html ( string $rating = null ) : string Returns the product rating in html format.
get_related ( $limit = 5 ) Get and return related products.
get_tags ( string $sep = ', ', string $before = '', string $after = '' ) : array Returns the product tags.
get_total_stock ( ) : integer Get total stock - This is the stock of parent and children combined.
get_upsells ( ) : array Returns the upsell product ids.
get_variation_default_attributes ( ) : array If set, get the default attributes for a variable product.
get_variation_description ( ) : string Get product variation description.
get_variation_id ( ) : integer Get variation ID.
grouped_product_sync ( )
has_all_attributes_set ( ) : boolean Check if all variation's attributes are set.
has_default_attributes ( ) : boolean Check if variable product has default attributes set.
increase_stock ( integer $amount = 1 ) : integer Increase stock level of the product.
list_attributes ( ) Lists a table of attributes for the product page.
parent_is_visible ( ) : boolean Returns whether or not the variations parent is visible.
reduce_stock ( integer $amount = 1 ) : integer Reduce stock level of the product.
set_stock ( $amount = null, $mode = 'set' ) Set stock level of the product.
sync_attributes ( $product, $children = false ) Sync the variable product's attributes with the variations.
sync_average_rating ( integer $post_id ) Sync product rating. Can be called statically.
sync_rating_count ( integer $post_id ) Sync product rating count. Can be called statically.
variable_product_sync ( $product_id = '' ) Sync variable product prices with the children lowest/highest prices.

Protected Methods

Method Description
build_related_query ( $cats_array, $tags_array, $exclude_ids, $limit ) Builds the related posts query.
get_availability_class ( ) : string Get availability classname based on stock status.
get_availability_text ( ) : string Get availability text based on stock status.
get_related_terms ( $term ) Retrieves related product terms.

Method Details

__get() public method

Magic __get method for backwards compatibility. Maps legacy vars to new getters.
public __get ( string $key ) : mixed
$key string Key name.
return mixed

__isset() public method

Magic __isset method for backwards compatibility. Legacy properties which could be accessed directly in the past.
public __isset ( string $key ) : boolean
$key string Key name.
return boolean

adjust_price() public method

Adjust a products price dynamically.
Deprecation: 2.7.0
public adjust_price ( mixed $price )
$price mixed

check_stock_status() public method

Check if the stock status needs changing.
Deprecation: 2.7.0 Sync is done automatically on read/save, so calling this should not be needed any more.
public check_stock_status ( )

enable_dimensions_display() public method

Returns whether or not we are showing dimensions on the product page.
Deprecation: 2.7.0 Unused.

get_availability() public method

Returns the availability of the product.
Deprecation: 2.7.0
public get_availability ( ) : string
return string

get_availability_class() protected method

Get availability classname based on stock status.
Deprecation: 2.7.0
protected get_availability_class ( ) : string
return string

get_availability_text() protected method

Get availability text based on stock status.
Deprecation: 2.7.0
protected get_availability_text ( ) : string
return string

get_categories() public method

Returns the product categories.
Deprecation: 2.7.0
public get_categories ( string $sep = ', ', string $before = '', string $after = '' ) : string
$sep string (default: ', ').
$before string (default: '').
$after string (default: '').
return string

get_child() public method

Returns the child product.
Deprecation: 2.7.0 Use wc_get_product instead.
public get_child ( mixed $child_id ) : WC_Product | WC_Product_variation
$child_id mixed
return WC_Product | WC_Product_variation

get_cross_sells() public method

Returns the cross sell product ids.
Deprecation: 2.7.0
public get_cross_sells ( ) : array
return array

get_display_price() public method

Returns the price including or excluding tax, based on the 'woocommerce_tax_display_shop' setting.
Deprecation: 2.7.0 Use wc_get_price_to_display instead.
public get_display_price ( string $price = '', integer $qty = 1 ) : string
$price string to calculate, left blank to just use get_price()
$qty integer passed on to get_price_including_tax() or get_price_excluding_tax()
return string

get_files() public method

Same as get_downloads in CRUD.
Deprecation: 2.7.0
public get_files ( ) : array
return array

get_formatted_variation_attributes() public method

Get formatted variation data with WC < 2.4 back compat and proper formatting of text-based attribute names.
Deprecation: 2.7.0
public get_formatted_variation_attributes ( $flat = false ) : string
return string

get_matching_variation() public method

Match a variation to a given set of attributes using a WP_Query.
Deprecation: 2.7.0 in favour of Product data store's find_matching_product_variation.
public get_matching_variation ( $match_attributes = [] )

get_parent() public method

Get the parent of the post.
Deprecation: 2.7.0
public get_parent ( ) : integer
return integer

get_post_data() public method

Get the product's post data.
Deprecation: 2.7.0
public get_post_data ( ) : WP_Post
return WP_Post

get_price_excluding_tax() public method

Uses store base tax rates. Can work for a specific $qty for more accurate taxes.
Deprecation: 2.7.0 Use wc_get_price_excluding_tax instead.
public get_price_excluding_tax ( integer $qty = 1, string $price = '' ) : string
$qty integer
$price string to calculate, left blank to just use get_price()
return string

get_price_html_from_text() public method

Functions for getting parts of a price, in html, used by get_price_html.
Deprecation: 2.7.0
public get_price_html_from_text ( ) : string
return string

get_price_html_from_to() public method

Functions for getting parts of a price, in html, used by get_price_html.
Deprecation: 2.7.0 Use wc_format_sale_price instead.
public get_price_html_from_to ( string $from, mixed $to ) : string
$from string String or float to wrap with 'from' text
$to mixed String or float to wrap with 'to' text
return string

get_price_including_tax() public method

Returns the price (including tax). Uses customer tax rates. Can work for a specific $qty for more accurate taxes.
Deprecation: 2.7.0 Use wc_get_price_including_tax instead.
public get_price_including_tax ( integer $qty = 1, string $price = '' ) : string
$qty integer
$price string to calculate, left blank to just use get_price()
return string

get_price_suffix() public method

Get the suffix to display after prices > 0.
Deprecation: 2.7.0 Use wc_get_price_suffix instead.
public get_price_suffix ( string $price = '', integer $qty = 1 ) : string
$price string to calculate, left blank to just use get_price()
$qty integer passed on to get_price_including_tax() or get_price_excluding_tax()
return string

get_rating_html() public method

Returns the product rating in html format.
Deprecation: 2.7.0
public get_rating_html ( string $rating = null ) : string
$rating string (default: '')
return string

get_tags() public method

Returns the product tags.
Deprecation: 2.7.0
public get_tags ( string $sep = ', ', string $before = '', string $after = '' ) : array
$sep string (default: ', ').
$before string (default: '').
$after string (default: '').
return array

get_total_stock() public method

Get total stock - This is the stock of parent and children combined.
Deprecation: 2.7.0
public get_total_stock ( ) : integer
return integer

get_upsells() public method

Returns the upsell product ids.
Deprecation: 2.7.0
public get_upsells ( ) : array
return array

get_variation_default_attributes() public method

If set, get the default attributes for a variable product.
Deprecation: 2.7.0

get_variation_description() public method

Get product variation description.
Deprecation: 2.7.0

get_variation_id() public method

Get variation ID.
Deprecation: 2.7.0
public get_variation_id ( ) : integer
return integer

grouped_product_sync() public method

has_all_attributes_set() public method

Check if all variation's attributes are set.
Deprecation: 2.7.0
public has_all_attributes_set ( ) : boolean
return boolean

has_default_attributes() public method

Check if variable product has default attributes set.
Deprecation: 2.7.0
public has_default_attributes ( ) : boolean
return boolean

increase_stock() public method

Increase stock level of the product.
Deprecation: 2.7.0
public increase_stock ( integer $amount = 1 ) : integer
$amount integer Amount to increase by. Default 1.
return integer new stock level

list_attributes() public method

Lists a table of attributes for the product page.
Deprecation: 2.7.0 Use wc_display_product_attributes instead.
public list_attributes ( )

parent_is_visible() public method

Returns whether or not the variations parent is visible.
Deprecation: 2.7.0
public parent_is_visible ( ) : boolean
return boolean

reduce_stock() public method

Reduce stock level of the product.
Deprecation: 2.7.0
public reduce_stock ( integer $amount = 1 ) : integer
$amount integer Amount to reduce by. Default: 1
return integer new stock level

set_stock() public method

Set stock level of the product.
Deprecation: 2.7.0
public set_stock ( $amount = null, $mode = 'set' )

sync_attributes() public static method

Sync the variable product's attributes with the variations.
public static sync_attributes ( $product, $children = false )

sync_average_rating() public static method

Sync product rating. Can be called statically.
Deprecation: 2.7.0
public static sync_average_rating ( integer $post_id )
$post_id integer

sync_rating_count() public static method

Sync product rating count. Can be called statically.
Deprecation: 2.7.0
public static sync_rating_count ( integer $post_id )
$post_id integer

variable_product_sync() public method

Sync variable product prices with the children lowest/highest prices.
Deprecation: 2.7.0 not used in core.
public variable_product_sync ( $product_id = '' )

Property Details

$product_type public property

The product's type (simple, variable etc).
Deprecation: 2.7.0 get_type() method should return string instead since this prop should not be changed or be public.
public string $product_type
return string