WC_Product_Variation
extends WC_Product_Simple
in package
Product variation class.
Table of Contents
- $cache_group : string
- Stores meta in cache for future reads.
- $changes : array<string|int, mixed>
- Core data changes for this object.
- $data : array<string|int, mixed>
- Core data for this object. Name value pairs (name + default value).
- $data_store : object
- Contains a reference to the data store for this class.
- $default_data : array<string|int, mixed>
- Set to _data on construct so we can track and reset data if needed.
- $extra_data : array<string|int, mixed>
- Extra data for this object. Name value pairs (name + default value).
- $id : int
- ID for this object.
- $legacy_datastore_props : array<string|int, mixed>
- List of properties that were earlier managed by data store. However, since DataStore is a not a stored entity in itself, they used to store data in metadata of the data object.
- $meta_data : array<string|int, mixed>
- Stores additional meta data.
- $object_read : bool
- This is false until the object is read from the DB.
- $object_type : string
- This is the name of this object type.
- $parent_data : array<string|int, mixed>
- Parent data.
- $post_type : string
- Post type.
- $supports : array<string|int, mixed>
- Supported features such as 'ajax_add_to_cart'.
- __clone() : mixed
- When the object is cloned, make sure meta is duplicated correctly.
- __construct() : mixed
- Override the default constructor to set custom defaults.
- __get() : mixed
- Magic __get method for backwards compatibility. Maps legacy vars to new getters.
- __isset() : bool
- Magic __isset method for backwards compatibility. Legacy properties which could be accessed directly in the past.
- __sleep() : array<string|int, mixed>
- Only store the object ID to avoid serializing the data object instance.
- __toString() : string
- Change data to JSON format.
- __wakeup() : mixed
- Re-run the constructor with the object ID.
- add_meta_data() : mixed
- Add meta data.
- add_to_cart_aria_describedby() : string
- Get the aria-describedby description for the add to cart button.
- add_to_cart_description() : string
- Get the add to cart button text description - used in aria tags.
- add_to_cart_text() : string
- Get the add to cart button text.
- add_to_cart_url() : string
- Get the add to url used mainly in loops.
- adjust_price() : mixed
- Adjust a products price dynamically.
- apply_changes() : mixed
- Merge changes with data and clear.
- backorders_allowed() : bool
- Returns whether or not the product can be backordered.
- backorders_require_notification() : bool
- Returns whether or not the product needs to notify the customer on backorder.
- check_stock_status() : mixed
- Check if the stock status needs changing.
- child_has_dimensions() : bool
- Does a child have dimensions?
- child_has_weight() : bool
- Does a child have a weight?
- delete() : bool
- Delete an object, set the ID to 0, and return result.
- delete_meta_data() : mixed
- Delete meta data.
- delete_meta_data_by_mid() : mixed
- Delete meta data.
- delete_meta_data_value() : mixed
- Delete meta data with a matching value.
- enable_dimensions_display() : bool
- Returns whether or not we are showing dimensions on the product page.
- exists() : bool
- Returns whether or not the product post exists.
- generate_meta_cache_key() : string
- Generate cache key from id and group.
- get_attribute() : string
- Returns a single product attribute as a string.
- get_attribute_summary() : string
- Get attribute summary.
- get_attributes() : array<string|int, mixed>
- Returns product attributes.
- get_availability() : array<string|int, string>
- Returns the availability of the product.
- get_average_rating() : float
- Get average rating.
- get_backorders() : string
- Get backorders.
- get_catalog_visibility() : string
- Get catalog visibility.
- get_categories() : string
- Returns the product categories.
- get_category_ids() : array<string|int, mixed>
- Get category ids.
- get_changes() : array<string|int, mixed>
- Return data changes only.
- get_child() : WC_Product|WC_Product_variation
- Returns the child product.
- get_children() : array<string|int, mixed>
- Returns the children IDs if applicable. Overridden by child classes.
- get_cross_sell_ids() : array<string|int, mixed>
- Get cross sell IDs.
- get_cross_sells() : array<string|int, mixed>
- Returns the cross sell product ids.
- get_data() : array<string|int, mixed>
- Returns all data for this object.
- get_data_keys() : array<string|int, mixed>
- Returns array of expected data keys for this object.
- get_data_store() : object
- Get the data store.
- get_date_created() : WC_DateTime|null
- Get product created date.
- get_date_modified() : WC_DateTime|null
- Get product modified date.
- get_date_on_sale_from() : WC_DateTime|null
- Get date on sale from.
- get_date_on_sale_to() : WC_DateTime|null
- Get date on sale to.
- get_default_attributes() : array<string|int, mixed>
- Get default attributes.
- get_description() : string
- Get product description.
- get_dimensions() : string|array<string|int, mixed>
- Returns formatted dimensions.
- get_display_price() : string
- Returns the price including or excluding tax, based on the 'woocommerce_tax_display_shop' setting.
- get_download_expiry() : int
- Get download expiry.
- get_download_limit() : int
- Get download limit.
- get_downloadable() : bool
- Get downloadable.
- get_downloads() : array<string|int, mixed>
- Get downloads.
- get_extra_data_keys() : array<string|int, mixed>
- Returns all "extra" data keys for an object (for sub objects like product types).
- get_featured() : bool
- If the product is featured.
- get_file() : array<string|int, mixed>|false
- Get a file by $download_id.
- get_file_download_path() : string
- Get file download path identified by $download_id.
- get_files() : array<string|int, mixed>
- Same as get_downloads in CRUD.
- get_formatted_name() : string
- Get product name with SKU or ID. Used within admin.
- get_formatted_variation_attributes() : string
- Get formatted variation data with WC < 2.4 back compat and proper formatting of text-based attribute names.
- get_gallery_attachment_ids() : array<string|int, mixed>
- Returns the gallery attachment ids.
- get_gallery_image_ids() : array<string|int, mixed>
- Returns the gallery attachment ids.
- get_height() : string
- Returns the product height.
- get_id() : int
- Returns the unique ID for this object.
- get_image() : string
- Returns the main product image.
- get_image_id() : string
- Get main image ID.
- get_length() : string
- Returns the product length.
- get_low_stock_amount() : int|string
- Get low stock amount.
- get_manage_stock() : bool|string
- Return if product manage stock.
- get_matching_variation() : mixed
- Match a variation to a given set of attributes using a WP_Query.
- get_max_purchase_quantity() : int
- Get max quantity which can be purchased at once.
- get_menu_order() : int
- Get menu order.
- get_meta() : mixed
- Get Meta Data by Key.
- get_meta_cache_key() : string
- Helper method to compute meta cache key. Different from WP Meta cache key in that meta data cached using this key also contains meta_id column.
- get_meta_data() : array<string|int, mixed>
- Get All Meta Data.
- get_min_purchase_quantity() : int
- Get min quantity which can be purchased at once.
- get_name() : string
- Get product name.
- get_object_read() : bool
- Get object read property.
- get_parent() : int
- Get the parent of the post.
- get_parent_data() : array<string|int, mixed>
- Get the parent data array for this variation.
- get_parent_id() : int
- Get parent ID.
- get_permalink() : string
- Wrapper for get_permalink. Adds this variations attributes to the URL.
- get_post_data() : WP_Post
- Get the product's post data.
- get_post_password() : int
- Get post password.
- get_price() : string
- Returns the product's active price.
- get_price_excluding_tax() : string
- Returns the price (excluding tax) - ignores tax_class filters since the price may *include* tax and thus needs subtracting.
- get_price_html() : string
- Returns the price in html format.
- 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
- Functions for getting parts of a price, in html, used by get_price_html.
- get_price_including_tax() : string
- Returns the price (including tax). Uses customer tax rates. Can work for a specific $qty for more accurate taxes.
- get_price_suffix() : string
- Get the suffix to display after prices > 0.
- get_purchase_note() : string
- Get purchase note.
- get_rating_count() : int
- Get the total amount (COUNT) of ratings, or just the count for one rating e.g. number of 5 star ratings.
- get_rating_counts() : array<string|int, mixed>
- Get rating count.
- get_rating_html() : string
- Returns the product rating in html format.
- get_regular_price() : string
- Returns the product's regular price.
- get_related() : array<string|int, mixed>
- Get and return related products.
- get_review_count() : int
- Get review count.
- get_reviews_allowed() : bool
- Return if reviews is allowed.
- get_sale_price() : string
- Returns the product's sale price.
- get_shipping_class() : string
- Returns the product shipping class SLUG.
- get_shipping_class_id() : int
- Get shipping class ID.
- get_short_description() : string
- Get product short description.
- get_sku() : string
- Get SKU (Stock-keeping unit) - product unique ID.
- get_slug() : string
- Get product slug.
- get_sold_individually() : bool
- Return if should be sold individually.
- get_status() : string
- Get product status.
- get_stock_managed_by_id() : int
- If the stock level comes from another product ID.
- get_stock_quantity() : int|null
- Returns number of items available for sale.
- get_stock_status() : string
- Return the stock status.
- get_tag_ids() : array<string|int, mixed>
- Get tag ids.
- get_tags() : array<string|int, mixed>
- Returns the product tags.
- get_tax_class() : string
- Returns the tax class.
- get_tax_status() : string
- Returns the tax status.
- get_title() : string
- Get the product's title. For variations this is the parent product name.
- get_total_sales() : int
- Get number total of sales.
- get_total_stock() : int
- Get total stock - This is the stock of parent and children combined.
- get_type() : string
- Get internal type.
- get_upsell_ids() : array<string|int, mixed>
- Get upsell IDs.
- get_upsells() : array<string|int, mixed>
- Returns the upsell product ids.
- get_variation_attributes() : array<string|int, mixed>
- Get variation attribute values. Keys are prefixed with attribute_, as stored, unless $with_prefix is false.
- get_variation_default_attributes() : array<string|int, mixed>
- If set, get the default attributes for a variable product.
- get_variation_description() : string
- Get product variation description.
- get_variation_id() : int
- Get variation ID.
- get_virtual() : bool
- Get virtual.
- get_weight() : string
- Returns the product's weight.
- get_width() : string
- Returns the product width.
- grouped_product_sync() : mixed
- has_all_attributes_set() : bool
- Check if all variation's attributes are set.
- has_attributes() : bool
- Returns whether or not the product has any visible attributes.
- has_child() : bool
- Returns whether or not the product has any child product.
- has_default_attributes() : bool
- Check if variable product has default attributes set.
- has_dimensions() : bool
- Returns whether or not the product has dimensions set.
- has_enough_stock() : bool
- Returns whether or not the product has enough stock for the order.
- has_file() : bool
- Check if downloadable product has a file attached.
- has_options() : bool
- Returns whether or not the product has additional options that need selecting before adding to cart.
- has_weight() : bool
- Returns whether or not the product has weight set.
- increase_stock() : int
- Increase stock level of the product.
- init_meta_data() : mixed
- Helper function to initialize metadata entries from filtered raw meta data.
- is_downloadable() : bool
- Checks if a product is downloadable.
- is_featured() : bool
- Returns whether or not the product is featured.
- is_in_stock() : bool
- Returns whether or not the product can be purchased.
- is_on_backorder() : bool
- Check if a product is on backorder.
- is_on_sale() : bool
- Returns whether or not the product is on sale.
- is_purchasable() : bool
- Returns false if the product cannot be bought.
- is_shipping_taxable() : bool
- Returns whether or not the product shipping is taxable.
- is_sold_individually() : bool
- Check if a product is sold individually (no quantities).
- is_taxable() : bool
- Returns whether or not the product is taxable.
- is_type() : bool
- Checks the product type.
- is_virtual() : bool
- Checks if a product is virtual (has no shipping).
- is_visible() : bool
- Returns whether or not the product is visible in the catalog.
- list_attributes() : mixed
- Lists a table of attributes for the product page.
- managing_stock() : bool
- Returns whether or not the product is stock managed.
- meta_exists() : bool
- See if meta data exists, since get_meta always returns a '' or array().
- needs_shipping() : bool
- Checks if a product needs shipping.
- parent_is_visible() : bool
- Returns whether or not the variations parent is visible.
- prime_raw_meta_data_cache() : mixed
- Prime caches for raw meta data. This includes meta_id column as well, which is not included by default in WP meta data.
- read_meta_data() : mixed
- Read Meta Data from the database. Ignore any internal properties.
- reduce_stock() : int
- Reduce stock level of the product.
- save() : int
- Save should create or update based on object existence.
- save_meta_data() : mixed
- Update Meta Data in the database.
- set_attribute_summary() : mixed
- Set attribute summary.
- set_attributes() : mixed
- Set attributes. Unlike the parent product which uses terms, variations are assigned specific attributes using name value pairs.
- set_average_rating() : mixed
- Set average rating. Read only.
- set_backorders() : mixed
- Set backorders.
- set_catalog_visibility() : mixed
- Set catalog visibility.
- set_category_ids() : mixed
- Set the product categories.
- set_cross_sell_ids() : mixed
- Set crosssell IDs.
- set_date_created() : mixed
- Set product created date.
- set_date_modified() : mixed
- Set product modified date.
- set_date_on_sale_from() : mixed
- Set date on sale from.
- set_date_on_sale_to() : mixed
- Set date on sale to.
- set_default_attributes() : mixed
- Set default attributes. These will be saved as strings and should map to attribute values.
- set_defaults() : mixed
- Set all props to default values.
- set_description() : mixed
- Set product description.
- set_download_expiry() : mixed
- Set download expiry.
- set_download_limit() : mixed
- Set download limit.
- set_downloadable() : mixed
- Set if the product is downloadable.
- set_downloads() : mixed
- Set downloads.
- set_featured() : mixed
- Set if the product is featured.
- set_gallery_image_ids() : mixed
- Set gallery attachment ids.
- set_height() : mixed
- Set the product height.
- set_id() : mixed
- Set ID.
- set_image_id() : mixed
- Set main image ID.
- set_length() : mixed
- Set the product length.
- set_low_stock_amount() : mixed
- Set low stock amount.
- set_manage_stock() : mixed
- Set if product manage stock.
- set_menu_order() : mixed
- Set menu order.
- set_meta_data() : mixed
- Set all meta data from array.
- set_name() : mixed
- Set product name.
- set_object_read() : mixed
- Set object read property.
- set_parent_data() : mixed
- Set the parent data array for this variation.
- set_parent_id() : mixed
- Set parent ID.
- set_post_password() : mixed
- Set post password.
- set_price() : mixed
- Set the product's active price.
- set_props() : bool|WP_Error
- Set a collection of props in one go, collect any errors, and return the result.
- set_purchase_note() : mixed
- Set purchase note.
- set_rating_counts() : mixed
- Set rating counts. Read only.
- set_regular_price() : mixed
- Set the product's regular price.
- set_review_count() : mixed
- Set review count. Read only.
- set_reviews_allowed() : mixed
- Set if reviews is allowed.
- set_sale_price() : mixed
- Set the product's sale price.
- set_shipping_class_id() : mixed
- Set shipping class ID.
- set_short_description() : mixed
- Set product short description.
- set_sku() : mixed
- Set SKU.
- set_slug() : mixed
- Set product slug.
- set_sold_individually() : mixed
- Set if should be sold individually.
- set_status() : mixed
- Set product status.
- set_stock() : int
- Set stock level of the product.
- set_stock_quantity() : mixed
- Set number of items available for sale.
- set_stock_status() : mixed
- Set stock status.
- set_tag_ids() : mixed
- Set the product tags.
- set_tax_class() : mixed
- Set the tax class.
- set_tax_status() : mixed
- Set the tax status.
- set_total_sales() : mixed
- Set number total of sales.
- set_upsell_ids() : mixed
- Set upsell IDs.
- set_virtual() : mixed
- Set if the product is virtual.
- set_weight() : mixed
- Set the product's weight.
- set_width() : mixed
- Set the product width.
- single_add_to_cart_text() : string
- Get the add to cart button text for the single page.
- supports() : bool
- Check if a product supports a given feature.
- sync_attributes() : mixed
- Sync the variable product's attributes with the variations.
- sync_average_rating() : mixed
- Sync product rating. Can be called statically.
- sync_rating_count() : mixed
- Sync product rating count. Can be called statically.
- update_meta_data() : mixed
- Update meta data by key or ID, if provided.
- validate_props() : mixed
- Ensure properties are set correctly before save.
- variable_product_sync() : mixed
- Sync variable product prices with the children lowest/highest prices.
- variation_is_active() : bool
- Controls whether this particular variation will appear greyed-out (inactive) or not (active).
- variation_is_visible() : bool
- Checks if this particular variation is visible. Invisible variations are enabled and can be selected, but no price / stock info is displayed.
- after_data_store_save_or_update() : mixed
- Do any extra processing needed after the actual product save (but before triggering the 'woocommerce_after_..._object_save' action)
- before_data_store_save_or_update() : mixed
- Do any extra processing needed before the actual product save (but after triggering the 'woocommerce_before_..._object_save' action)
- build_related_query() : mixed
- Builds the related posts query.
- error() : mixed
- When invalid data is found, throw an exception unless reading from the DB.
- filter_null_meta() : bool
- Filter null meta values from array.
- get_availability_class() : string
- Get availability classname based on stock status.
- get_availability_text() : string
- Get availability text based on stock status.
- get_hook_prefix() : string
- Prefix for action and filter hooks on data.
- get_prop() : mixed
- Gets a prop for a getter method.
- get_related_terms() : array<string|int, mixed>
- Retrieves related product terms.
- get_valid_tax_classes() : array<string|int, mixed>
- Return valid tax classes. Adds 'parent' to the default list of valid tax classes.
- is_internal_meta_key() : bool
- Check if the key is an internal one.
- is_visible_core() : bool
- Returns whether or not the product is visible in the catalog (doesn't trigger filters).
- maybe_defer_product_sync() : mixed
- If this is a child product, queue its parent for syncing at the end of the request.
- maybe_read_meta_data() : mixed
- Read meta data if null.
- set_date_prop() : mixed
- Sets a date prop whilst handling formatting and datetime objects.
- set_prop() : mixed
- Sets a prop for a setter method.
- build_downloads_map() : array<string|int, WC_Product_Download>
- Takes an array of downloadable file representations and converts it into an array of WC_Product_Download objects, indexed by download ID.
Properties
$cache_group
Stores meta in cache for future reads.
protected
string
$cache_group
= ''
A group must be set to to enable caching.
Tags
$changes
Core data changes for this object.
protected
array<string|int, mixed>
$changes
= array()
Tags
$data
Core data for this object. Name value pairs (name + default value).
protected
array<string|int, mixed>
$data
= array()
Tags
$data_store
Contains a reference to the data store for this class.
protected
object
$data_store
Tags
$default_data
Set to _data on construct so we can track and reset data if needed.
protected
array<string|int, mixed>
$default_data
= array()
Tags
$extra_data
Extra data for this object. Name value pairs (name + default value).
protected
array<string|int, mixed>
$extra_data
= array()
Used as a standard way for sub classes (like product types) to add additional information to an inherited class.
Tags
$id
ID for this object.
protected
int
$id
= 0
Tags
$legacy_datastore_props
List of properties that were earlier managed by data store. However, since DataStore is a not a stored entity in itself, they used to store data in metadata of the data object.
protected
array<string|int, mixed>
$legacy_datastore_props
= array()
With custom tables, some of these are moved from metadata to their own columns, but existing code will still try to add them to metadata. This array is used to keep track of such properties.
Only reason to add a property here is that you are moving properties from DataStore instance to data object. If you are adding a new property, consider adding it to to $data array instead.
$meta_data
Stores additional meta data.
protected
array<string|int, mixed>
$meta_data
=
ull
Tags
$object_read
This is false until the object is read from the DB.
protected
bool
$object_read
= alse
Tags
$object_type
This is the name of this object type.
protected
string
$object_type
= 'data'
Tags
$parent_data
Parent data.
protected
array<string|int, mixed>
$parent_data
= array('title' => '', 'sku' => '', 'manage_stock' => '', 'backorders' => '', 'stock_quantity' => '', 'weight' => '', 'length' => '', 'width' => '', 'height' => '', 'tax_class' => '', 'shipping_class_id' => '', 'image_id' => '', 'purchase_note' => '')
$post_type
Post type.
protected
string
$post_type
= 'product_variation'
$supports
Supported features such as 'ajax_add_to_cart'.
protected
array<string|int, mixed>
$supports
= array()
Methods
__clone()
When the object is cloned, make sure meta is duplicated correctly.
public
__clone() : mixed
Tags
Return values
mixed —__construct()
Override the default constructor to set custom defaults.
public
__construct(int|WC_Product|object $product) : mixed
Parameters
- $product : int|WC_Product|object
-
Product to init.
Return values
mixed —__get()
Magic __get method for backwards compatibility. Maps legacy vars to new getters.
public
__get(string $key) : mixed
Parameters
- $key : string
-
Key name.
Return values
mixed —__isset()
Magic __isset method for backwards compatibility. Legacy properties which could be accessed directly in the past.
public
__isset(string $key) : bool
Parameters
- $key : string
-
Key name.
Return values
bool —__sleep()
Only store the object ID to avoid serializing the data object instance.
public
__sleep() : array<string|int, mixed>
Return values
array<string|int, mixed> —__toString()
Change data to JSON format.
public
__toString() : string
Tags
Return values
string — Data in JSON format.__wakeup()
Re-run the constructor with the object ID.
public
__wakeup() : mixed
If the object no longer exists, remove the ID.
Return values
mixed —add_meta_data()
Add meta data.
public
add_meta_data(string $key, string|array<string|int, mixed> $value[, bool $unique = false ]) : mixed
Parameters
- $key : string
-
Meta key.
- $value : string|array<string|int, mixed>
-
Meta value.
- $unique : bool = false
-
Should this be a unique key?.
Tags
Return values
mixed —add_to_cart_aria_describedby()
Get the aria-describedby description for the add to cart button.
public
add_to_cart_aria_describedby() : string
Return values
string —add_to_cart_description()
Get the add to cart button text description - used in aria tags.
public
add_to_cart_description() : string
Tags
Return values
string —add_to_cart_text()
Get the add to cart button text.
public
add_to_cart_text() : string
Return values
string —add_to_cart_url()
Get the add to url used mainly in loops.
public
add_to_cart_url() : string
Return values
string —adjust_price()
Adjust a products price dynamically.
public
adjust_price(mixed $price) : mixed
Parameters
- $price : mixed
Tags
Return values
mixed —apply_changes()
Merge changes with data and clear.
public
apply_changes() : mixed
Tags
Return values
mixed —backorders_allowed()
Returns whether or not the product can be backordered.
public
backorders_allowed() : bool
Return values
bool —backorders_require_notification()
Returns whether or not the product needs to notify the customer on backorder.
public
backorders_require_notification() : bool
Return values
bool —check_stock_status()
Check if the stock status needs changing.
public
check_stock_status() : mixed
Tags
Return values
mixed —child_has_dimensions()
Does a child have dimensions?
public
child_has_dimensions() : bool
Tags
Return values
bool —child_has_weight()
Does a child have a weight?
public
child_has_weight() : bool
Tags
Return values
bool —delete()
Delete an object, set the ID to 0, and return result.
public
delete([bool $force_delete = false ]) : bool
Parameters
- $force_delete : bool = false
-
Should the date be deleted permanently.
Tags
Return values
bool — resultdelete_meta_data()
Delete meta data.
public
delete_meta_data(string $key) : mixed
Parameters
- $key : string
-
Meta key.
Tags
Return values
mixed —delete_meta_data_by_mid()
Delete meta data.
public
delete_meta_data_by_mid(int $mid) : mixed
Parameters
- $mid : int
-
Meta ID.
Tags
Return values
mixed —delete_meta_data_value()
Delete meta data with a matching value.
public
delete_meta_data_value(string $key, mixed $value) : mixed
Parameters
- $key : string
-
Meta key.
- $value : mixed
-
Meta value. Entries will only be removed that match the value.
Tags
Return values
mixed —enable_dimensions_display()
Returns whether or not we are showing dimensions on the product page.
public
enable_dimensions_display() : bool
Tags
Return values
bool —exists()
Returns whether or not the product post exists.
public
exists() : bool
Return values
bool —generate_meta_cache_key()
Generate cache key from id and group.
public
static generate_meta_cache_key(int|string $id, string $cache_group) : string
Parameters
- $id : int|string
-
Object ID.
- $cache_group : string
-
Group name use to store cache. Whole group cache can be invalidated in one go.
Tags
Return values
string — Meta cache key.get_attribute()
Returns a single product attribute as a string.
public
get_attribute(string $attribute) : string
Parameters
- $attribute : string
-
to get.
Return values
string —get_attribute_summary()
Get attribute summary.
public
get_attribute_summary([string $context = 'view' ]) : string
By default, attribute summary contains comma-delimited 'attribute_name: attribute_value' pairs for all attributes.
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
string —get_attributes()
Returns product attributes.
public
get_attributes([string $context = 'view' ]) : array<string|int, mixed>
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Return values
array<string|int, mixed> —get_availability()
Returns the availability of the product.
public
get_availability() : array<string|int, string>
Return values
array<string|int, string> —get_average_rating()
Get average rating.
public
get_average_rating([string $context = 'view' ]) : float
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Return values
float —get_backorders()
Get backorders.
public
get_backorders([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
string — yes no or notifyget_catalog_visibility()
Get catalog visibility.
public
get_catalog_visibility([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Return values
string —get_categories()
Returns the product categories.
public
get_categories([string $sep = ', ' ][, string $before = '' ][, string $after = '' ]) : string
Parameters
- $sep : string = ', '
-
(default: ', ').
- $before : string = ''
-
(default: '').
- $after : string = ''
-
(default: '').
Tags
Return values
string —get_category_ids()
Get category ids.
public
get_category_ids([string $context = 'view' ]) : array<string|int, mixed>
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
array<string|int, mixed> —get_changes()
Return data changes only.
public
get_changes() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_child()
Returns the child product.
public
get_child(mixed $child_id) : WC_Product|WC_Product_variation
Parameters
- $child_id : mixed
Tags
Return values
WC_Product|WC_Product_variation —get_children()
Returns the children IDs if applicable. Overridden by child classes.
public
get_children() : array<string|int, mixed>
Return values
array<string|int, mixed> — of IDsget_cross_sell_ids()
Get cross sell IDs.
public
get_cross_sell_ids([string $context = 'view' ]) : array<string|int, mixed>
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
array<string|int, mixed> —get_cross_sells()
Returns the cross sell product ids.
public
get_cross_sells() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_data()
Returns all data for this object.
public
get_data() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_data_keys()
Returns array of expected data keys for this object.
public
get_data_keys() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_data_store()
Get the data store.
public
get_data_store() : object
Tags
Return values
object —get_date_created()
Get product created date.
public
get_date_created([string $context = 'view' ]) : WC_DateTime|null
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
WC_DateTime|null — object if the date is set or null if there is no date.get_date_modified()
Get product modified date.
public
get_date_modified([string $context = 'view' ]) : WC_DateTime|null
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
WC_DateTime|null — object if the date is set or null if there is no date.get_date_on_sale_from()
Get date on sale from.
public
get_date_on_sale_from([string $context = 'view' ]) : WC_DateTime|null
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
WC_DateTime|null — object if the date is set or null if there is no date.get_date_on_sale_to()
Get date on sale to.
public
get_date_on_sale_to([string $context = 'view' ]) : WC_DateTime|null
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
WC_DateTime|null — object if the date is set or null if there is no date.get_default_attributes()
Get default attributes.
public
get_default_attributes([string $context = 'view' ]) : array<string|int, mixed>
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
array<string|int, mixed> —get_description()
Get product description.
public
get_description([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
string —get_dimensions()
Returns formatted dimensions.
public
get_dimensions([bool $formatted = true ]) : string|array<string|int, mixed>
Parameters
- $formatted : bool = true
-
True by default for legacy support - will be false/not set in future versions to return the array only. Use wc_format_dimensions for formatted versions instead.
Return values
string|array<string|int, mixed> —get_display_price()
Returns the price including or excluding tax, based on the 'woocommerce_tax_display_shop' setting.
public
get_display_price([string $price = '' ][, int $qty = 1 ]) : string
Parameters
- $price : string = ''
-
to calculate, left blank to just use get_price()
- $qty : int = 1
-
passed on to get_price_including_tax() or get_price_excluding_tax()
Tags
Return values
string —get_download_expiry()
Get download expiry.
public
get_download_expiry([string $context = 'view' ]) : int
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
int —get_download_limit()
Get download limit.
public
get_download_limit([string $context = 'view' ]) : int
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
int —get_downloadable()
Get downloadable.
public
get_downloadable([string $context = 'view' ]) : bool
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
bool —get_downloads()
Get downloads.
public
get_downloads([string $context = 'view' ]) : array<string|int, mixed>
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
array<string|int, mixed> —get_extra_data_keys()
Returns all "extra" data keys for an object (for sub objects like product types).
public
get_extra_data_keys() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_featured()
If the product is featured.
public
get_featured([string $context = 'view' ]) : bool
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
bool —get_file()
Get a file by $download_id.
public
get_file([string $download_id = '' ]) : array<string|int, mixed>|false
Parameters
- $download_id : string = ''
-
file identifier.
Return values
array<string|int, mixed>|false — if not foundget_file_download_path()
Get file download path identified by $download_id.
public
get_file_download_path(string $download_id) : string
Parameters
- $download_id : string
-
file identifier.
Return values
string —get_files()
Same as get_downloads in CRUD.
public
get_files() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_formatted_name()
Get product name with SKU or ID. Used within admin.
public
get_formatted_name() : string
Return values
string — Formatted product nameget_formatted_variation_attributes()
Get formatted variation data with WC < 2.4 back compat and proper formatting of text-based attribute names.
public
get_formatted_variation_attributes([bool $flat = false ]) : string
Parameters
- $flat : bool = false
Tags
Return values
string —get_gallery_attachment_ids()
Returns the gallery attachment ids.
public
get_gallery_attachment_ids() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_gallery_image_ids()
Returns the gallery attachment ids.
public
get_gallery_image_ids([string $context = 'view' ]) : array<string|int, mixed>
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Return values
array<string|int, mixed> —get_height()
Returns the product height.
public
get_height([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Return values
string —get_id()
Returns the unique ID for this object.
public
get_id() : int
Tags
Return values
int —get_image()
Returns the main product image.
public
get_image([string $size = 'woocommerce_thumbnail' ][, array<string|int, mixed> $attr = array() ][, bool $placeholder = true ]) : string
Parameters
- $size : string = 'woocommerce_thumbnail'
-
(default: 'woocommerce_thumbnail').
- $attr : array<string|int, mixed> = array()
-
Image attributes.
- $placeholder : bool = true
-
True to return $placeholder if no image is found, or false to return an empty string.
Return values
string —get_image_id()
Get main image ID.
public
get_image_id([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
string —get_length()
Returns the product length.
public
get_length([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Return values
string —get_low_stock_amount()
Get low stock amount.
public
get_low_stock_amount([string $context = 'view' ]) : int|string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
int|string — Returns empty string if value not setget_manage_stock()
Return if product manage stock.
public
get_manage_stock([string $context = 'view' ]) : bool|string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
bool|string — true, false, or parent.get_matching_variation()
Match a variation to a given set of attributes using a WP_Query.
public
get_matching_variation([array<string|int, mixed> $match_attributes = array() ]) : mixed
Parameters
- $match_attributes : array<string|int, mixed> = array()
Tags
Return values
mixed —get_max_purchase_quantity()
Get max quantity which can be purchased at once.
public
get_max_purchase_quantity() : int
Tags
Return values
int — Quantity or -1 if unlimited.get_menu_order()
Get menu order.
public
get_menu_order([string $context = 'view' ]) : int
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
int —get_meta()
Get Meta Data by Key.
public
get_meta([string $key = '' ][, bool $single = true ][, string $context = 'view' ]) : mixed
Parameters
- $key : string = ''
-
Meta Key.
- $single : bool = true
-
return first found meta with key, or all with $key.
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
mixed —get_meta_cache_key()
Helper method to compute meta cache key. Different from WP Meta cache key in that meta data cached using this key also contains meta_id column.
public
get_meta_cache_key() : string
Tags
Return values
string —get_meta_data()
Get All Meta Data.
public
get_meta_data() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> — of objects.get_min_purchase_quantity()
Get min quantity which can be purchased at once.
public
get_min_purchase_quantity() : int
Tags
Return values
int —get_name()
Get product name.
public
get_name([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
string —get_object_read()
Get object read property.
public
get_object_read() : bool
Tags
Return values
bool —get_parent()
Get the parent of the post.
public
get_parent() : int
Tags
Return values
int —get_parent_data()
Get the parent data array for this variation.
public
get_parent_data() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_parent_id()
Get parent ID.
public
get_parent_id([string $context = 'view' ]) : int
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
int —get_permalink()
Wrapper for get_permalink. Adds this variations attributes to the URL.
public
get_permalink([array<string|int, mixed>|null $item_object = null ]) : string
Parameters
- $item_object : array<string|int, mixed>|null = null
-
item array If a cart or order item is passed, we can get a link containing the exact attributes selected for the variation, rather than the default attributes.
Return values
string —get_post_data()
Get the product's post data.
public
get_post_data() : WP_Post
Tags
Return values
WP_Post —get_post_password()
Get post password.
public
get_post_password([string $context = 'view' ]) : int
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
int —get_price()
Returns the product's active price.
public
get_price([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Return values
string — priceget_price_excluding_tax()
Returns the price (excluding tax) - ignores tax_class filters since the price may *include* tax and thus needs subtracting.
public
get_price_excluding_tax([int $qty = 1 ][, string $price = '' ]) : string
Uses store base tax rates. Can work for a specific $qty for more accurate taxes.
Parameters
- $qty : int = 1
- $price : string = ''
-
to calculate, left blank to just use get_price()
Tags
Return values
string —get_price_html()
Returns the price in html format.
public
get_price_html([string $deprecated = '' ]) : string
Parameters
- $deprecated : string = ''
-
Deprecated param.
Return values
string —get_price_html_from_text()
Functions for getting parts of a price, in html, used by get_price_html.
public
get_price_html_from_text() : string
Tags
Return values
string —get_price_html_from_to()
Functions for getting parts of a price, in html, used by get_price_html.
public
get_price_html_from_to(string $from, mixed $to) : string
Parameters
- $from : string
-
String or float to wrap with 'from' text
- $to : mixed
-
String or float to wrap with 'to' text
Tags
Return values
string —get_price_including_tax()
Returns the price (including tax). Uses customer tax rates. Can work for a specific $qty for more accurate taxes.
public
get_price_including_tax([int $qty = 1 ][, string $price = '' ]) : string
Parameters
- $qty : int = 1
- $price : string = ''
-
to calculate, left blank to just use get_price()
Tags
Return values
string —get_price_suffix()
Get the suffix to display after prices > 0.
public
get_price_suffix([string $price = '' ][, int $qty = 1 ]) : string
Parameters
- $price : string = ''
-
to calculate, left blank to just use get_price().
- $qty : int = 1
-
passed on to get_price_including_tax() or get_price_excluding_tax().
Return values
string —get_purchase_note()
Get purchase note.
public
get_purchase_note([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
string —get_rating_count()
Get the total amount (COUNT) of ratings, or just the count for one rating e.g. number of 5 star ratings.
public
get_rating_count([int $value = null ]) : int
Parameters
- $value : int = null
-
Optional. Rating value to get the count for. By default returns the count of all rating values.
Return values
int —get_rating_counts()
Get rating count.
public
get_rating_counts([string $context = 'view' ]) : array<string|int, mixed>
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Return values
array<string|int, mixed> — of countsget_rating_html()
Returns the product rating in html format.
public
get_rating_html([string $rating = null ]) : string
Parameters
- $rating : string = null
-
(default: '')
Tags
Return values
string —get_regular_price()
Returns the product's regular price.
public
get_regular_price([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Return values
string — priceget_related()
Get and return related products.
public
get_related([int $limit = 5 ]) : array<string|int, mixed>
Parameters
- $limit : int = 5
Tags
Return values
array<string|int, mixed> —get_review_count()
Get review count.
public
get_review_count([string $context = 'view' ]) : int
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Return values
int —get_reviews_allowed()
Return if reviews is allowed.
public
get_reviews_allowed([string $context = 'view' ]) : bool
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
bool —get_sale_price()
Returns the product's sale price.
public
get_sale_price([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Return values
string — priceget_shipping_class()
Returns the product shipping class SLUG.
public
get_shipping_class() : string
Return values
string —get_shipping_class_id()
Get shipping class ID.
public
get_shipping_class_id([string $context = 'view' ]) : int
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
int —get_short_description()
Get product short description.
public
get_short_description([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
string —get_sku()
Get SKU (Stock-keeping unit) - product unique ID.
public
get_sku([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Return values
string —get_slug()
Get product slug.
public
get_slug([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
string —get_sold_individually()
Return if should be sold individually.
public
get_sold_individually([string $context = 'view' ]) : bool
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
bool —get_status()
Get product status.
public
get_status([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
string —get_stock_managed_by_id()
If the stock level comes from another product ID.
public
get_stock_managed_by_id() : int
Tags
Return values
int —get_stock_quantity()
Returns number of items available for sale.
public
get_stock_quantity([string $context = 'view' ]) : int|null
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Return values
int|null —get_stock_status()
Return the stock status.
public
get_stock_status([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
string —get_tag_ids()
Get tag ids.
public
get_tag_ids([string $context = 'view' ]) : array<string|int, mixed>
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
array<string|int, mixed> —get_tags()
Returns the product tags.
public
get_tags([string $sep = ', ' ][, string $before = '' ][, string $after = '' ]) : array<string|int, mixed>
Parameters
- $sep : string = ', '
-
(default: ', ').
- $before : string = ''
-
(default: '').
- $after : string = ''
-
(default: '').
Tags
Return values
array<string|int, mixed> —get_tax_class()
Returns the tax class.
public
get_tax_class([string $context = 'view' ]) : string
Does not use get_prop so it can handle 'parent' inheritance correctly.
Parameters
- $context : string = 'view'
-
view, edit, or unfiltered.
Return values
string —get_tax_status()
Returns the tax status.
public
get_tax_status([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Return values
string —get_title()
Get the product's title. For variations this is the parent product name.
public
get_title() : string
Return values
string —get_total_sales()
Get number total of sales.
public
get_total_sales([string $context = 'view' ]) : int
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
int —get_total_stock()
Get total stock - This is the stock of parent and children combined.
public
get_total_stock() : int
Tags
Return values
int —get_type()
Get internal type.
public
get_type() : string
Return values
string —get_upsell_ids()
Get upsell IDs.
public
get_upsell_ids([string $context = 'view' ]) : array<string|int, mixed>
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
array<string|int, mixed> —get_upsells()
Returns the upsell product ids.
public
get_upsells() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_variation_attributes()
Get variation attribute values. Keys are prefixed with attribute_, as stored, unless $with_prefix is false.
public
get_variation_attributes([bool $with_prefix = true ]) : array<string|int, mixed>
Parameters
- $with_prefix : bool = true
-
Whether keys should be prepended with attribute_ or not, default is true.
Return values
array<string|int, mixed> — of attributes and their values for this variation.get_variation_default_attributes()
If set, get the default attributes for a variable product.
public
get_variation_default_attributes() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_variation_description()
Get product variation description.
public
get_variation_description() : string
Tags
Return values
string —get_variation_id()
Get variation ID.
public
get_variation_id() : int
Tags
Return values
int —get_virtual()
Get virtual.
public
get_virtual([string $context = 'view' ]) : bool
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
bool —get_weight()
Returns the product's weight.
public
get_weight([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Return values
string —get_width()
Returns the product width.
public
get_width([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Return values
string —grouped_product_sync()
public
grouped_product_sync() : mixed
Tags
Return values
mixed —has_all_attributes_set()
Check if all variation's attributes are set.
public
has_all_attributes_set() : bool
Tags
Return values
bool —has_attributes()
Returns whether or not the product has any visible attributes.
public
has_attributes() : bool
Variations are mapped to specific attributes unlike products, and the return value of ->get_attributes differs. Therefore this returns false.
Return values
bool —has_child()
Returns whether or not the product has any child product.
public
has_child() : bool
Return values
bool —has_default_attributes()
Check if variable product has default attributes set.
public
has_default_attributes() : bool
Tags
Return values
bool —has_dimensions()
Returns whether or not the product has dimensions set.
public
has_dimensions() : bool
Return values
bool —has_enough_stock()
Returns whether or not the product has enough stock for the order.
public
has_enough_stock(mixed $quantity) : bool
Parameters
- $quantity : mixed
-
Quantity of a product added to an order.
Return values
bool —has_file()
Check if downloadable product has a file attached.
public
has_file([string $download_id = '' ]) : bool
Parameters
- $download_id : string = ''
-
file identifier.
Tags
Return values
bool — Whether downloadable product has a file attached.has_options()
Returns whether or not the product has additional options that need selecting before adding to cart.
public
has_options() : bool
Tags
Return values
bool —has_weight()
Returns whether or not the product has weight set.
public
has_weight() : bool
Return values
bool —increase_stock()
Increase stock level of the product.
public
increase_stock([int $amount = 1 ]) : int
Parameters
- $amount : int = 1
-
Amount to increase by. Default 1.
Tags
Return values
int — new stock levelinit_meta_data()
Helper function to initialize metadata entries from filtered raw meta data.
public
init_meta_data([array<string|int, mixed> $filtered_meta_data = array() ]) : mixed
Parameters
- $filtered_meta_data : array<string|int, mixed> = array()
-
Filtered metadata fetched from DB.
Return values
mixed —is_downloadable()
Checks if a product is downloadable.
public
is_downloadable() : bool
Return values
bool —is_featured()
Returns whether or not the product is featured.
public
is_featured() : bool
Return values
bool —is_in_stock()
Returns whether or not the product can be purchased.
public
is_in_stock() : bool
This returns true for 'instock' and 'onbackorder' stock statuses.
Return values
bool —is_on_backorder()
Check if a product is on backorder.
public
is_on_backorder(int $qty_in_cart) : bool
Parameters
- $qty_in_cart : int
-
(default: 0).
Return values
bool —is_on_sale()
Returns whether or not the product is on sale.
public
is_on_sale([string $context = 'view' ]) : bool
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Return values
bool —is_purchasable()
Returns false if the product cannot be bought.
public
is_purchasable() : bool
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.
Return values
bool —is_shipping_taxable()
Returns whether or not the product shipping is taxable.
public
is_shipping_taxable() : bool
Return values
bool —is_sold_individually()
Check if a product is sold individually (no quantities).
public
is_sold_individually() : bool
Return values
bool —is_taxable()
Returns whether or not the product is taxable.
public
is_taxable() : bool
Return values
bool —is_type()
Checks the product type.
public
is_type(string|array<string|int, mixed> $type) : bool
Backwards compatibility with downloadable/virtual.
Parameters
- $type : string|array<string|int, mixed>
-
Array or string of types.
Return values
bool —is_virtual()
Checks if a product is virtual (has no shipping).
public
is_virtual() : bool
Return values
bool —is_visible()
Returns whether or not the product is visible in the catalog.
public
is_visible() : bool
Return values
bool —list_attributes()
Lists a table of attributes for the product page.
public
list_attributes() : mixed
Tags
Return values
mixed —managing_stock()
Returns whether or not the product is stock managed.
public
managing_stock() : bool
Return values
bool —meta_exists()
See if meta data exists, since get_meta always returns a '' or array().
public
meta_exists([string $key = '' ]) : bool
Parameters
- $key : string = ''
-
Meta Key.
Tags
Return values
bool —needs_shipping()
Checks if a product needs shipping.
public
needs_shipping() : bool
Return values
bool —parent_is_visible()
Returns whether or not the variations parent is visible.
public
parent_is_visible() : bool
Tags
Return values
bool —prime_raw_meta_data_cache()
Prime caches for raw meta data. This includes meta_id column as well, which is not included by default in WP meta data.
public
static prime_raw_meta_data_cache(array<string|int, mixed> $raw_meta_data_collection, string $cache_group) : mixed
Parameters
- $raw_meta_data_collection : array<string|int, mixed>
-
Array of objects of { object_id => array( meta_row_1, meta_row_2, ... }.
- $cache_group : string
-
Name of cache group.
Tags
Return values
mixed —read_meta_data()
Read Meta Data from the database. Ignore any internal properties.
public
read_meta_data([bool $force_read = false ]) : mixed
Uses it's own caches because get_metadata does not provide meta_ids.
Parameters
- $force_read : bool = false
-
True to force a new DB read (and update cache).
Tags
Return values
mixed —reduce_stock()
Reduce stock level of the product.
public
reduce_stock([int $amount = 1 ]) : int
Parameters
- $amount : int = 1
-
Amount to reduce by. Default: 1
Tags
Return values
int — new stock levelsave()
Save should create or update based on object existence.
public
save() : int
Tags
Return values
int —save_meta_data()
Update Meta Data in the database.
public
save_meta_data() : mixed
Tags
Return values
mixed —set_attribute_summary()
Set attribute summary.
public
set_attribute_summary(string $attribute_summary) : mixed
By default, attribute summary contains comma-delimited 'attribute_name: attribute_value' pairs for all attributes.
Parameters
- $attribute_summary : string
-
Summary of attribute names and values assigned to the variation.
Tags
Return values
mixed —set_attributes()
Set attributes. Unlike the parent product which uses terms, variations are assigned specific attributes using name value pairs.
public
set_attributes(array<string|int, mixed> $raw_attributes) : mixed
Parameters
- $raw_attributes : array<string|int, mixed>
-
array of raw attributes.
Return values
mixed —set_average_rating()
Set average rating. Read only.
public
set_average_rating(float $average) : mixed
Parameters
- $average : float
-
Product average rating.
Return values
mixed —set_backorders()
Set backorders.
public
set_backorders(string $backorders) : mixed
Parameters
- $backorders : string
-
Options: 'yes', 'no' or 'notify'.
Tags
Return values
mixed —set_catalog_visibility()
Set catalog visibility.
public
set_catalog_visibility(string $visibility) : mixed
Parameters
- $visibility : string
-
Options: 'hidden', 'visible', 'search' and 'catalog'.
Tags
Return values
mixed —set_category_ids()
Set the product categories.
public
set_category_ids(array<string|int, mixed> $term_ids) : mixed
Parameters
- $term_ids : array<string|int, mixed>
-
List of terms IDs.
Tags
Return values
mixed —set_cross_sell_ids()
Set crosssell IDs.
public
set_cross_sell_ids(array<string|int, mixed> $cross_sell_ids) : mixed
Parameters
- $cross_sell_ids : array<string|int, mixed>
-
IDs from the cross-sell products.
Tags
Return values
mixed —set_date_created()
Set product created date.
public
set_date_created([string|int|null $date = null ]) : mixed
Parameters
- $date : string|int|null = null
-
UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.
Tags
Return values
mixed —set_date_modified()
Set product modified date.
public
set_date_modified([string|int|null $date = null ]) : mixed
Parameters
- $date : string|int|null = null
-
UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.
Tags
Return values
mixed —set_date_on_sale_from()
Set date on sale from.
public
set_date_on_sale_from([string|int|null $date = null ]) : mixed
Parameters
- $date : string|int|null = null
-
UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.
Tags
Return values
mixed —set_date_on_sale_to()
Set date on sale to.
public
set_date_on_sale_to([string|int|null $date = null ]) : mixed
Parameters
- $date : string|int|null = null
-
UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.
Tags
Return values
mixed —set_default_attributes()
Set default attributes. These will be saved as strings and should map to attribute values.
public
set_default_attributes(array<string|int, mixed> $default_attributes) : mixed
Parameters
- $default_attributes : array<string|int, mixed>
-
List of default attributes.
Tags
Return values
mixed —set_defaults()
Set all props to default values.
public
set_defaults() : mixed
Tags
Return values
mixed —set_description()
Set product description.
public
set_description(string $description) : mixed
Parameters
- $description : string
-
Product description.
Tags
Return values
mixed —set_download_expiry()
Set download expiry.
public
set_download_expiry(int|string $download_expiry) : mixed
Parameters
- $download_expiry : int|string
-
Product download expiry.
Tags
Return values
mixed —set_download_limit()
Set download limit.
public
set_download_limit(int|string $download_limit) : mixed
Parameters
- $download_limit : int|string
-
Product download limit.
Tags
Return values
mixed —set_downloadable()
Set if the product is downloadable.
public
set_downloadable(bool|string $downloadable) : mixed
Parameters
- $downloadable : bool|string
-
Whether product is downloadable or not.
Tags
Return values
mixed —set_downloads()
Set downloads.
public
set_downloads(array<string|int, mixed> $downloads_array) : mixed
Parameters
- $downloads_array : array<string|int, mixed>
-
Array of WC_Product_Download objects or arrays.
Tags
Return values
mixed —set_featured()
Set if the product is featured.
public
set_featured(bool|string $featured) : mixed
Parameters
- $featured : bool|string
-
Whether the product is featured or not.
Tags
Return values
mixed —set_gallery_image_ids()
Set gallery attachment ids.
public
set_gallery_image_ids(array<string|int, mixed> $image_ids) : mixed
Parameters
- $image_ids : array<string|int, mixed>
-
List of image ids.
Tags
Return values
mixed —set_height()
Set the product height.
public
set_height(float|string $height) : mixed
Parameters
- $height : float|string
-
Total height.
Tags
Return values
mixed —set_id()
Set ID.
public
set_id(int $id) : mixed
Parameters
- $id : int
-
ID.
Tags
Return values
mixed —set_image_id()
Set main image ID.
public
set_image_id([int|string $image_id = '' ]) : mixed
Parameters
- $image_id : int|string = ''
-
Product image id.
Tags
Return values
mixed —set_length()
Set the product length.
public
set_length(float|string $length) : mixed
Parameters
- $length : float|string
-
Total length.
Tags
Return values
mixed —set_low_stock_amount()
Set low stock amount.
public
set_low_stock_amount(int|string $amount) : mixed
Parameters
- $amount : int|string
-
Empty string if value not set.
Tags
Return values
mixed —set_manage_stock()
Set if product manage stock.
public
set_manage_stock(bool $manage_stock) : mixed
Parameters
- $manage_stock : bool
-
Whether or not manage stock is enabled.
Tags
Return values
mixed —set_menu_order()
Set menu order.
public
set_menu_order(int $menu_order) : mixed
Parameters
- $menu_order : int
-
Menu order.
Tags
Return values
mixed —set_meta_data()
Set all meta data from array.
public
set_meta_data(array<string|int, mixed> $data) : mixed
Parameters
- $data : array<string|int, mixed>
-
Key/Value pairs.
Tags
Return values
mixed —set_name()
Set product name.
public
set_name(string $name) : mixed
Parameters
- $name : string
-
Product name.
Tags
Return values
mixed —set_object_read()
Set object read property.
public
set_object_read([bool $read = true ]) : mixed
Parameters
- $read : bool = true
-
Should read?.
Tags
Return values
mixed —set_parent_data()
Set the parent data array for this variation.
public
set_parent_data(array<string|int, mixed> $parent_data) : mixed
Parameters
- $parent_data : array<string|int, mixed>
-
parent data array for this variation.
Tags
Return values
mixed —set_parent_id()
Set parent ID.
public
set_parent_id(int $parent_id) : mixed
Parameters
- $parent_id : int
-
Product parent ID.
Tags
Return values
mixed —set_post_password()
Set post password.
public
set_post_password(int $post_password) : mixed
Parameters
- $post_password : int
-
Post password.
Tags
Return values
mixed —set_price()
Set the product's active price.
public
set_price(string $price) : mixed
Parameters
- $price : string
-
Price.
Return values
mixed —set_props()
Set a collection of props in one go, collect any errors, and return the result.
public
set_props(array<string|int, mixed> $props[, string $context = 'set' ]) : bool|WP_Error
Only sets using public methods.
Parameters
- $props : array<string|int, mixed>
-
Key value pairs to set. Key is the prop and should map to a setter function name.
- $context : string = 'set'
-
In what context to run this.
Tags
Return values
bool|WP_Error —set_purchase_note()
Set purchase note.
public
set_purchase_note(string $purchase_note) : mixed
Parameters
- $purchase_note : string
-
Purchase note.
Tags
Return values
mixed —set_rating_counts()
Set rating counts. Read only.
public
set_rating_counts(array<string|int, mixed> $counts) : mixed
Parameters
- $counts : array<string|int, mixed>
-
Product rating counts.
Return values
mixed —set_regular_price()
Set the product's regular price.
public
set_regular_price(string $price) : mixed
Parameters
- $price : string
-
Regular price.
Tags
Return values
mixed —set_review_count()
Set review count. Read only.
public
set_review_count(int $count) : mixed
Parameters
- $count : int
-
Product review count.
Return values
mixed —set_reviews_allowed()
Set if reviews is allowed.
public
set_reviews_allowed(bool $reviews_allowed) : mixed
Parameters
- $reviews_allowed : bool
-
Reviews allowed or not.
Tags
Return values
mixed —set_sale_price()
Set the product's sale price.
public
set_sale_price(string $price) : mixed
Parameters
- $price : string
-
sale price.
Tags
Return values
mixed —set_shipping_class_id()
Set shipping class ID.
public
set_shipping_class_id(int $id) : mixed
Parameters
- $id : int
-
Product shipping class id.
Tags
Return values
mixed —set_short_description()
Set product short description.
public
set_short_description(string $short_description) : mixed
Parameters
- $short_description : string
-
Product short description.
Tags
Return values
mixed —set_sku()
Set SKU.
public
set_sku(string $sku) : mixed
Parameters
- $sku : string
-
Product SKU.
Tags
Return values
mixed —set_slug()
Set product slug.
public
set_slug(string $slug) : mixed
Parameters
- $slug : string
-
Product slug.
Tags
Return values
mixed —set_sold_individually()
Set if should be sold individually.
public
set_sold_individually(bool $sold_individually) : mixed
Parameters
- $sold_individually : bool
-
Whether or not product is sold individually.
Tags
Return values
mixed —set_status()
Set product status.
public
set_status(string $status) : mixed
Parameters
- $status : string
-
Product status.
Tags
Return values
mixed —set_stock()
Set stock level of the product.
public
set_stock([int $amount = null ][, string $mode = 'set' ]) : int
Parameters
- $amount : int = null
- $mode : string = 'set'
Tags
Return values
int —set_stock_quantity()
Set number of items available for sale.
public
set_stock_quantity(float|null $quantity) : mixed
Parameters
- $quantity : float|null
-
Stock quantity.
Tags
Return values
mixed —set_stock_status()
Set stock status.
public
set_stock_status([string $status = 'instock' ]) : mixed
Parameters
- $status : string = 'instock'
-
New status.
Return values
mixed —set_tag_ids()
Set the product tags.
public
set_tag_ids(array<string|int, mixed> $term_ids) : mixed
Parameters
- $term_ids : array<string|int, mixed>
-
List of terms IDs.
Tags
Return values
mixed —set_tax_class()
Set the tax class.
public
set_tax_class(string $class) : mixed
Parameters
- $class : string
-
Tax class.
Tags
Return values
mixed —set_tax_status()
Set the tax status.
public
set_tax_status(string $status) : mixed
Parameters
- $status : string
-
Tax status.
Tags
Return values
mixed —set_total_sales()
Set number total of sales.
public
set_total_sales(int $total) : mixed
Parameters
- $total : int
-
Total of sales.
Tags
Return values
mixed —set_upsell_ids()
Set upsell IDs.
public
set_upsell_ids(array<string|int, mixed> $upsell_ids) : mixed
Parameters
- $upsell_ids : array<string|int, mixed>
-
IDs from the up-sell products.
Tags
Return values
mixed —set_virtual()
Set if the product is virtual.
public
set_virtual(bool|string $virtual) : mixed
Parameters
- $virtual : bool|string
-
Whether product is virtual or not.
Tags
Return values
mixed —set_weight()
Set the product's weight.
public
set_weight(float|string $weight) : mixed
Parameters
- $weight : float|string
-
Total weight.
Tags
Return values
mixed —set_width()
Set the product width.
public
set_width(float|string $width) : mixed
Parameters
- $width : float|string
-
Total width.
Tags
Return values
mixed —single_add_to_cart_text()
Get the add to cart button text for the single page.
public
single_add_to_cart_text() : string
Return values
string —supports()
Check if a product supports a given feature.
public
supports(string $feature) : bool
Product classes should override this to declare support (or lack of support) for a feature.
Parameters
- $feature : string
-
string The name of a feature to test support for.
Tags
Return values
bool — True if the product supports the feature, false otherwise.sync_attributes()
Sync the variable product's attributes with the variations.
public
static sync_attributes( $product[, bool $children = false ]) : mixed
Parameters
Return values
mixed —sync_average_rating()
Sync product rating. Can be called statically.
public
static sync_average_rating(int $post_id) : mixed
Parameters
- $post_id : int
Tags
Return values
mixed —sync_rating_count()
Sync product rating count. Can be called statically.
public
static sync_rating_count(int $post_id) : mixed
Parameters
- $post_id : int
Tags
Return values
mixed —update_meta_data()
Update meta data by key or ID, if provided.
public
update_meta_data(string $key, string|array<string|int, mixed> $value, int $meta_id) : mixed
Parameters
- $key : string
-
Meta key.
- $value : string|array<string|int, mixed>
-
Meta value.
- $meta_id : int
-
Meta ID.
Tags
Return values
mixed —validate_props()
Ensure properties are set correctly before save.
public
validate_props() : mixed
Tags
Return values
mixed —variable_product_sync()
Sync variable product prices with the children lowest/highest prices.
public
variable_product_sync(int $product_id) : mixed
Parameters
- $product_id : int
Tags
Return values
mixed —variation_is_active()
Controls whether this particular variation will appear greyed-out (inactive) or not (active).
public
variation_is_active() : bool
Used by extensions to make incompatible variations appear greyed-out, etc. Other possible uses: prevent out-of-stock variations from being selected.
Return values
bool —variation_is_visible()
Checks if this particular variation is visible. Invisible variations are enabled and can be selected, but no price / stock info is displayed.
public
variation_is_visible() : bool
Instead, a suitable 'unavailable' message is displayed. Invisible by default: Disabled variations and variations with an empty price.
Return values
bool —after_data_store_save_or_update()
Do any extra processing needed after the actual product save (but before triggering the 'woocommerce_after_..._object_save' action)
protected
after_data_store_save_or_update(mixed $state) : mixed
Parameters
- $state : mixed
-
The state object that was returned by before_data_store_save_or_update.
Return values
mixed —before_data_store_save_or_update()
Do any extra processing needed before the actual product save (but after triggering the 'woocommerce_before_..._object_save' action)
protected
before_data_store_save_or_update() : mixed
Return values
mixed — A state value that will be passed to after_data_store_save_or_update.build_related_query()
Builds the related posts query.
protected
build_related_query( $cats_array, $tags_array, $exclude_ids, $limit) : mixed
Parameters
Tags
Return values
mixed —error()
When invalid data is found, throw an exception unless reading from the DB.
protected
error(string $code, string $message[, int $http_status_code = 400 ][, array<string|int, mixed> $data = array() ]) : mixed
Parameters
- $code : string
-
Error code.
- $message : string
-
Error message.
- $http_status_code : int = 400
-
HTTP status code.
- $data : array<string|int, mixed> = array()
-
Extra error data.
Tags
Return values
mixed —filter_null_meta()
Filter null meta values from array.
protected
filter_null_meta(mixed $meta) : bool
Parameters
- $meta : mixed
-
Meta value to check.
Tags
Return values
bool —get_availability_class()
Get availability classname based on stock status.
protected
get_availability_class() : string
Return values
string —get_availability_text()
Get availability text based on stock status.
protected
get_availability_text() : string
Return values
string —get_hook_prefix()
Prefix for action and filter hooks on data.
protected
get_hook_prefix() : string
Tags
Return values
string —get_prop()
Gets a prop for a getter method.
protected
get_prop(string $prop[, string $context = 'view' ]) : mixed
Gets the value from either current pending changes, or the data itself. Context controls what happens to the value before it's returned.
Parameters
- $prop : string
-
Name of prop to get.
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Tags
Return values
mixed —get_related_terms()
Retrieves related product terms.
protected
get_related_terms( $term) : array<string|int, mixed>
Parameters
Tags
Return values
array<string|int, mixed> —get_valid_tax_classes()
Return valid tax classes. Adds 'parent' to the default list of valid tax classes.
protected
get_valid_tax_classes() : array<string|int, mixed>
Return values
array<string|int, mixed> — valid tax classesis_internal_meta_key()
Check if the key is an internal one.
protected
is_internal_meta_key(string $key) : bool
Parameters
- $key : string
-
Key to check.
Tags
Return values
bool — true if it's an internal key, false otherwiseis_visible_core()
Returns whether or not the product is visible in the catalog (doesn't trigger filters).
protected
is_visible_core() : bool
Return values
bool —maybe_defer_product_sync()
If this is a child product, queue its parent for syncing at the end of the request.
protected
maybe_defer_product_sync() : mixed
Return values
mixed —maybe_read_meta_data()
Read meta data if null.
protected
maybe_read_meta_data() : mixed
Tags
Return values
mixed —set_date_prop()
Sets a date prop whilst handling formatting and datetime objects.
protected
set_date_prop(string $prop, string|int $value) : mixed
Parameters
- $prop : string
-
Name of prop to set.
- $value : string|int
-
Value of the prop.
Tags
Return values
mixed —set_prop()
Sets a prop for a setter method.
protected
set_prop(string $prop, mixed $value) : mixed
This stores changes in a special array so we can track what needs saving the DB later.
Parameters
- $prop : string
-
Name of prop to set.
- $value : mixed
-
Value of the prop.
Tags
Return values
mixed —build_downloads_map()
Takes an array of downloadable file representations and converts it into an array of WC_Product_Download objects, indexed by download ID.
private
build_downloads_map(array<string|int, array<string|int, mixed>>|array<string|int, WC_Product_Download> $downloads) : array<string|int, WC_Product_Download>
Parameters
- $downloads : array<string|int, array<string|int, mixed>>|array<string|int, WC_Product_Download>
-
Download data to be re-mapped.