WooCommerce Code Reference

WC_Product_Data_Store_Interface

Product Data Store Interface

Tags
version
3.0.0

Table of Contents

find_matching_product_variation()  : int
Find a matching (enabled) variation within a variable product.
get_ending_sales()  : array
Returns an array of IDs of products that have sales which are due to end.
get_featured_product_ids()  : array
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_on_sale_products()  : array
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
Returns an array of products.
get_related_products()  : array
Return a list of related products (using data like categories and IDs).
get_shipping_class_id_by_slug()  : int|false
Get shipping class ID by slug.
get_starting_sales()  : array
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.
sort_all_product_variations()  : mixed
Make sure all variations have a sort order set so they can be reordered correctly.
update_product_sales()  : mixed
Update a product's sale count directly.
update_product_stock()  : mixed
Update a product's stock amount directly.

Methods

find_matching_product_variation()

Find a matching (enabled) variation within a variable product.

public find_matching_product_variation(WC_Product $product[, array $match_attributes = array() ]) : int
Parameters
$product : WC_Product

Variable product object.

$match_attributes : array = array()

Array of attributes we want to try to match.

Return values
intMatching variation ID or 0.

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
Return values
array

Return a list of related products (using data like categories and IDs).

public get_related_products(array $cats_array, array $tags_array, array $exclude_ids, int $limit, int $product_id) : array
Parameters
$cats_array : array

List of categories IDs.

$tags_array : array

List of tags IDs.

$exclude_ids : array

Excluded IDs.

$limit : int

Limit of results.

$product_id : int

Product ID.

Return values
array

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

Stock quantity to use for update.

$operation : string = 'set'

Either set, increase or decrease.

Return values
mixed

update_product_stock()

Update a product's stock amount directly.

public update_product_stock(int $product_id_with_stock[, int|null $stock_quantity = null ][, string $operation = 'set' ]) : mixed

Uses queries rather than update_post_meta so we can do this in one query (to avoid stock issues).

Parameters
$product_id_with_stock : int

Product ID.

$stock_quantity : int|null = null

Stock quantity to update to.

$operation : string = 'set'

Either set, increase or decrease.

Return values
mixed