MetaDataUtil
in package
Utility methods for handling order item meta data.
Tags
Table of Contents
- maybe_unserialize_no_classes() : mixed
- Unserialize a meta value, if it is serialized, without instantiating any object it may contain.
- normalize() : array<string|int, array<string|int, mixed>>
- Normalize an array of raw meta data entries from a REST API request.
- update() : void
- Normalize and process meta data entries from a REST API request.
Methods
maybe_unserialize_no_classes()
Unserialize a meta value, if it is serialized, without instantiating any object it may contain.
public
static maybe_unserialize_no_classes(mixed $value) : mixed
Parameters
- $value : mixed
-
Raw meta value, maybe serialized.
Tags
Return values
mixed — Unserialized value.normalize()
Normalize an array of raw meta data entries from a REST API request.
public
static normalize(array<string|int, mixed> $meta_data[, mixed $default_id = '' ]) : array<string|int, array<string|int, mixed>>
Filters out entries without a key and applies default values for missing 'value' and 'id' fields. Each returned entry is guaranteed to have 'key', 'value', and 'id' set.
Parameters
- $meta_data : array<string|int, mixed>
-
Raw meta data array from the request.
- $default_id : mixed = ''
-
Default value for 'id' when not provided (default '').
Tags
Return values
array<string|int, array<string|int, mixed>> — Normalized meta data entries.update()
Normalize and process meta data entries from a REST API request.
public
static update(mixed $meta_data, WC_Data $target[, mixed $default_id = '' ]) : void
Skips entries without a key, applies defaults for missing 'value' and 'id' fields, then calls update_meta_data on the given WC_Data object for each valid entry.
Parameters
- $meta_data : mixed
-
Raw meta data from the request (non-array values are ignored).
- $target : WC_Data
-
A WC_Data object to call update_meta_data on.
- $default_id : mixed = ''
-
Default value for 'id' when not provided (default '').
