WooCommerce Code Reference

WC_Product_Data_Store_Interface

WC Product Data Store Interface

Functions that must be defined by product store classes.

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<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_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>
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_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.
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<string|int, mixed> $match_attributes = array() ]) : int
Parameters
$product : WC_Product

Variable product object.

$match_attributes : array<string|int, mixed> = 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<string|int, mixed>
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>
Return values
array<string|int, mixed>

get_products()

Returns an array of products.

public get_products([array<string|int, mixed> $args = array() ]) : array<string|int, mixed>
Parameters
$args : array<string|int, mixed> = array()

@see wc_get_products.

Return values
array<string|int, mixed>

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.

Return values
array<string|int, 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

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