WooCommerce Code Reference

WC_Data_Store
in package

Data store class.

Table of Contents

$current_class_name  : string
Contains the name of the current data store's class name.
$instance  : WC_Data_Store
Contains an instance of the data store class that we are working with.
$object_type  : string
The object type this store works with.
$stores  : array<string|int, mixed>
Contains an array of default WC supported data stores.
__call()  : mixed
Data stores can define additional functions (for example, coupons have some helper methods for increasing or decreasing usage). This passes through to the instance if that function exists.
__construct()  : mixed
Tells WC_Data_Store which object (coupon, product, order, etc) store we want to work with.
__sleep()  : array<string|int, mixed>
Only store the object type to avoid serializing the data store instance.
__wakeup()  : mixed
Re-run the constructor with the object type.
create()  : mixed
Create an object in the data store.
delete()  : mixed
Delete an object from the data store.
get_current_class_name()  : string
Returns the class name of the current data store.
has_callable()  : bool
Check if the data store we are working with has a callable method.
load()  : WC_Data_Store
Loads a data store.
read()  : mixed
Reads an object from the data store.
read_multiple()  : mixed
Reads multiple objects from the data store.
update()  : mixed
Update an object in the data store.

Properties

$stores

Contains an array of default WC supported data stores.

private array<string|int, mixed> $stores = array('coupon' => 'WC_Coupon_Data_Store_CPT', 'customer' => 'WC_Customer_Data_Store', 'customer-download' => 'WC_Customer_Download_Data_Store', 'customer-download-log' => 'WC_Customer_Download_Log_Data_Store', 'customer-session' => 'WC_Customer_Data_Store_Session', 'order' => 'WC_Order_Data_Store_CPT', 'order-refund' => 'WC_Order_Refund_Data_Store_CPT', 'order-item' => 'WC_Order_Item_Data_Store', 'order-item-coupon' => 'WC_Order_Item_Coupon_Data_Store', 'order-item-fee' => 'WC_Order_Item_Fee_Data_Store', 'order-item-product' => 'WC_Order_Item_Product_Data_Store', 'order-item-shipping' => 'WC_Order_Item_Shipping_Data_Store', 'order-item-tax' => 'WC_Order_Item_Tax_Data_Store', 'payment-token' => 'WC_Payment_Token_Data_Store', 'product' => 'WC_Product_Data_Store_CPT', 'product-grouped' => 'WC_Product_Grouped_Data_Store_CPT', 'product-variable' => 'WC_Product_Variable_Data_Store_CPT', 'product-variation' => 'WC_Product_Variation_Data_Store_CPT', 'shipping-zone' => 'WC_Shipping_Zone_Data_Store', 'webhook' => 'WC_Webhook_Data_Store')

Format of object name => class name. Example: 'product' => 'WC_Product_Data_Store_CPT' You can also pass something like product_ for product stores and that type will be used first when available, if a store is requested like this and doesn't exist, then the store would fall back to 'product'. Ran through woocommerce_data_stores.

Methods

__call()

Data stores can define additional functions (for example, coupons have some helper methods for increasing or decreasing usage). This passes through to the instance if that function exists.

public __call(string $method, mixed $parameters) : mixed
Parameters
$method : string

Method.

$parameters : mixed

Parameters.

Tags
since
3.0.0
Return values
mixed

__construct()

Tells WC_Data_Store which object (coupon, product, order, etc) store we want to work with.

public __construct(string $object_type) : mixed
Parameters
$object_type : string

Name of object.

Tags
throws
Exception

When validation fails.

Return values
mixed

__sleep()

Only store the object type to avoid serializing the data store instance.

public __sleep() : array<string|int, mixed>
Return values
array<string|int, mixed>

__wakeup()

Re-run the constructor with the object type.

public __wakeup() : mixed
Tags
throws
Exception

When validation fails.

Return values
mixed

delete()

Delete an object from the data store.

public delete(WC_Data &$data[, array<string|int, mixed> $args = array() ]) : mixed
Parameters
$data : WC_Data

WooCommerce data instance.

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

Array of args to pass to the delete method.

Tags
since
3.0.0
Return values
mixed

get_current_class_name()

Returns the class name of the current data store.

public get_current_class_name() : string
Tags
since
3.0.0
Return values
string

has_callable()

Check if the data store we are working with has a callable method.

public has_callable(string $method) : bool
Parameters
$method : string

Method name.

Return values
boolWhether the passed method is callable.

read_multiple()

Reads multiple objects from the data store.

public read_multiple([mixed &$objects = array() ]) : mixed
Parameters
$objects : mixed = array()

Array of object instances to read.

Tags
since
6.9.0
Return values
mixed