WooCommerce Code Reference

OrderCountCache
in package

A class to cache counts for various order statuses.

Table of Contents

$expiration  : int
Default value for the duration of the objects in the cache, in seconds (may not be used depending on the cache engine used WordPress cache implementation).
$cache_prefix  : string
Cache prefix.
decrement()  : int
Decrement the cache value for a given order status.
flush()  : void
Flush the cache for a given order type and statuses.
get()  : array<string|int, int>
Get the cache value for a given order type and set of statuses.
get_default_statuses()  : array<string|int, string>
Get the default statuses.
increment()  : int
Increment the cache value for a given order status.
is_cached()  : bool
Check if the cache has a value for a given order type and status.
set()  : bool
Set the cache value for a given order type and status.
set_multiple()  : array<string|int, mixed>|array<string|int, bool>
Set the cache count value for multiple statuses at once.
ensure_statuses_for_type()  : void
Adds the given statuses to the cached statuses array for the order type if they are not already stored.
get_cache_key()  : string
Get the cache key for a given order type and status.
get_saved_statuses_cache_key()  : string
Get the cache key saved statuses of the given order type.
get_saved_statuses_for_type()  : array<string|int, string>
Retrieves the list of known statuses by order type. A cached array of statuses is saved per order type for improved backward compatibility with some of the extensions that don't register all statuses they use with WooCommerce.

Properties

$expiration

Default value for the duration of the objects in the cache, in seconds (may not be used depending on the cache engine used WordPress cache implementation).

protected int $expiration = DAY_IN_SECONDS

Methods

decrement()

Decrement the cache value for a given order status.

public decrement(string $order_type, string $order_status[, int $offset = 1 ]) : int
Parameters
$order_type : string

The type of order.

$order_status : string

The status of the order.

$offset : int = 1

The amount to decrement by.

Return values
intThe new value of the cache.

flush()

Flush the cache for a given order type and statuses.

public flush([string $order_type = 'shop_order' ][, array<string|int, string> $order_statuses = array() ]) : void
Parameters
$order_type : string = 'shop_order'

The type of order.

$order_statuses : array<string|int, string> = array()

The statuses of the order.

Return values
void

get()

Get the cache value for a given order type and set of statuses.

public get(string $order_type[, array<string|int, string> $order_statuses = array() ]) : array<string|int, int>
Parameters
$order_type : string

The type of order.

$order_statuses : array<string|int, string> = array()

The statuses of the order.

Return values
array<string|int, int>The cache value.

get_default_statuses()

Get the default statuses.

public get_default_statuses() : array<string|int, string>
Tags
deprecated
10.1.0

This method will be removed in the future.

Return values
array<string|int, string>

increment()

Increment the cache value for a given order status.

public increment(string $order_type, string $order_status[, int $offset = 1 ]) : int
Parameters
$order_type : string

The type of order.

$order_status : string

The status of the order.

$offset : int = 1

The amount to increment by.

Return values
intThe new value of the cache.

is_cached()

Check if the cache has a value for a given order type and status.

public is_cached(string $order_type, string $order_status) : bool
Parameters
$order_type : string

The type of order.

$order_status : string

The status of the order.

Return values
boolTrue if the cache has a value, false otherwise.

set()

Set the cache value for a given order type and status.

public set(string $order_type, string $order_status, int $value) : bool
Parameters
$order_type : string

The type of order.

$order_status : string

The status slug of the order.

$value : int

The value to set.

Return values
boolTrue if the value was set, false otherwise.

set_multiple()

Set the cache count value for multiple statuses at once.

public set_multiple(string $order_type, array<string|int, mixed> $counts) : array<string|int, mixed>|array<string|int, bool>
Parameters
$order_type : string

The order type being set.

$counts : array<string|int, mixed>

Normalized counts keyed by status slug (e.g. [ 'wc-processing' => 10, 'wc-pending' => 5 ]).

Return values
array<string|int, mixed>|array<string|int, bool>Success map from wp_cache_set_multiple().

ensure_statuses_for_type()

Adds the given statuses to the cached statuses array for the order type if they are not already stored.

private ensure_statuses_for_type(string $order_type, array<string|int, string> $order_statuses) : void
Parameters
$order_type : string

The order type to save with.

$order_statuses : array<string|int, string>

One or more normalised statuses to add.

Return values
void

get_cache_key()

Get the cache key for a given order type and status.

private get_cache_key(string $order_type, string $order_status) : string
Parameters
$order_type : string

The type of order.

$order_status : string

The status of the order.

Return values
stringThe cache key.

get_saved_statuses_cache_key()

Get the cache key saved statuses of the given order type.

private get_saved_statuses_cache_key(string $order_type) : string
Parameters
$order_type : string

The type of order.

Return values
stringThe cache key.

get_saved_statuses_for_type()

Retrieves the list of known statuses by order type. A cached array of statuses is saved per order type for improved backward compatibility with some of the extensions that don't register all statuses they use with WooCommerce.

private get_saved_statuses_for_type(string $order_type) : array<string|int, string>
Parameters
$order_type : string

The type of order.

Return values
array<string|int, string>