WC_Product_Variation_Data_Store_CPT
extends WC_Product_Data_Store_CPT
in package
implements
WC_Object_Data_Store_Interface
WC Variation Product Data Store: Stored in CPT.
Tags
Interfaces, Classes and Traits
- WC_Object_Data_Store_Interface
- WC Data Store Interface
Table of Contents
- $extra_data_saved : bool
- If we have already saved our extra data, don't do automatic / default handling.
- $internal_meta_keys : array<string|int, mixed>
- Data stored in meta keys, but not considered "meta" for an object.
- $meta_type : string
- Meta type. This should match up with the types available at https://developer.wordpress.org/reference/functions/add_metadata/.
- $must_exist_meta_keys : array<string|int, mixed>
- Meta data which should exist in the DB, even if empty.
- $object_id_field_for_meta : string
- This only needs set if you are using a custom metadata type (for example payment tokens.
- $updated_props : array<string|int, mixed>
- Stores updated props.
- add_meta() : int
- Add new piece of meta.
- create() : mixed
- Create a new product.
- create_all_product_variations() : int
- Creates all possible combinations of variations from the attributes, without creating duplicates.
- delete() : bool
- Method to delete a product from the database.
- delete_from_lookup_table() : mixed
- Delete lookup table data for an ID.
- delete_meta() : mixed
- Deletes meta based on meta ID.
- filter_raw_meta_data() : mixed|void
- Helper method to filter internal meta keys from all meta data rows for the object.
- find_matching_product_variation() : int
- Find a matching (enabled) variation within a variable product.
- get_ending_sales() : array<string|int, mixed>
- Returns an array of IDs of products that have sales which are due to end.
- get_featured_product_ids() : array<string|int, mixed>
- Returns a list of product IDs ( id as key => parent as value) that are featured. Uses get_posts instead of wc_get_products since we want some extra meta queries and ALL products (posts_per_page = -1).
- get_internal_meta_keys() : array<string|int, mixed>
- Return list of internal meta keys.
- get_on_sale_products() : array<string|int, mixed>
- Returns an array of on sale products, as an array of objects with an ID and parent_id present. Example: $return[0]->id, $return[0]->parent_id.
- get_product_id_by_sku() : int
- Return product ID based on SKU.
- get_product_type() : bool|string
- Get the product type based on product ID.
- get_products() : array<string|int, mixed>|object
- Returns an array of products.
- get_related_products() : array<string|int, mixed>
- Return a list of related products (using data like categories and IDs).
- get_related_products_query() : array<string|int, mixed>
- Builds the related posts query.
- get_shipping_class_id_by_slug() : int|false
- Get shipping class ID by slug.
- get_starting_sales() : array<string|int, mixed>
- Returns an array of IDs of products that have sales starting soon.
- is_existing_sku() : bool
- Check if product sku is found for any other product IDs.
- parse_date_for_wp_query() : array<string|int, mixed>
- Map a valid date query var to WP_Query arguments.
- query() : array<string|int, mixed>|object
- Query for Products matching specific criteria.
- read() : mixed
- Reads a product from the database and sets its data to the class.
- read_meta() : array<string|int, mixed>
- Returns an array of meta for an object.
- read_stock_quantity() : mixed
- Re-reads stock from the DB ignoring changes.
- reviews_allowed_query_where() : string
- Add ability to get products by 'reviews_allowed' in WC_Product_Query.
- search_products() : array<string|int, mixed>
- Search product data for a term and return ids.
- sort_all_product_variations() : mixed
- Make sure all variations have a sort order set so they can be reordered correctly.
- update() : mixed
- Updates an existing product.
- update_average_rating() : mixed
- Update a products average rating meta.
- update_meta() : mixed
- Update meta.
- update_post_meta() : mixed
- Helper method that updates all the post meta for a product based on it's settings in the WC_Product class.
- update_product_sales() : mixed
- Update a product's sale count directly.
- update_product_stock() : int|float
- Update a product's stock amount directly.
- update_rating_counts() : mixed
- Update a products rating counts.
- update_review_count() : mixed
- Update a products review count meta.
- clear_caches() : mixed
- Clear any caches.
- exclude_internal_meta_keys() : bool
- Callback to remove unwanted meta data.
- generate_attribute_summary() : string
- Generates attribute summary for the variation.
- generate_product_title() : string
- Generates a title with attribute information for a variation.
- get_data_for_lookup_table() : array<string|int, mixed>
- Get data to save to a lookup table.
- get_db_info() : array<string|int, mixed>
- Table structure is slightly different between meta types, this function will return what we need to know.
- get_primary_key_for_lookup_table() : string
- Get primary key name for lookup table.
- get_props_to_update() : array<string|int, mixed>
- Gets a list of props and meta keys that need updated based on change state or if they are present in the database or not.
- get_search_stopwords() : array<string|int, mixed>
- Retrieve stopwords used when parsing search terms.
- get_term_ids() : array<string|int, mixed>
- Get and store terms from a taxonomy.
- get_valid_search_terms() : array<string|int, mixed>
- Check if the terms are suitable for searching.
- get_wp_query_args() : array<string|int, mixed>
- Get valid WP_Query args from a WC_Object_Query's query variables.
- handle_updated_props() : mixed
- Handle updated meta props after updating meta data.
- prefix_key() : string
- Internal meta keys we don't want exposed as part of meta_data. This is in addition to all data props with _ prefix.
- read_attributes() : mixed
- Read attributes from post meta.
- read_downloads() : mixed
- Read downloads from post meta.
- read_extra_data() : mixed
- Read extra data associated with the product, like button text or product URL for external products.
- read_product_data() : mixed
- Read post data.
- read_visibility() : mixed
- Convert visibility terms to props.
- set_product_stock() : mixed
- Update a product's stock amount directly in the database.
- string_to_timestamp() : int|null
- Converts a WP post date string into a timestamp.
- update_attributes() : mixed
- Update attribute meta values.
- update_downloads() : bool
- Update downloads.
- update_guid() : mixed
- Update product variation guid.
- update_lookup_table() : null
- Update a lookup table for an object.
- update_or_delete_post_meta() : bool
- Update meta data in, or delete it from, the database.
- update_terms() : mixed
- For all stored terms in all taxonomies, save them to the DB.
- update_version_and_type() : mixed
- Make sure we store the product version (to track data changes).
- update_visibility() : mixed
- Update visibility terms based on props.
Properties
$extra_data_saved
If we have already saved our extra data, don't do automatic / default handling.
protected
bool
$extra_data_saved
= alse
$internal_meta_keys
Data stored in meta keys, but not considered "meta" for an object.
protected
array<string|int, mixed>
$internal_meta_keys
= array()
Tags
$meta_type
Meta type. This should match up with the types available at https://developer.wordpress.org/reference/functions/add_metadata/.
protected
string
$meta_type
= 'post'
WP defines 'post', 'user', 'comment', and 'term'.
$must_exist_meta_keys
Meta data which should exist in the DB, even if empty.
protected
array<string|int, mixed>
$must_exist_meta_keys
= array()
Tags
$object_id_field_for_meta
This only needs set if you are using a custom metadata type (for example payment tokens.
protected
string
$object_id_field_for_meta
= ''
This should be the name of the field your table uses for associating meta with objects. For example, in payment_tokenmeta, this would be payment_token_id.
$updated_props
Stores updated props.
protected
array<string|int, mixed>
$updated_props
= array()
Methods
add_meta()
Add new piece of meta.
public
add_meta(WC_Data &$object, stdClass $meta) : int
Parameters
- $object : WC_Data
-
WC_Data object.
- $meta : stdClass
-
(containing ->key and ->value).
Tags
Return values
int — meta IDcreate()
Create a new product.
public
create(WC_Product_Variation &$product) : mixed
Parameters
- $product : WC_Product_Variation
-
Product object.
Tags
Return values
mixed —create_all_product_variations()
Creates all possible combinations of variations from the attributes, without creating duplicates.
public
create_all_product_variations(WC_Product $product[, int $limit = -1 ][, array<string|int, mixed> $default_values = array() ][, array<string|int, mixed> $metadata = array() ]) : int
Parameters
- $product : WC_Product
-
Variable product.
- $limit : int = -1
-
Limit the number of created variations.
- $default_values : array<string|int, mixed> = array()
-
Key value pairs to set on created variations.
- $metadata : array<string|int, mixed> = array()
-
Key value pairs to set as meta data on created variations.
Tags
Return values
int — Number of created variations.delete()
Method to delete a product from the database.
public
delete(WC_Product &$product[, array<string|int, mixed> $args = array() ]) : bool
Parameters
- $product : WC_Product
-
Product object.
- $args : array<string|int, mixed> = array()
-
Array of args to pass to the delete method.
Return values
bool — resultdelete_from_lookup_table()
Delete lookup table data for an ID.
public
delete_from_lookup_table(int $id, string $table) : mixed
Parameters
- $id : int
-
ID of object to update.
- $table : string
-
Lookup table name.
Tags
Return values
mixed —delete_meta()
Deletes meta based on meta ID.
public
delete_meta(WC_Data &$object, stdClass $meta) : mixed
Parameters
- $object : WC_Data
-
WC_Data object.
- $meta : stdClass
-
(containing at least ->id).
Tags
Return values
mixed —filter_raw_meta_data()
Helper method to filter internal meta keys from all meta data rows for the object.
public
filter_raw_meta_data(WC_Data &$object, array<string|int, mixed> $raw_meta_data) : mixed|void
Parameters
- $object : WC_Data
-
WC_Data object.
- $raw_meta_data : array<string|int, mixed>
-
Array of std object of meta data to be filtered.
Tags
Return values
mixed|void —find_matching_product_variation()
Find a matching (enabled) variation within a variable product.
public
find_matching_product_variation(WC_Product $product[, array<string|int, mixed> $match_attributes = array() ]) : int
Parameters
- $product : WC_Product
-
Variable product.
- $match_attributes : array<string|int, mixed> = array()
-
Array of attributes we want to try to match.
Tags
Return values
int — Matching variation ID or 0.get_ending_sales()
Returns an array of IDs of products that have sales which are due to end.
public
get_ending_sales() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_featured_product_ids()
Returns a list of product IDs ( id as key => parent as value) that are featured. Uses get_posts instead of wc_get_products since we want some extra meta queries and ALL products (posts_per_page = -1).
public
get_featured_product_ids() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_internal_meta_keys()
Return list of internal meta keys.
public
get_internal_meta_keys() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_on_sale_products()
Returns an array of on sale products, as an array of objects with an ID and parent_id present. Example: $return[0]->id, $return[0]->parent_id.
public
get_on_sale_products() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_product_id_by_sku()
Return product ID based on SKU.
public
get_product_id_by_sku(string $sku) : int
Parameters
- $sku : string
-
Product SKU.
Tags
Return values
int —get_product_type()
Get the product type based on product ID.
public
get_product_type(int $product_id) : bool|string
Parameters
- $product_id : int
-
Product ID.
Tags
Return values
bool|string —get_products()
Returns an array of products.
public
get_products([array<string|int, mixed> $args = array() ]) : array<string|int, mixed>|object
Parameters
- $args : array<string|int, mixed> = array()
-
Args to pass to WC_Product_Query().
Tags
Return values
array<string|int, mixed>|object —get_related_products()
Return a list of related products (using data like categories and IDs).
public
get_related_products(array<string|int, mixed> $cats_array, array<string|int, mixed> $tags_array, array<string|int, mixed> $exclude_ids, int $limit, int $product_id) : array<string|int, mixed>
Parameters
- $cats_array : array<string|int, mixed>
-
List of categories IDs.
- $tags_array : array<string|int, mixed>
-
List of tags IDs.
- $exclude_ids : array<string|int, mixed>
-
Excluded IDs.
- $limit : int
-
Limit of results.
- $product_id : int
-
Product ID.
Tags
Return values
array<string|int, mixed> —get_related_products_query()
Builds the related posts query.
public
get_related_products_query(array<string|int, mixed> $cats_array, array<string|int, mixed> $tags_array, array<string|int, mixed> $exclude_ids, int $limit) : array<string|int, mixed>
Parameters
- $cats_array : array<string|int, mixed>
-
List of categories IDs.
- $tags_array : array<string|int, mixed>
-
List of tags IDs.
- $exclude_ids : array<string|int, mixed>
-
Excluded IDs.
- $limit : int
-
Limit of results.
Tags
Return values
array<string|int, mixed> —get_shipping_class_id_by_slug()
Get shipping class ID by slug.
public
get_shipping_class_id_by_slug(string $slug) : int|false
Parameters
- $slug : string
-
Product shipping class slug.
Tags
Return values
int|false —get_starting_sales()
Returns an array of IDs of products that have sales starting soon.
public
get_starting_sales() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —is_existing_sku()
Check if product sku is found for any other product IDs.
public
is_existing_sku(int $product_id, string $sku) : bool
Parameters
- $product_id : int
-
Product ID.
- $sku : string
-
Will be slashed to work around https://core.trac.wordpress.org/ticket/27421.
Tags
Return values
bool —parse_date_for_wp_query()
Map a valid date query var to WP_Query arguments.
public
parse_date_for_wp_query(mixed $query_var, string $key[, array<string|int, mixed> $wp_query_args = array() ]) : array<string|int, mixed>
Valid date formats: YYYY-MM-DD or timestamp, possibly combined with an operator from $valid_operators. Also accepts a WC_DateTime object.
Parameters
- $query_var : mixed
-
A valid date format.
- $key : string
-
meta or db column key.
- $wp_query_args : array<string|int, mixed> = array()
-
WP_Query args.
Tags
Return values
array<string|int, mixed> — Modified $wp_query_argsquery()
Query for Products matching specific criteria.
public
query(array<string|int, mixed> $query_vars) : array<string|int, mixed>|object
Parameters
- $query_vars : array<string|int, mixed>
-
Query vars from a WC_Product_Query.
Tags
Return values
array<string|int, mixed>|object —read()
Reads a product from the database and sets its data to the class.
public
read(WC_Product_Variation &$product) : mixed
Parameters
- $product : WC_Product_Variation
-
Product object.
Tags
Return values
mixed —read_meta()
Returns an array of meta for an object.
public
read_meta(WC_Data &$object) : array<string|int, mixed>
Parameters
- $object : WC_Data
-
WC_Data object.
Tags
Return values
array<string|int, mixed> —read_stock_quantity()
Re-reads stock from the DB ignoring changes.
public
read_stock_quantity(WC_Product &$product[, int|float $new_stock = null ]) : mixed
Parameters
- $product : WC_Product
-
Product object.
- $new_stock : int|float = null
-
New stock level if already read.
Return values
mixed —reviews_allowed_query_where()
Add ability to get products by 'reviews_allowed' in WC_Product_Query.
public
reviews_allowed_query_where(string $where, WP_Query $wp_query) : string
Parameters
- $where : string
-
Where clause.
- $wp_query : WP_Query
-
WP_Query instance.
Tags
Return values
string —search_products()
Search product data for a term and return ids.
public
search_products(string $term[, string $type = '' ][, bool $include_variations = false ][, bool $all_statuses = false ][, null|int $limit = null ][, null|array<string|int, mixed> $include = null ][, null|array<string|int, mixed> $exclude = null ]) : array<string|int, mixed>
Parameters
- $term : string
-
Search term.
- $type : string = ''
-
Type of product.
- $include_variations : bool = false
-
Include variations in search or not.
- $all_statuses : bool = false
-
Should we search all statuses or limit to published.
- $limit : null|int = null
-
Limit returned results. @since 3.5.0.
- $include : null|array<string|int, mixed> = null
-
Keep specific results. @since 3.6.0.
- $exclude : null|array<string|int, mixed> = null
-
Discard specific results. @since 3.6.0.
Return values
array<string|int, mixed> — of idssort_all_product_variations()
Make sure all variations have a sort order set so they can be reordered correctly.
public
sort_all_product_variations(int $parent_id) : mixed
Parameters
- $parent_id : int
-
Product ID.
Return values
mixed —update()
Updates an existing product.
public
update(WC_Product_Variation &$product) : mixed
Parameters
- $product : WC_Product_Variation
-
Product object.
Tags
Return values
mixed —update_average_rating()
Update a products average rating meta.
public
update_average_rating(WC_Product $product) : mixed
Parameters
- $product : WC_Product
-
Product object.
Tags
Return values
mixed —update_meta()
Update meta.
public
update_meta(WC_Data &$object, stdClass $meta) : mixed
Parameters
- $object : WC_Data
-
WC_Data object.
- $meta : stdClass
-
(containing ->id, ->key and ->value).
Tags
Return values
mixed —update_post_meta()
Helper method that updates all the post meta for a product based on it's settings in the WC_Product class.
public
update_post_meta(WC_Product &$product[, bool $force = false ]) : mixed
Parameters
- $product : WC_Product
-
Product object.
- $force : bool = false
-
Force update. Used during create.
Tags
Return values
mixed —update_product_sales()
Update a product's sale count directly.
public
update_product_sales(int $product_id[, int|null $quantity = null ][, string $operation = 'set' ]) : mixed
Uses queries rather than update_post_meta so we can do this in one query for performance.
Parameters
- $product_id : int
-
Product ID.
- $quantity : int|null = null
-
Quantity.
- $operation : string = 'set'
-
set, increase and decrease.
Tags
Return values
mixed —update_product_stock()
Update a product's stock amount directly.
public
update_product_stock(int $product_id_with_stock[, int|float|null $stock_quantity = null ][, string $operation = 'set' ]) : int|float
Uses queries rather than update_post_meta so we can do this in one query (to avoid stock issues). Ignores manage stock setting on the product and sets quantities directly in the db: post meta and lookup tables. Uses locking to update the quantity. If the lock is not acquired, change is lost.
Parameters
- $product_id_with_stock : int
-
Product ID.
- $stock_quantity : int|float|null = null
-
Stock quantity.
- $operation : string = 'set'
-
Set, increase and decrease.
Tags
Return values
int|float — New stock level.update_rating_counts()
Update a products rating counts.
public
update_rating_counts(WC_Product $product) : mixed
Parameters
- $product : WC_Product
-
Product object.
Tags
Return values
mixed —update_review_count()
Update a products review count meta.
public
update_review_count(WC_Product $product) : mixed
Parameters
- $product : WC_Product
-
Product object.
Tags
Return values
mixed —clear_caches()
Clear any caches.
protected
clear_caches(WC_Product &$product) : mixed
Parameters
- $product : WC_Product
-
Product object.
Tags
Return values
mixed —exclude_internal_meta_keys()
Callback to remove unwanted meta data.
protected
exclude_internal_meta_keys(object $meta) : bool
Parameters
- $meta : object
-
Meta object.
Return values
bool — false if excluded.generate_attribute_summary()
Generates attribute summary for the variation.
protected
generate_attribute_summary(WC_Product_Variation $product) : string
Attribute summary contains comma-delimited 'attribute_name: attribute_value' pairs for all attributes.
Parameters
- $product : WC_Product_Variation
-
Product variation to generate the attribute summary for.
Tags
Return values
string —generate_product_title()
Generates a title with attribute information for a variation.
protected
generate_product_title(WC_Product $product) : string
Products will get a title of the form "Name - Value, Value" or just "Name".
Parameters
- $product : WC_Product
-
Product object.
Tags
Return values
string —get_data_for_lookup_table()
Get data to save to a lookup table.
protected
get_data_for_lookup_table(int $id, string $table) : array<string|int, mixed>
Parameters
- $id : int
-
ID of object to update.
- $table : string
-
Lookup table name.
Tags
Return values
array<string|int, mixed> —get_db_info()
Table structure is slightly different between meta types, this function will return what we need to know.
protected
get_db_info() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> — Array elements: table, object_id_field, meta_id_fieldget_primary_key_for_lookup_table()
Get primary key name for lookup table.
protected
get_primary_key_for_lookup_table(string $table) : string
Parameters
- $table : string
-
Lookup table name.
Tags
Return values
string —get_props_to_update()
Gets a list of props and meta keys that need updated based on change state or if they are present in the database or not.
protected
get_props_to_update(WC_Data $object, array<string|int, mixed> $meta_key_to_props[, string $meta_type = 'post' ]) : array<string|int, mixed>
Parameters
- $object : WC_Data
-
The WP_Data object (WC_Coupon for coupons, etc).
- $meta_key_to_props : array<string|int, mixed>
-
A mapping of meta keys => prop names.
- $meta_type : string = 'post'
-
The internal WP meta type (post, user, etc).
Return values
array<string|int, mixed> — A mapping of meta keys => prop names, filtered by ones that should be updated.get_search_stopwords()
Retrieve stopwords used when parsing search terms.
protected
get_search_stopwords() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> — Stopwords.get_term_ids()
Get and store terms from a taxonomy.
protected
get_term_ids(WC_Data|int $object, string $taxonomy) : array<string|int, mixed>
Parameters
- $object : WC_Data|int
-
WC_Data object or object ID.
- $taxonomy : string
-
Taxonomy name e.g. product_cat.
Tags
Return values
array<string|int, mixed> — of termsget_valid_search_terms()
Check if the terms are suitable for searching.
protected
get_valid_search_terms(array<string|int, mixed> $terms) : array<string|int, mixed>
Uses an array of stopwords (terms) that are excluded from the separate term matching when searching for posts. The list of English stopwords is the approximate search engines list, and is translatable.
Parameters
- $terms : array<string|int, mixed>
-
Terms to check.
Tags
Return values
array<string|int, mixed> — Terms that are not stopwords.get_wp_query_args()
Get valid WP_Query args from a WC_Object_Query's query variables.
protected
get_wp_query_args(array<string|int, mixed> $query_vars) : array<string|int, mixed>
Parameters
- $query_vars : array<string|int, mixed>
-
query vars from a WC_Object_Query.
Tags
Return values
array<string|int, mixed> —handle_updated_props()
Handle updated meta props after updating meta data.
protected
handle_updated_props(WC_Product &$product) : mixed
Parameters
- $product : WC_Product
-
Product Object.
Tags
Return values
mixed —prefix_key()
Internal meta keys we don't want exposed as part of meta_data. This is in addition to all data props with _ prefix.
protected
prefix_key(string $key) : string
Parameters
- $key : string
-
Prefix to be added to meta keys.
Tags
Return values
string —read_attributes()
Read attributes from post meta.
protected
read_attributes(WC_Product &$product) : mixed
Parameters
- $product : WC_Product
-
Product object.
Return values
mixed —read_downloads()
Read downloads from post meta.
protected
read_downloads(WC_Product &$product) : mixed
Parameters
- $product : WC_Product
-
Product object.
Tags
Return values
mixed —read_extra_data()
Read extra data associated with the product, like button text or product URL for external products.
protected
read_extra_data(WC_Product &$product) : mixed
Parameters
- $product : WC_Product
-
Product object.
Tags
Return values
mixed —read_product_data()
Read post data.
protected
read_product_data(WC_Product_Variation &$product) : mixed
Parameters
- $product : WC_Product_Variation
-
Product object.
Tags
Return values
mixed —read_visibility()
Convert visibility terms to props.
protected
read_visibility(WC_Product &$product) : mixed
Catalog visibility valid values are 'visible', 'catalog', 'search', and 'hidden'.
Parameters
- $product : WC_Product
-
Product object.
Tags
Return values
mixed —set_product_stock()
Update a product's stock amount directly in the database.
protected
set_product_stock(int $product_id_with_stock, int|float|null $stock_quantity) : mixed
Updates both post meta and lookup tables. Ignores manage stock setting on the product.
Parameters
- $product_id_with_stock : int
-
Product ID.
- $stock_quantity : int|float|null
-
Stock quantity.
Return values
mixed —string_to_timestamp()
Converts a WP post date string into a timestamp.
protected
string_to_timestamp(string $time_string) : int|null
Parameters
- $time_string : string
-
The WP post date string.
Tags
Return values
int|null — The date string converted to a timestamp or null.update_attributes()
Update attribute meta values.
protected
update_attributes(WC_Product &$product[, bool $force = false ]) : mixed
Parameters
- $product : WC_Product
-
Product object.
- $force : bool = false
-
Force update. Used during create.
Tags
Return values
mixed —update_downloads()
Update downloads.
protected
update_downloads(WC_Product &$product[, bool $force = false ]) : bool
Parameters
- $product : WC_Product
-
Product object.
- $force : bool = false
-
Force update. Used during create.
Tags
Return values
bool — If updated or not.update_guid()
Update product variation guid.
protected
update_guid(WC_Product_Variation $product) : mixed
Parameters
- $product : WC_Product_Variation
-
Product variation object.
Tags
Return values
mixed —update_lookup_table()
Update a lookup table for an object.
protected
update_lookup_table(int $id, string $table) : null
Parameters
- $id : int
-
ID of object to update.
- $table : string
-
Lookup table name.
Tags
Return values
null —update_or_delete_post_meta()
Update meta data in, or delete it from, the database.
protected
update_or_delete_post_meta(WC_Data $object, string $meta_key, mixed $meta_value) : bool
Avoids storing meta when it's either an empty string or empty array.
Other empty values such as numeric 0 and null should still be stored.
Data-stores can force meta to exist using must_exist_meta_keys
.
Note: WordPress get_metadata
function returns an empty string when meta data does not exist.
Parameters
- $object : WC_Data
-
The WP_Data object (WC_Coupon for coupons, etc).
- $meta_key : string
-
Meta key to update.
- $meta_value : mixed
-
Value to save.
Tags
Return values
bool — True if updated/deleted.update_terms()
For all stored terms in all taxonomies, save them to the DB.
protected
update_terms(WC_Product &$product[, bool $force = false ]) : mixed
Parameters
- $product : WC_Product
-
Product object.
- $force : bool = false
-
Force update. Used during create.
Tags
Return values
mixed —update_version_and_type()
Make sure we store the product version (to track data changes).
protected
update_version_and_type(WC_Product &$product) : mixed
Parameters
- $product : WC_Product
-
Product object.
Tags
Return values
mixed —update_visibility()
Update visibility terms based on props.
protected
update_visibility(WC_Product &$product[, bool $force = false ]) : mixed
Parameters
- $product : WC_Product
-
Product object.
- $force : bool = false
-
Force update. Used during create.