WooCommerce Code Reference

Fulfillment extends WC_Data
in package

WC Order Fulfillment Class

Tags
since
10.1.0

Table of Contents

CLONE_MODE_CACHE  = 'cache'
Clone mode constant: Cache mode preserves meta IDs.
CLONE_MODE_DUPLICATE  = 'duplicate'
Clone mode constant: Duplicate mode clears meta IDs (default, for backward compatibility).
$cache_group  : string
Stores meta in cache for future reads.
$changes  : array<string|int, mixed>
Core data changes for this object.
$clone_mode  : string
Clone mode for controlling meta ID handling during clone operations.
$data  : array<string|int, mixed>
Core data for this object. Name/value pairs.
$data_store  : object
Contains a reference to the data store for this class.
$default_data  : array<string|int, mixed>
Set to _data on construct so we can track and reset data if needed.
$extra_data  : array<string|int, mixed>
Extra data for this object. Name value pairs (name + default value).
$id  : int
ID for this object.
$legacy_datastore_props  : array<string|int, mixed>
List of properties that were earlier managed by data store. However, since DataStore is a not a stored entity in itself, they used to store data in metadata of the data object.
$meta_data  : array<string|int, WC_Meta_Data>|null
Stores additional meta data.
$object_read  : bool
This is false until the object is read from the DB.
$object_type  : string
This is the name of this object type.
$meta_snapshot  : array<string, mixed>
Snapshot of meta values taken after the object is read from the database.
__clone()  : mixed
When the object is cloned, make sure meta is cloned correctly.
__construct()  : mixed
Fulfillment constructor. Loads fulfillment data.
__sleep()  : array<string|int, mixed>
Only store the object ID to avoid serializing the data object instance.
__toString()  : string
Change data to JSON format.
__wakeup()  : mixed
Re-run the constructor with the object ID.
add_meta_data()  : mixed
Add meta data.
apply_changes()  : void
Merge changes with data, clear changes, and refresh the meta snapshot.
delete()  : bool
Delete an object, set the ID to 0, and return result.
delete_meta_data()  : mixed
Delete meta data.
delete_meta_data_by_mid()  : mixed
Delete meta data.
delete_meta_data_value()  : mixed
Delete meta data with a matching value.
generate_meta_cache_key()  : string
Generate cache key from id and group.
get_changes()  : array<string|int, mixed>
Return data changes including meta-based field changes.
get_clone_mode()  : string
Get the current clone mode.
get_data()  : array<string|int, mixed>
Returns all data for this object.
get_data_keys()  : array<string|int, mixed>
Returns array of expected data keys for this object.
get_data_store()  : object
Get the data store.
get_date_deleted()  : string|null
Get the date deleted.
get_date_fulfilled()  : string|null
Get the date the fulfillment was fulfilled.
get_date_updated()  : string|null
Get the date updated.
get_entity_id()  : string|null
Get the entity ID.
get_entity_type()  : string|null
Get the entity type.
get_extra_data_keys()  : array<string|int, mixed>
Returns all "extra" data keys for an object (for sub objects like product types).
get_id()  : int
Get the fulfillment ID.
get_is_fulfilled()  : bool
Get if the fulfillment is fulfilled.
get_item_count()  : int
Get the item count for the fulfillment.
get_items()  : array<string|int, mixed>
Get the fulfillment items.
get_lock_message()  : string
Get the lock message.
get_meta()  : mixed
Get Meta Data by Key.
get_meta_cache_key()  : string
Helper method to compute meta cache key. Different from WP Meta cache key in that meta data cached using this key also contains meta_id column.
get_meta_data()  : array<string|int, mixed>
Get All Meta Data.
get_object_read()  : bool
Get object read property.
get_order()  : WC_Order|null
Get the order associated with this fulfillment.
get_raw_data()  : array<string|int, mixed>
Returns all data for this object as an associative array.
get_raw_meta_data()  : array<string|int, mixed>
Returns the meta data as array for this object.
get_shipment_provider()  : string|null
Get the shipment provider.
get_status()  : string|null
Get the fulfillment status.
get_tracking_number()  : string|null
Get the tracking number.
get_tracking_url()  : string|null
Get the tracking URL.
init_meta_data()  : mixed
Helper function to initialize metadata entries from filtered raw meta data.
is_locked()  : bool
Check if the fulfillment is locked.
meta_exists()  : bool
See if meta data exists, since get_meta always returns a '' or array().
prime_raw_meta_data_cache()  : mixed
Prime caches for raw meta data. This includes meta_id column as well, which is not included by default in WP meta data.
read_meta_data()  : mixed
Read Meta Data from the database. Ignore any internal properties.
save()  : int
Save should create or update based on object existence.
save_meta_data()  : mixed
Update Meta Data in the database.
set_clone_mode()  : mixed
Set the clone mode.
set_date_deleted()  : void
Set the date deleted.
set_date_fulfilled()  : void
Set the date the fulfillment was fulfilled.
set_date_updated()  : void
Set the date updated.
set_defaults()  : mixed
Set all props to default values.
set_entity_id()  : void
Set the entity ID.
set_entity_type()  : void
Set the entity type.
set_id()  : void
Set the fulfillment ID.
set_items()  : void
Set the fulfillment items.
set_locked()  : void
Set the lock status and message.
set_meta_data()  : mixed
Set all meta data from array.
set_object_read()  : mixed
Set object read property.
set_props()  : bool|WP_Error
Set a collection of props in one go, collect any errors, and return the result.
set_shipment_provider()  : void
Set the shipment provider.
set_status()  : void
Set fulfillment status.
set_tracking_number()  : void
Set the tracking number.
set_tracking_url()  : void
Set the tracking URL.
snapshot_meta()  : void
Capture a snapshot of all current meta values.
update_meta_data()  : mixed
Update meta data by key or ID, if provided.
error()  : mixed
When invalid data is found, throw an exception unless reading from the DB.
filter_null_meta()  : bool
Filter null meta values from array.
get_hook_prefix()  : string
Prefix for action and filter hooks on data.
get_prop()  : mixed
Gets a prop for a getter method.
is_internal_meta_key()  : bool
Check if the key is an internal one.
maybe_read_meta_data()  : mixed
Read meta data if null.
set_date_prop()  : mixed
Sets a date prop whilst handling formatting and datetime objects.
set_prop()  : mixed
Sets a prop for a setter method.
set_is_fulfilled()  : void
Set if the fulfillment is fulfilled. This is an internal method which is bound to the fulfillment status.

Constants

CLONE_MODE_DUPLICATE

Clone mode constant: Duplicate mode clears meta IDs (default, for backward compatibility).

public mixed CLONE_MODE_DUPLICATE = 'duplicate'
Tags
since
10.4.0

Properties

$clone_mode

Clone mode for controlling meta ID handling during clone operations.

protected string $clone_mode = self::CLONE_MODE_DUPLICATE
Tags
since
10.4.0

$data

Core data for this object. Name/value pairs.

protected array<string|int, mixed> $data = array('id' => 0, 'entity_type' => null, 'entity_id' => null, 'status' => null, 'is_fulfilled' => false, 'date_updated' => null, 'date_deleted' => null)

$default_data

Set to _data on construct so we can track and reset data if needed.

protected array<string|int, mixed> $default_data = array()
Tags
since
3.0.0

$extra_data

Extra data for this object. Name value pairs (name + default value).

protected array<string|int, mixed> $extra_data = array()

Used as a standard way for sub classes (like product types) to add additional information to an inherited class.

Tags
since
3.0.0

$legacy_datastore_props

List of properties that were earlier managed by data store. However, since DataStore is a not a stored entity in itself, they used to store data in metadata of the data object.

protected array<string|int, mixed> $legacy_datastore_props = array()

With custom tables, some of these are moved from metadata to their own columns, but existing code will still try to add them to metadata. This array is used to keep track of such properties.

Only reason to add a property here is that you are moving properties from DataStore instance to data object. If you are adding a new property, consider adding it to to $data array instead.

$meta_snapshot

Snapshot of meta values taken after the object is read from the database.

private array<string, mixed> $meta_snapshot = array()

Used by get_changes() to detect meta-based field changes.

Methods

__clone()

When the object is cloned, make sure meta is cloned correctly.

public __clone() : mixed

Meta ID handling depends on the clone mode:

  • CLONE_MODE_DUPLICATE (default): Forces reading of Meta and clears meta IDs for duplication (backward compatible).
  • CLONE_MODE_CACHE: Preserves meta IDs for caching purposes.
Tags
since
3.0.2
Return values
mixed

__sleep()

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

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

__wakeup()

Re-run the constructor with the object ID.

public __wakeup() : mixed

If the object no longer exists, remove the ID.

Return values
mixed

add_meta_data()

Add meta data.

public add_meta_data(string $key, string|array<string|int, mixed> $value[, bool $unique = false ]) : mixed
Parameters
$key : string

Meta key.

$value : string|array<string|int, mixed>

Meta value.

$unique : bool = false

Should this be a unique key?.

Tags
since
2.6.0
Return values
mixed

delete()

Delete an object, set the ID to 0, and return result.

public delete([bool $force_delete = false ]) : bool
Parameters
$force_delete : bool = false

Should the date be deleted permanently.

Tags
since
2.6.0
Return values
boolresult

delete_meta_data()

Delete meta data.

public delete_meta_data(string $key) : mixed
Parameters
$key : string

Meta key.

Tags
since
2.6.0
Return values
mixed

delete_meta_data_by_mid()

Delete meta data.

public delete_meta_data_by_mid(int $mid) : mixed
Parameters
$mid : int

Meta ID.

Tags
since
2.6.0
Return values
mixed

delete_meta_data_value()

Delete meta data with a matching value.

public delete_meta_data_value(string $key, mixed $value) : mixed
Parameters
$key : string

Meta key.

$value : mixed

Meta value. Entries will only be removed that match the value.

Tags
since
7.7.0
Return values
mixed

generate_meta_cache_key()

Generate cache key from id and group.

public static generate_meta_cache_key(int|string $id, string $cache_group) : string
Parameters
$id : int|string

Object ID.

$cache_group : string

Group name use to store cache. Whole group cache can be invalidated in one go.

Tags
since
4.7.0
Return values
stringMeta cache key.

get_changes()

Return data changes including meta-based field changes.

public get_changes() : array<string|int, mixed>

Core data props are tracked by set_prop(); meta-based fields are detected by comparing current meta values against the snapshot taken on read.

Tags
since
10.7.0
Return values
array<string|int, mixed>

get_clone_mode()

Get the current clone mode.

public get_clone_mode() : string
Tags
since
10.4.0
Return values
stringThe current clone mode (one of the CLONE_MODE_* constants).

get_data()

Returns all data for this object.

public get_data() : array<string|int, mixed>
Tags
since
2.6.0
Return values
array<string|int, mixed>

get_data_keys()

Returns array of expected data keys for this object.

public get_data_keys() : array<string|int, mixed>
Tags
since
3.0.0
Return values
array<string|int, mixed>

get_extra_data_keys()

Returns all "extra" data keys for an object (for sub objects like product types).

public get_extra_data_keys() : array<string|int, mixed>
Tags
since
3.0.0
Return values
array<string|int, mixed>

get_item_count()

Get the item count for the fulfillment.

public get_item_count() : int

This method calculates the total quantity of items in the fulfillment.

Tags
since
10.7.0
Return values
intTotal quantity of items in the fulfillment.

get_meta()

Get Meta Data by Key.

public get_meta([string $key = '' ][, bool $single = true ][, string $context = 'view' ]) : mixed
Parameters
$key : string = ''

Meta Key.

$single : bool = true

return first found meta with key, or all with $key.

$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
2.6.0
Return values
mixed

get_meta_cache_key()

Helper method to compute meta cache key. Different from WP Meta cache key in that meta data cached using this key also contains meta_id column.

public get_meta_cache_key() : string
Tags
since
4.7.0
Return values
string

get_meta_data()

Get All Meta Data.

public get_meta_data() : array<string|int, mixed>
Tags
since
2.6.0
Return values
array<string|int, mixed>of objects.

get_order()

Get the order associated with this fulfillment.

public get_order() : WC_Order|null

This method retrieves the order based on the entity type and entity ID. If the entity type is WC_Order, it returns the order object.

Return values
WC_Order|nullThe order object or null if not found.

init_meta_data()

Helper function to initialize metadata entries from filtered raw meta data.

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

Filtered metadata fetched from DB.

Return values
mixed

meta_exists()

See if meta data exists, since get_meta always returns a '' or array().

public meta_exists([string $key = '' ]) : bool
Parameters
$key : string = ''

Meta Key.

Tags
since
3.0.0
Return values
bool

prime_raw_meta_data_cache()

Prime caches for raw meta data. This includes meta_id column as well, which is not included by default in WP meta data.

public static prime_raw_meta_data_cache(array<string|int, mixed> $raw_meta_data_collection, string $cache_group) : mixed
Parameters
$raw_meta_data_collection : array<string|int, mixed>

Array of objects of { object_id => array( meta_row_1, meta_row_2, ... }.

$cache_group : string

Name of cache group.

Tags
since
4.7.0
Return values
mixed

read_meta_data()

Read Meta Data from the database. Ignore any internal properties.

public read_meta_data([bool $force_read = false ]) : mixed

Uses it's own caches because get_metadata does not provide meta_ids.

Parameters
$force_read : bool = false

True to force a new DB read (and update cache).

Tags
since
2.6.0
Return values
mixed

set_clone_mode()

Set the clone mode.

public set_clone_mode(string $mode) : mixed

This controls how meta IDs are handled when the object is cloned:

  • CLONE_MODE_DUPLICATE (default): Clears meta IDs for duplication workflows
  • CLONE_MODE_CACHE: Preserves meta IDs for caching workflows
Parameters
$mode : string

One of the CLONE_MODE_* constants.

Tags
since
10.4.0
throws
InvalidArgumentException

If an invalid mode is provided.

Return values
mixed

set_date_fulfilled()

Set the date the fulfillment was fulfilled.

public set_date_fulfilled(string $date_fulfilled) : void
Parameters
$date_fulfilled : string

Date fulfilled.

Return values
void

set_entity_type()

Set the entity type.

public set_entity_type(class-string|null $entity_type) : void
Parameters
$entity_type : class-string|null

Entity type.

Return values
void

set_items()

Set the fulfillment items.

public set_items(array<string|int, mixed> $items) : void
Parameters
$items : array<string|int, mixed>

Fulfillment items.

Return values
void

set_locked()

Set the lock status and message.

public set_locked(bool $locked[, string $message = '' ]) : void
Parameters
$locked : bool

Whether the fulfillment is locked.

$message : string = ''

Optional. The lock message. Defaults to an empty string.

Return values
void

set_meta_data()

Set all meta data from array.

public set_meta_data(array<string|int, mixed> $data) : mixed
Parameters
$data : array<string|int, mixed>

Key/Value pairs.

Tags
since
2.6.0
Return values
mixed

set_object_read()

Set object read property.

public set_object_read([bool $read = true ]) : mixed
Parameters
$read : bool = true

Should read?.

Tags
since
3.0.0
Return values
mixed

set_props()

Set a collection of props in one go, collect any errors, and return the result.

public set_props(array<string|int, mixed> $props[, string $context = 'set' ]) : bool|WP_Error

Only sets using public methods.

Parameters
$props : array<string|int, mixed>

Key value pairs to set. Key is the prop and should map to a setter function name.

$context : string = 'set'

In what context to run this.

Tags
since
3.0.0
Return values
bool|WP_Error

set_shipment_provider()

Set the shipment provider.

public set_shipment_provider(string $shipment_provider) : void
Parameters
$shipment_provider : string

Shipment provider slug.

Tags
since
10.7.0
Return values
void

set_status()

Set fulfillment status.

public set_status(string|null $status) : void
Parameters
$status : string|null

Fulfillment status.

Tags
throws
InvalidArgumentException

If the status is invalid.

Return values
void

set_tracking_number()

Set the tracking number.

public set_tracking_number(string $tracking_number) : void
Parameters
$tracking_number : string

Tracking number.

Tags
since
10.7.0
Return values
void

set_tracking_url()

Set the tracking URL.

public set_tracking_url(string $tracking_url) : void
Parameters
$tracking_url : string

Tracking URL.

Tags
since
10.7.0
Return values
void

snapshot_meta()

Capture a snapshot of all current meta values.

public snapshot_meta() : void

Called by the data store after reading so that get_changes() can detect meta modifications alongside core data property changes.

Tags
since
10.7.0
Return values
void

update_meta_data()

Update meta data by key or ID, if provided.

public update_meta_data(string $key, string|array<string|int, mixed> $value, int $meta_id) : mixed
Parameters
$key : string

Meta key.

$value : string|array<string|int, mixed>

Meta value.

$meta_id : int

Meta ID.

Tags
since
2.6.0
Return values
mixed

error()

When invalid data is found, throw an exception unless reading from the DB.

protected error(string $code, string $message[, int $http_status_code = 400 ][, array<string|int, mixed> $data = array() ]) : mixed
Parameters
$code : string

Error code.

$message : string

Error message.

$http_status_code : int = 400

HTTP status code.

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

Extra error data.

Tags
throws
WC_Data_Exception

Data Exception.

since
3.0.0
Return values
mixed

filter_null_meta()

Filter null meta values from array.

protected filter_null_meta(mixed $meta) : bool
Parameters
$meta : mixed

Meta value to check.

Tags
since
3.0.0
Return values
bool

get_prop()

Gets a prop for a getter method.

protected get_prop(string $prop[, string $context = 'view' ]) : mixed

Gets the value from either current pending changes, or the data itself. Context controls what happens to the value before it's returned.

Parameters
$prop : string

Name of prop to get.

$context : string = 'view'

What the value is for. Valid values are view and edit.

Tags
since
3.0.0
Return values
mixed

is_internal_meta_key()

Check if the key is an internal one.

protected is_internal_meta_key(string $key) : bool
Parameters
$key : string

Key to check.

Tags
since
3.2.0
Return values
booltrue if it's an internal key, false otherwise

set_date_prop()

Sets a date prop whilst handling formatting and datetime objects.

protected set_date_prop(string $prop, string|int $value) : mixed
Parameters
$prop : string

Name of prop to set.

$value : string|int

Value of the prop.

Tags
since
3.0.0
Return values
mixed

set_prop()

Sets a prop for a setter method.

protected set_prop(string $prop, mixed $value) : mixed

This stores changes in a special array so we can track what needs saving the DB later.

Parameters
$prop : string

Name of prop to set.

$value : mixed

Value of the prop.

Tags
since
3.0.0
Return values
mixed

set_is_fulfilled()

Set if the fulfillment is fulfilled. This is an internal method which is bound to the fulfillment status.

private set_is_fulfilled(bool $is_fulfilled) : void
Parameters
$is_fulfilled : bool

Whether the fulfillment is fulfilled.

@return void

Return values
void