WC_Order_Item_Tax
extends WC_Order_Item
in package
Order item tax.
Table of Contents
- $cache_group : string
- Stores meta in cache for future reads.
- $changes : array<string|int, mixed>
- Core data changes for this object.
- $data : array<string|int, mixed>
- Core data for this object. Name value pairs (name + default value).
- $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>
- Order Data array. This is the core order data exposed in APIs since 3.0.0.
- $id : int
- ID for this object.
- $meta_data : array<string|int, mixed>
- Stores additional meta data.
- $meta_type : string
- Meta type. This should match up with the types available at https://developer.wordpress.org/reference/functions/add_metadata/.
- $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.
- __clone() : mixed
- When the object is cloned, make sure meta is duplicated correctly.
- __construct() : mixed
- Default constructor.
- __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() : mixed
- Merge changes with data and clear.
- calculate_taxes() : bool
- Calculate item taxes.
- 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.
- generate_meta_cache_key() : string
- Generate cache key from id and group.
- get_all_formatted_meta_data() : array<string|int, mixed>
- Wrapper for get_formatted_meta_data that includes all metadata by default. See https://github.com/woocommerce/woocommerce/pull/30948
- get_changes() : array<string|int, mixed>
- Return data changes only.
- get_compound() : bool
- Get compound.
- 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_extra_data_keys() : array<string|int, mixed>
- Returns all "extra" data keys for an object (for sub objects like product types).
- get_formatted_meta_data() : array<string|int, mixed>
- Expands things like term slugs before return.
- get_id() : int
- Returns the unique ID for this object.
- get_label() : string
- Get label.
- 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_name() : string
- Get rate code/name.
- get_object_read() : bool
- Get object read property.
- get_order() : WC_Order
- Get parent order object.
- get_order_id() : int
- Get order ID this meta belongs to.
- get_quantity() : int
- Get quantity.
- get_rate_code() : string
- Get rate code/name.
- get_rate_id() : int
- Get tax rate ID.
- get_rate_percent() : float
- Get rate value
- get_shipping_tax_total() : string
- Get shipping_tax_total
- get_tax_class() : string
- Get tax class.
- get_tax_status() : string
- Get tax status.
- get_tax_total() : string
- Get tax_total
- get_type() : string
- Get order item type.
- is_compound() : bool
- Is this a compound tax rate?
- is_type() : bool
- Type checking.
- meta_exists() : bool
- See if meta data exists, since get_meta always returns a '' or array().
- offsetExists() : bool
- OffsetExists for ArrayAccess.
- offsetGet() : mixed
- O for ArrayAccess/Backwards compatibility.
- offsetSet() : mixed
- OffsetSet for ArrayAccess/Backwards compatibility.
- offsetUnset() : mixed
- OffsetUnset for ArrayAccess.
- 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_compound() : mixed
- Set compound.
- set_defaults() : mixed
- Set all props to default values.
- set_id() : mixed
- Set ID.
- set_label() : mixed
- Set item name.
- set_meta_data() : mixed
- Set all meta data from array.
- set_name() : mixed
- Set order item name.
- set_object_read() : mixed
- Set object read property.
- set_order_id() : mixed
- Set order ID.
- set_props() : bool|WP_Error
- Set a collection of props in one go, collect any errors, and return the result.
- set_rate() : mixed
- Set properties based on passed in tax rate by ID.
- set_rate_code() : mixed
- Set item name.
- set_rate_id() : mixed
- Set tax rate id.
- set_rate_percent() : mixed
- Set rate value.
- set_shipping_tax_total() : mixed
- Set shipping tax total.
- set_tax_total() : mixed
- Set tax total.
- 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.
Properties
$cache_group
Stores meta in cache for future reads.
protected
string
$cache_group
= ''
A group must be set to to enable caching.
Tags
$changes
Core data changes for this object.
protected
array<string|int, mixed>
$changes
= array()
Tags
$data
Core data for this object. Name value pairs (name + default value).
protected
array<string|int, mixed>
$data
= array()
Tags
$data_store
Contains a reference to the data store for this class.
protected
object
$data_store
Tags
$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
$extra_data
Order Data array. This is the core order data exposed in APIs since 3.0.0.
protected
array<string|int, mixed>
$extra_data
= array('rate_code' => '', 'rate_id' => 0, 'label' => '', 'compound' => alse, 'tax_total' => 0, 'shipping_tax_total' => 0, 'rate_percent' =>
ull)
Tags
$id
ID for this object.
protected
int
$id
= 0
Tags
$meta_data
Stores additional meta data.
protected
array<string|int, mixed>
$meta_data
=
ull
Tags
$meta_type
Meta type. This should match up with the types available at https://developer.wordpress.org/reference/functions/add_metadata/.
protected
string
$meta_type
= 'order_item'
WP defines 'post', 'user', 'comment', and 'term'.
$object_read
This is false until the object is read from the DB.
protected
bool
$object_read
= alse
Tags
$object_type
This is the name of this object type.
protected
string
$object_type
= 'data'
Tags
Methods
__clone()
When the object is cloned, make sure meta is duplicated correctly.
public
__clone() : mixed
Tags
Return values
mixed —__construct()
Default constructor.
public
__construct(int|object|array<string|int, mixed> $read) : mixed
Parameters
- $read : int|object|array<string|int, mixed>
-
ID to load from the DB (optional) or already queried data.
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> —__toString()
Change data to JSON format.
public
__toString() : string
Tags
Return values
string — Data in JSON format.__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
Return values
mixed —apply_changes()
Merge changes with data and clear.
public
apply_changes() : mixed
Tags
Return values
mixed —calculate_taxes()
Calculate item taxes.
public
calculate_taxes([array<string|int, mixed> $calculate_tax_for = array() ]) : bool
Parameters
- $calculate_tax_for : array<string|int, mixed> = array()
-
Location data to get taxes for. Required.
Tags
Return values
bool — True if taxes were calculated.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
Return values
bool — resultdelete_meta_data()
Delete meta data.
public
delete_meta_data(string $key) : mixed
Parameters
- $key : string
-
Meta key.
Tags
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
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
Return values
string — Meta cache key.get_all_formatted_meta_data()
Wrapper for get_formatted_meta_data that includes all metadata by default. See https://github.com/woocommerce/woocommerce/pull/30948
public
get_all_formatted_meta_data([string $hideprefix = '_' ][, bool $include_all = true ]) : array<string|int, mixed>
Parameters
- $hideprefix : string = '_'
-
Meta data prefix, (default: _).
- $include_all : bool = true
-
Include all meta data, this stop skip items with values already in the product name.
Return values
array<string|int, mixed> —get_changes()
Return data changes only.
public
get_changes() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_compound()
Get compound.
public
get_compound([string $context = 'view' ]) : bool
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
bool —get_data()
Returns all data for this object.
public
get_data() : array<string|int, mixed>
Tags
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
Return values
array<string|int, mixed> —get_data_store()
Get the data store.
public
get_data_store() : object
Tags
Return values
object —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
Return values
array<string|int, mixed> —get_formatted_meta_data()
Expands things like term slugs before return.
public
get_formatted_meta_data([string $hideprefix = '_' ][, bool $include_all = false ]) : array<string|int, mixed>
Parameters
- $hideprefix : string = '_'
-
Meta data prefix, (default: _).
- $include_all : bool = false
-
Include all meta data, this stop skip items with values already in the product name.
Return values
array<string|int, mixed> —get_id()
Returns the unique ID for this object.
public
get_id() : int
Tags
Return values
int —get_label()
Get label.
public
get_label([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
string —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
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
Return values
string —get_meta_data()
Get All Meta Data.
public
get_meta_data() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> — of objects.get_name()
Get rate code/name.
public
get_name([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
string —get_object_read()
Get object read property.
public
get_object_read() : bool
Tags
Return values
bool —get_order()
Get parent order object.
public
get_order() : WC_Order
Return values
WC_Order —get_order_id()
Get order ID this meta belongs to.
public
get_order_id([string $context = 'view' ]) : int
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
int —get_quantity()
Get quantity.
public
get_quantity() : int
Return values
int —get_rate_code()
Get rate code/name.
public
get_rate_code([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
string —get_rate_id()
Get tax rate ID.
public
get_rate_id([string $context = 'view' ]) : int
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
int —get_rate_percent()
Get rate value
public
get_rate_percent([string $context = 'view' ]) : float
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
float —get_shipping_tax_total()
Get shipping_tax_total
public
get_shipping_tax_total([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
string —get_tax_class()
Get tax class.
public
get_tax_class() : string
Return values
string —get_tax_status()
Get tax status.
public
get_tax_status() : string
Return values
string —get_tax_total()
Get tax_total
public
get_tax_total([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are 'view' and 'edit'.
Return values
string —get_type()
Get order item type.
public
get_type() : string
Return values
string —is_compound()
Is this a compound tax rate?
public
is_compound() : bool
Return values
bool —is_type()
Type checking.
public
is_type(string|array<string|int, mixed> $type) : bool
Parameters
- $type : string|array<string|int, mixed>
-
Type.
Return values
bool —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
Return values
bool —offsetExists()
OffsetExists for ArrayAccess.
public
offsetExists(string $offset) : bool
Parameters
- $offset : string
-
Offset.
Return values
bool —offsetGet()
O for ArrayAccess/Backwards compatibility.
public
offsetGet(string $offset) : mixed
Parameters
- $offset : string
-
Offset.
Return values
mixed —offsetSet()
OffsetSet for ArrayAccess/Backwards compatibility.
public
offsetSet(string $offset, mixed $value) : mixed
Parameters
- $offset : string
-
Offset.
- $value : mixed
-
Value.
Tags
Return values
mixed —offsetUnset()
OffsetUnset for ArrayAccess.
public
offsetUnset(string $offset) : mixed
Parameters
- $offset : string
-
Offset.
Return values
mixed —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
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
Return values
mixed —save()
Save should create or update based on object existence.
public
save() : int
Tags
Return values
int —save_meta_data()
Update Meta Data in the database.
public
save_meta_data() : mixed
Tags
Return values
mixed —set_compound()
Set compound.
public
set_compound(bool $value) : mixed
Parameters
- $value : bool
-
If tax is compound.
Return values
mixed —set_defaults()
Set all props to default values.
public
set_defaults() : mixed
Tags
Return values
mixed —set_id()
Set ID.
public
set_id(int $id) : mixed
Parameters
- $id : int
-
ID.
Tags
Return values
mixed —set_label()
Set item name.
public
set_label(string $value) : mixed
Parameters
- $value : string
-
Label.
Return values
mixed —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
Return values
mixed —set_name()
Set order item name.
public
set_name(string $value) : mixed
Parameters
- $value : string
-
Name.
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
Return values
mixed —set_order_id()
Set order ID.
public
set_order_id(int $value) : mixed
Parameters
- $value : int
-
Order ID.
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
Return values
bool|WP_Error —set_rate()
Set properties based on passed in tax rate by ID.
public
set_rate(int $tax_rate_id) : mixed
Parameters
- $tax_rate_id : int
-
Tax rate ID.
Return values
mixed —set_rate_code()
Set item name.
public
set_rate_code(string $value) : mixed
Parameters
- $value : string
-
Rate code.
Return values
mixed —set_rate_id()
Set tax rate id.
public
set_rate_id(int $value) : mixed
Parameters
- $value : int
-
Rate ID.
Return values
mixed —set_rate_percent()
Set rate value.
public
set_rate_percent(float $value) : mixed
Parameters
- $value : float
-
tax rate value.
Return values
mixed —set_shipping_tax_total()
Set shipping tax total.
public
set_shipping_tax_total(string $value) : mixed
Parameters
- $value : string
-
Shipping tax total.
Return values
mixed —set_tax_total()
Set tax total.
public
set_tax_total(string $value) : mixed
Parameters
- $value : string
-
Tax total.
Return values
mixed —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
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
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
Return values
bool —get_hook_prefix()
Prefix for action and filter hooks on data.
protected
get_hook_prefix() : string
Tags
Return values
string —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
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
Return values
bool — true if it's an internal key, false otherwisemaybe_read_meta_data()
Read meta data if null.
protected
maybe_read_meta_data() : mixed
Tags
Return values
mixed —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
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 the DB later.
Parameters
- $prop : string
-
Name of prop to set.
- $value : mixed
-
Value of the prop.