WC_Abstract_Order
extends WC_Abstract_Legacy_Order
in package
Uses
WC_Item_Totals
WC_Abstract_Order class.
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>
- Order Data array. This is the core order data exposed in APIs since 3.0.0.
- $data_store : object
- Contains a reference to the data store for this class.
- $data_store_name : string
- Which data store to load.
- $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.
- $items : array<string|int, mixed>
- Order items will be stored here, sometimes before they persist in the DB.
- $items_to_delete : array<string|int, mixed>
- Order items that need deleting are stored here.
- $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, mixed>
- 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.
- __clone() : mixed
- This method overwrites the base class's clone method to make it a no-op. In base class WC_Data, we are unsetting the meta_id to clone.
- __construct() : mixed
- Get the order if ID is passed, otherwise the order is new and empty.
- __get() : mixed
- Magic __get method for backwards compatibility.
- __isset() : bool
- Magic __isset method for backwards compatibility. Handles legacy properties which could be accessed directly in the past.
- __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_coupon() : int
- Add coupon code to the order.
- add_fee() : int
- Add a fee to the order.
- add_item() : false|void
- Adds an order item to this order. The order item will not persist until save.
- add_meta_data() : mixed
- Add meta data.
- add_payment_token() : bool|int
- Add a payment token to an order
- add_product() : int
- Add a product line item to the order. This is the only line item type with its own method because it saves looking up order amounts (costs are added up for you).
- add_shipping() : int
- Add a shipping row to the order.
- add_tax() : int
- Add a tax row to the order.
- apply_changes() : mixed
- Merge changes with data and clear.
- apply_coupon() : true|WP_Error
- Apply a coupon to the order and recalculate totals.
- calculate_shipping() : float
- Calculate shipping total.
- calculate_taxes() : mixed
- Calculate taxes for all line items and shipping, and store the totals and tax rows.
- calculate_totals() : float
- Calculate totals by looking at the contents of the order. Stores the totals and returns the orders final total.
- cancel_order() : mixed
- Cancel the order and restore the cart (before payment).
- decrease_coupon_usage_counts() : mixed
- Decrease applied coupon counts.
- 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.
- display_item_downloads() : mixed
- Display download links for an order item.
- display_item_meta() : mixed
- Display meta data belonging to an item.
- email_order_items_table() : string
- Output items for display in html emails.
- expand_item_meta() : array<string|int, mixed>
- Expand item meta into the $item array.
- generate_meta_cache_key() : string
- Generate cache key from id and group.
- get_base_data() : array<string|int, mixed>
- Get basic order data in array format.
- get_cart_tax() : float
- Gets cart tax amount.
- get_changes() : array<string|int, mixed>
- Return data changes only.
- get_coupon_codes() : array<string|int, mixed>
- Get used coupon codes only.
- get_coupons() : array<string|int, WC_Order_Item_Coupon>
- Return an array of coupons within this order.
- get_currency() : string
- Gets order currency.
- get_data() : array<string|int, mixed>
- Get all class data in array format.
- 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_completed() : WC_DateTime|null
- Get date_modified.
- get_date_created() : WC_DateTime|null
- Get date_created.
- get_date_modified() : WC_DateTime|null
- Get date_modified.
- get_date_paid() : WC_DateTime|null
- Get date_modified.
- get_discount_tax() : string
- Get discount_tax.
- get_discount_to_display() : string
- Get the discount amount (formatted).
- get_discount_total() : string
- Get discount_total.
- get_download_url() : string
- Get the Download URL.
- get_extra_data_keys() : array<string|int, mixed>
- Returns all "extra" data keys for an object (for sub objects like product types).
- get_fees() : array<string|int, WC_Order_item_Fee>
- Return an array of fees within this order.
- get_formatted_line_subtotal() : string
- Gets line subtotal - formatted for display.
- get_formatted_order_total() : string
- Gets order total - formatted for display.
- get_id() : int
- Returns the unique ID for this object.
- get_item() : WC_Order_Item|false
- Get an order item object, based on its type.
- get_item_count() : int|string
- Gets the count of order items of a certain type.
- get_item_downloads() : array<string|int, mixed>
- Get the downloadable files for an item in this order.
- get_item_meta() : array<string|int, mixed>|string
- Get order item meta.
- get_item_meta_array() : array<string|int, mixed>
- Get all item meta data in array format in the order it was saved. Does not group meta by key like get_item_meta().
- get_item_subtotal() : float
- Get item subtotal - this is the cost before discount.
- get_item_tax() : float
- Get item tax - useful for gateways.
- get_item_total() : float
- Calculate item cost - useful for gateways.
- get_items() : array<string|int, WC_Order_Item>
- Return an array of items/products within this order.
- get_items_tax_classes() : array<string|int, mixed>
- Get all tax classes for items in the order.
- get_line_subtotal() : float
- Get line subtotal - this is the cost before discount.
- get_line_tax() : float
- Get line tax - useful for gateways.
- get_line_total() : float
- Calculate line total - useful for gateways.
- 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() : bool
- Gets an order from the database.
- get_order_currency() : mixed
- Get currency.
- get_order_item_totals() : array<string|int, mixed>
- Get totals for display on pages and in emails.
- get_parent_id() : int
- Get parent order ID.
- get_payment_tokens() : array<string|int, mixed>
- Returns a list of all payment tokens associated with the current order
- get_prices_include_tax() : bool
- Get prices_include_tax.
- get_product_from_item() : WC_Product|bool
- Get a product (either product or variation).
- get_recorded_coupon_usage_counts() : bool
- Gets information about whether coupon counts were updated.
- get_rounded_items_total() : float|int
- Return rounded total based on settings. Will be used by Cart and Orders.
- get_shipping_method() : string
- Gets formatted shipping method title.
- get_shipping_methods() : array<string|int, WC_Order_Item_Shipping>
- Return an array of shipping costs within this order.
- get_shipping_tax() : string
- Get shipping_tax.
- get_shipping_to_display() : string
- Gets shipping (formatted).
- get_shipping_total() : string
- Get shipping_total.
- get_status() : string
- Return the order statuses without wc- internal prefix.
- get_subtotal() : float
- Gets order subtotal. Order subtotal is the price of all items excluding taxes, fees, shipping cost, and coupon discounts.
- get_subtotal_to_display() : string
- Gets subtotal - subtotal is shown before discounts, but with localised taxes.
- get_tax_totals() : array<string|int, mixed>
- Get taxes, merged by code, formatted ready for output.
- get_taxable_location() : array<string|int, mixed>
- Public wrapper for exposing get_tax_location() method, enabling 3rd parties to get the tax location for an order.
- get_taxes() : array<string|int, WC_Order_Item_Tax>
- Return an array of taxes within this order.
- get_title() : string
- Get order title.
- get_total() : float
- Gets order grand total including taxes, shipping cost, fees, and coupon discounts. Used in gateways.
- get_total_discount() : float
- Gets the total discount amount.
- get_total_fees() : float
- Calculate fees for all line items.
- get_total_shipping() : float
- Gets shipping total. Alias of WC_Order::get_shipping_total().
- get_total_tax() : float
- Get total tax amount. Alias for get_order_tax().
- get_type() : string
- Get internal type.
- get_used_coupons() : array<string|int, mixed>
- Get coupon codes only.
- get_user() : WP_User|false
- Get user. Used by orders, not other order types like refunds.
- get_user_id() : int
- Get user ID. Used by orders, not other order types like refunds.
- get_version() : string
- Get order_version.
- has_free_item() : bool
- Returns true if the order contains a free product.
- has_meta() : array<string|int, mixed>
- has_meta function for order items. This is different to the WC_Data version and should be removed in future versions.
- has_shipping_method() : bool
- Check whether this order has a specific shipping method or not.
- has_status() : bool
- Checks the order status against a passed in status.
- hold_applied_coupons() : mixed
- Check and records coupon usage tentatively so that counts validation is correct. Display an error if coupon usage limit has been reached.
- increase_coupon_usage_counts() : mixed
- Increase applied coupon counts.
- init_meta_data() : mixed
- Helper function to initialize metadata entries from filtered raw meta data.
- legacy_set_total() : bool
- Set an order total.
- meta_exists() : bool
- See if meta data exists, since get_meta always returns a '' or array().
- populate() : mixed
- Populates an order from the loaded post data.
- 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.
- recalculate_coupons() : mixed
- Apply all coupons in this order again to all line items.
- record_product_sales() : mixed
- Record sales.
- reduce_order_stock() : mixed
- Reduce stock levels for all line items in the order.
- remove_coupon() : bool
- Remove a coupon from the order and recalculate totals.
- remove_item() : false|void
- Remove item from the order.
- remove_order_items() : mixed
- Remove all line items (products, coupons, shipping, taxes) from the order.
- round_item_subtotal() : float
- Apply rounding to item subtotal before summing.
- save() : int
- Save data to the database.
- save_meta_data() : mixed
- Update Meta Data in the database.
- send_stock_notifications() : mixed
- Send the stock notifications.
- set_address() : mixed
- Set the customer address.
- set_cart_tax() : mixed
- Set cart tax.
- set_currency() : mixed
- Set order_currency.
- set_date_created() : mixed
- Set date_created.
- set_date_modified() : mixed
- Set date_modified.
- set_defaults() : mixed
- Set all props to default values.
- set_discount_tax() : mixed
- Set discount_tax.
- set_discount_total() : mixed
- Set discount_total.
- set_id() : mixed
- Set ID.
- set_meta_data() : mixed
- Set all meta data from array.
- set_object_read() : mixed
- Set object read property.
- set_parent_id() : mixed
- Set parent order ID.
- set_prices_include_tax() : mixed
- Set prices_include_tax.
- set_props() : bool|WP_Error
- Set a collection of props in one go, collect any errors, and return the result.
- set_recorded_coupon_usage_counts() : void
- Stores information about whether the coupon usage were counted.
- set_shipping_tax() : mixed
- Set shipping_tax.
- set_shipping_total() : mixed
- Set shipping_total.
- set_status() : array<string|int, mixed>
- Set order status.
- set_total() : bool|void
- Set total.
- set_version() : mixed
- Set order_version.
- update_coupon() : int
- Update coupon for order. Note this does not update order totals.
- update_fee() : int
- Update fee for order.
- update_meta_data() : mixed
- Update meta data by key or ID, if provided.
- update_product() : int
- Update a line item for the order.
- update_shipping() : int
- Update shipping method for order.
- update_tax() : int
- Update tax line on order.
- update_taxes() : mixed
- Update tax lines for the order based on the line item taxes themselves.
- add_order_item_totals_discount_row() : mixed
- Add total row for discounts.
- add_order_item_totals_fee_rows() : mixed
- Add total row for fees.
- add_order_item_totals_shipping_row() : mixed
- Add total row for shipping.
- add_order_item_totals_subtotal_row() : mixed
- Add total row for subtotal.
- add_order_item_totals_tax_rows() : mixed
- Add total row for taxes.
- add_order_item_totals_total_row() : mixed
- Add total row for grand total.
- 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_cart_subtotal_for_order() : float
- Helper function.
- get_cart_total_for_order() : float
- Helper function.
- get_hook_prefix() : string
- Prefix for action and filter hooks on data.
- get_items_key() : string
- Get key for where a certain item type is stored in _items.
- get_prop() : mixed
- Gets a prop for a getter method.
- get_tax_location() : array<string|int, mixed>
- Get tax location for this order.
- get_tax_rates() : mixed|void
- Get tax rates for an order. Use order's shipping or billing address, defaults to base location.
- get_valid_statuses() : array<string|int, mixed>
- Get all valid statuses for this order
- get_values_for_total() : array<string|int, mixed>
- Return array of values for calculations.
- handle_exception() : mixed
- Log an error about this order is exception is encountered.
- init() : mixed
- Load the order object. Called from the constructor.
- is_internal_meta_key() : bool
- Check if the key is an internal one.
- maybe_read_meta_data() : mixed
- Read meta data if null.
- round_at_subtotal() : bool
- Should always round at subtotal?
- round_line_tax() : float
- Apply rounding to an array of taxes before summing. Rounds to store DP setting, ignoring precision.
- save_items() : mixed
- Save all order items which are part of this order.
- set_coupon_discount_amounts() : mixed
- After applying coupons via the WC_Discounts class, update or create coupon items.
- set_date_prop() : mixed
- Sets a date prop whilst handling formatting and datetime objects.
- set_item_discount_amounts() : mixed
- After applying coupons via the WC_Discounts class, update line items.
- set_prop() : mixed
- Sets a prop for a setter method.
- set_total_tax() : mixed
- Sets order tax (sum of cart and shipping tax). Used internally only.
- type_to_group() : string
- Convert a type to a types group.
- get_billing_and_current_user_aliases() : array<string|int, mixed>
- Helper method to get all aliases for current user and provide billing email.
- get_temporary_coupon() : WC_Coupon
- Get a coupon object populated from order line item metadata, to be used when reapplying coupons if the original coupon no longer exists.
- hold_coupon() : string
- Hold coupon if a global usage limit is defined.
- hold_coupon_for_users() : string
- Hold coupon if usage limit per customer is defined.
Properties
$cache_group
Stores meta in cache for future reads.
protected
string
$cache_group
= 'orders'
A group must be set to to enable caching.
$changes
Core data changes for this object.
protected
array<string|int, mixed>
$changes
= array()
Tags
$data
Order Data array. This is the core order data exposed in APIs since 3.0.0.
protected
array<string|int, mixed>
$data
= array('parent_id' => 0, 'status' => '', 'currency' => '', 'version' => '', 'prices_include_tax' => alse, 'date_created' =>
ull, 'date_modified' =>
ull, 'discount_total' => 0, 'discount_tax' => 0, 'shipping_total' => 0, 'shipping_tax' => 0, 'cart_tax' => 0, 'total' => 0, 'total_tax' => 0)
Notes: cart_tax = cart_tax is the new name for the legacy 'order_tax' which is the tax for items only, not shipping.
Tags
$data_store
Contains a reference to the data store for this class.
protected
object
$data_store
Tags
$data_store_name
Which data store to load.
protected
string
$data_store_name
= 'order'
$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
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
$id
ID for this object.
protected
int
$id
= 0
Tags
$items
Order items will be stored here, sometimes before they persist in the DB.
protected
array<string|int, mixed>
$items
= array()
Tags
$items_to_delete
Order items that need deleting are stored here.
protected
array<string|int, mixed>
$items_to_delete
= array()
Tags
$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('_recorded_coupon_usage_counts')
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_data
Stores additional meta data.
protected
array<string|int, mixed>
$meta_data
=
ull
Tags
$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
= 'order'
Methods
__clone()
This method overwrites the base class's clone method to make it a no-op. In base class WC_Data, we are unsetting the meta_id to clone.
public
__clone() : mixed
It seems like this was done to avoid conflicting the metadata when duplicating products. However, doing that does not seems necessary for orders. In-fact, when we do that for orders, we lose the capability to clone orders with custom meta data by caching plugins. This is because, when we clone an order object for caching, it will clone the metadata without the ID. Unfortunately, when this cached object with nulled meta ID is retrieved, WC_Data will consider it as a new meta and will insert it as a new meta-data causing duplicates.
Eventually, we should move away from overwriting the __clone method in base class itself, since it's easily possible to still duplicate the product without having to hook into the __clone method.
Tags
Return values
mixed —__construct()
Get the order if ID is passed, otherwise the order is new and empty.
public
__construct(int|object|WC_Order $order) : mixed
This class should NOT be instantiated, but the wc_get_order function or new WC_Order_Factory should be used. It is possible, but the aforementioned are preferred and are the only methods that will be maintained going forward.
Parameters
- $order : int|object|WC_Order
-
Order to read.
Return values
mixed —__get()
Magic __get method for backwards compatibility.
public
__get(string $key) : mixed
Parameters
- $key : string
Return values
mixed —__isset()
Magic __isset method for backwards compatibility. Handles legacy properties which could be accessed directly in the past.
public
__isset(string $key) : bool
Parameters
- $key : string
Return values
bool —__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_coupon()
Add coupon code to the order.
public
add_coupon([string|array<string|int, mixed> $code = array() ], int $discount, int $discount_tax) : int
Parameters
- $code : string|array<string|int, mixed> = array()
- $discount : int
-
tax amount.
- $discount_tax : int
-
amount.
Tags
Return values
int — order item IDadd_fee()
Add a fee to the order.
public
add_fee(object $fee) : int
Order must be saved prior to adding items.
Fee is an amount of money charged for a particular piece of work or for a particular right or service, and not supposed to be negative.
Parameters
- $fee : object
-
Fee data.
Tags
Return values
int — Updated order item ID.add_item()
Adds an order item to this order. The order item will not persist until save.
public
add_item(WC_Order_Item $item) : false|void
Parameters
- $item : WC_Order_Item
-
Order item object (product, shipping, fee, coupon, tax).
Tags
Return values
false|void —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 —add_payment_token()
Add a payment token to an order
public
add_payment_token(WC_Payment_Token $token) : bool|int
Parameters
- $token : WC_Payment_Token
-
Payment token object.
Tags
Return values
bool|int — The new token ID or false if it failed.add_product()
Add a product line item to the order. This is the only line item type with its own method because it saves looking up order amounts (costs are added up for you).
public
add_product(WC_Product $product[, int $qty = 1 ][, array<string|int, mixed> $args = array() ]) : int
Parameters
- $product : WC_Product
-
Product object.
- $qty : int = 1
-
Quantity to add.
- $args : array<string|int, mixed> = array()
-
Args for the added product.
Return values
int —add_shipping()
Add a shipping row to the order.
public
add_shipping(mixed $shipping_rate) : int
Parameters
- $shipping_rate : mixed
Tags
Return values
int — order item IDadd_tax()
Add a tax row to the order.
public
add_tax(int $tax_rate_id, int $tax_amount, int $shipping_tax_amount) : int
Parameters
- $tax_rate_id : int
- $tax_amount : int
-
amount of tax.
- $shipping_tax_amount : int
-
shipping amount.
Tags
Return values
int — order item IDapply_changes()
Merge changes with data and clear.
public
apply_changes() : mixed
Tags
Return values
mixed —apply_coupon()
Apply a coupon to the order and recalculate totals.
public
apply_coupon(string|WC_Coupon $raw_coupon) : true|WP_Error
Parameters
- $raw_coupon : string|WC_Coupon
-
Coupon code or object.
Tags
Return values
true|WP_Error — True if applied, error if not.calculate_shipping()
Calculate shipping total.
public
calculate_shipping() : float
Tags
Return values
float —calculate_taxes()
Calculate taxes for all line items and shipping, and store the totals and tax rows.
public
calculate_taxes([array<string|int, mixed> $args = array() ]) : mixed
If by default the taxes are based on the shipping address and the current order doesn't have any, it would use the billing address rather than using the Shopping base location.
Will use the base country unless customer addresses are set.
Parameters
- $args : array<string|int, mixed> = array()
-
Added in 3.0.0 to pass things like location.
Return values
mixed —calculate_totals()
Calculate totals by looking at the contents of the order. Stores the totals and returns the orders final total.
public
calculate_totals([bool $and_taxes = true ]) : float
Parameters
- $and_taxes : bool = true
-
Calc taxes if true.
Tags
Return values
float — calculated grand total.cancel_order()
Cancel the order and restore the cart (before payment).
public
cancel_order([string $note = '' ]) : mixed
Parameters
- $note : string = ''
-
(default: '') Optional note to add.
Tags
Return values
mixed —decrease_coupon_usage_counts()
Decrease applied coupon counts.
public
decrease_coupon_usage_counts() : mixed
Tags
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
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 —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
Return values
mixed —display_item_downloads()
Display download links for an order item.
public
display_item_downloads(array<string|int, mixed> $item) : mixed
Parameters
- $item : array<string|int, mixed>
Return values
mixed —display_item_meta()
Display meta data belonging to an item.
public
display_item_meta(array<string|int, mixed> $item) : mixed
Parameters
- $item : array<string|int, mixed>
Return values
mixed —email_order_items_table()
Output items for display in html emails.
public
email_order_items_table([array<string|int, mixed> $args = array() ]) : string
Parameters
- $args : array<string|int, mixed> = array()
-
Items args.
Tags
Return values
string —expand_item_meta()
Expand item meta into the $item array.
public
expand_item_meta(array<string|int, mixed> $item) : array<string|int, mixed>
Parameters
- $item : array<string|int, mixed>
-
before expansion.
Tags
Return values
array<string|int, 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_base_data()
Get basic order data in array format.
public
get_base_data() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_cart_tax()
Gets cart tax amount.
public
get_cart_tax([string $context = 'view' ]) : float
Parameters
- $context : string = 'view'
-
View or edit context.
Return values
float —get_changes()
Return data changes only.
public
get_changes() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_coupon_codes()
Get used coupon codes only.
public
get_coupon_codes() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_coupons()
Return an array of coupons within this order.
public
get_coupons() : array<string|int, WC_Order_Item_Coupon>
Tags
Return values
array<string|int, WC_Order_Item_Coupon> —get_currency()
Gets order currency.
public
get_currency([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
View or edit context.
Return values
string —get_data()
Get all class data in array format.
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_date_completed()
Get date_modified.
public
get_date_completed([string $context = 'view' ]) : WC_DateTime|null
Parameters
- $context : string = 'view'
-
View or edit context.
Return values
WC_DateTime|null — object if the date is set or null if there is no date.get_date_created()
Get date_created.
public
get_date_created([string $context = 'view' ]) : WC_DateTime|null
Parameters
- $context : string = 'view'
-
View or edit context.
Return values
WC_DateTime|null — object if the date is set or null if there is no date.get_date_modified()
Get date_modified.
public
get_date_modified([string $context = 'view' ]) : WC_DateTime|null
Parameters
- $context : string = 'view'
-
View or edit context.
Return values
WC_DateTime|null — object if the date is set or null if there is no date.get_date_paid()
Get date_modified.
public
get_date_paid([string $context = 'view' ]) : WC_DateTime|null
Parameters
- $context : string = 'view'
-
View or edit context.
Return values
WC_DateTime|null — object if the date is set or null if there is no date.get_discount_tax()
Get discount_tax.
public
get_discount_tax([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
View or edit context.
Return values
string —get_discount_to_display()
Get the discount amount (formatted).
public
get_discount_to_display([string $tax_display = '' ]) : string
Parameters
- $tax_display : string = ''
-
Excl or incl tax display mode.
Tags
Return values
string —get_discount_total()
Get discount_total.
public
get_discount_total([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
View or edit context.
Return values
string —get_download_url()
Get the Download URL.
public
get_download_url(int $product_id, int $download_id) : string
Parameters
- $product_id : int
- $download_id : int
Return values
string —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_fees()
Return an array of fees within this order.
public
get_fees() : array<string|int, WC_Order_item_Fee>
Return values
array<string|int, WC_Order_item_Fee> —get_formatted_line_subtotal()
Gets line subtotal - formatted for display.
public
get_formatted_line_subtotal(object $item[, string $tax_display = '' ]) : string
Parameters
- $item : object
-
Item to get total from.
- $tax_display : string = ''
-
Incl or excl tax display mode.
Return values
string —get_formatted_order_total()
Gets order total - formatted for display.
public
get_formatted_order_total() : string
Return values
string —get_id()
Returns the unique ID for this object.
public
get_id() : int
Tags
Return values
int —get_item()
Get an order item object, based on its type.
public
get_item(int $item_id[, bool $load_from_db = true ]) : WC_Order_Item|false
Parameters
- $item_id : int
-
ID of item to get.
- $load_from_db : bool = true
-
Prior to 3.2 this item was loaded direct from WC_Order_Factory, not this object. This param is here for backwards compatibility with that. If false, uses the local items variable instead.
Tags
Return values
WC_Order_Item|false —get_item_count()
Gets the count of order items of a certain type.
public
get_item_count([string $item_type = '' ]) : int|string
Parameters
- $item_type : string = ''
-
Item type to lookup.
Return values
int|string —get_item_downloads()
Get the downloadable files for an item in this order.
public
get_item_downloads(array<string|int, mixed> $item) : array<string|int, mixed>
Parameters
- $item : array<string|int, mixed>
Return values
array<string|int, mixed> —get_item_meta()
Get order item meta.
public
get_item_meta(mixed $order_item_id[, string $key = '' ][, bool $single = false ]) : array<string|int, mixed>|string
Parameters
- $order_item_id : mixed
- $key : string = ''
-
(default: '')
- $single : bool = false
-
(default: false)
Tags
Return values
array<string|int, mixed>|string —get_item_meta_array()
Get all item meta data in array format in the order it was saved. Does not group meta by key like get_item_meta().
public
get_item_meta_array(mixed $order_item_id) : array<string|int, mixed>
Parameters
- $order_item_id : mixed
Return values
array<string|int, mixed> — of objectsget_item_subtotal()
Get item subtotal - this is the cost before discount.
public
get_item_subtotal(object $item[, bool $inc_tax = false ][, bool $round = true ]) : float
Parameters
- $item : object
-
Item to get total from.
- $inc_tax : bool = false
-
(default: false).
- $round : bool = true
-
(default: true).
Return values
float —get_item_tax()
Get item tax - useful for gateways.
public
get_item_tax(mixed $item[, bool $round = true ]) : float
Parameters
- $item : mixed
-
Item to get total from.
- $round : bool = true
-
(default: true).
Return values
float —get_item_total()
Calculate item cost - useful for gateways.
public
get_item_total(object $item[, bool $inc_tax = false ][, bool $round = true ]) : float
Parameters
- $item : object
-
Item to get total from.
- $inc_tax : bool = false
-
(default: false).
- $round : bool = true
-
(default: true).
Return values
float —get_items()
Return an array of items/products within this order.
public
get_items([string|array<string|int, mixed> $types = 'line_item' ]) : array<string|int, WC_Order_Item>
Parameters
- $types : string|array<string|int, mixed> = 'line_item'
-
Types of line items to get (array or string).
Return values
array<string|int, WC_Order_Item> —get_items_tax_classes()
Get all tax classes for items in the order.
public
get_items_tax_classes() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_line_subtotal()
Get line subtotal - this is the cost before discount.
public
get_line_subtotal(object $item[, bool $inc_tax = false ][, bool $round = true ]) : float
Parameters
- $item : object
-
Item to get total from.
- $inc_tax : bool = false
-
(default: false).
- $round : bool = true
-
(default: true).
Return values
float —get_line_tax()
Get line tax - useful for gateways.
public
get_line_tax(mixed $item) : float
Parameters
- $item : mixed
-
Item to get total from.
Return values
float —get_line_total()
Calculate line total - useful for gateways.
public
get_line_total(object $item[, bool $inc_tax = false ][, bool $round = true ]) : float
Parameters
- $item : object
-
Item to get total from.
- $inc_tax : bool = false
-
(default: false).
- $round : bool = true
-
(default: true).
Return values
float —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_object_read()
Get object read property.
public
get_object_read() : bool
Tags
Return values
bool —get_order()
Gets an order from the database.
public
get_order(int $id) : bool
Parameters
- $id : int
-
(default: 0).
Tags
Return values
bool —get_order_currency()
Get currency.
public
get_order_currency() : mixed
Tags
Return values
mixed —get_order_item_totals()
Get totals for display on pages and in emails.
public
get_order_item_totals([mixed $tax_display = '' ]) : array<string|int, mixed>
Parameters
- $tax_display : mixed = ''
-
Excl or incl tax display mode.
Return values
array<string|int, mixed> —get_parent_id()
Get parent order ID.
public
get_parent_id([string $context = 'view' ]) : int
Parameters
- $context : string = 'view'
-
View or edit context.
Tags
Return values
int —get_payment_tokens()
Returns a list of all payment tokens associated with the current order
public
get_payment_tokens() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> — An array of payment token objectsget_prices_include_tax()
Get prices_include_tax.
public
get_prices_include_tax([string $context = 'view' ]) : bool
Parameters
- $context : string = 'view'
-
View or edit context.
Return values
bool —get_product_from_item()
Get a product (either product or variation).
public
get_product_from_item(object $item) : WC_Product|bool
Parameters
- $item : object
Tags
Return values
WC_Product|bool —get_recorded_coupon_usage_counts()
Gets information about whether coupon counts were updated.
public
get_recorded_coupon_usage_counts([string $context = 'view' ]) : bool
Parameters
- $context : string = 'view'
-
What the value is for. Valid values are view and edit.
Return values
bool — True if coupon counts were updated, false otherwise.get_rounded_items_total()
Return rounded total based on settings. Will be used by Cart and Orders.
public
static get_rounded_items_total(array<string|int, mixed> $values) : float|int
Parameters
- $values : array<string|int, mixed>
-
Values to round. Should be with precision.
Tags
Return values
float|int — Appropriately rounded value.get_shipping_method()
Gets formatted shipping method title.
public
get_shipping_method() : string
Return values
string —get_shipping_methods()
Return an array of shipping costs within this order.
public
get_shipping_methods() : array<string|int, WC_Order_Item_Shipping>
Return values
array<string|int, WC_Order_Item_Shipping> —get_shipping_tax()
Get shipping_tax.
public
get_shipping_tax([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
View or edit context.
Return values
string —get_shipping_to_display()
Gets shipping (formatted).
public
get_shipping_to_display([string $tax_display = '' ]) : string
Parameters
- $tax_display : string = ''
-
Excl or incl tax display mode.
Return values
string —get_shipping_total()
Get shipping_total.
public
get_shipping_total([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
View or edit context.
Return values
string —get_status()
Return the order statuses without wc- internal prefix.
public
get_status([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
View or edit context.
Return values
string —get_subtotal()
Gets order subtotal. Order subtotal is the price of all items excluding taxes, fees, shipping cost, and coupon discounts.
public
get_subtotal() : float
If sale price is set on an item, the subtotal will include this sale discount. E.g. a product with a regular price of $100 bought at a 50% discount will represent $50 of the subtotal for the order.
Return values
float —get_subtotal_to_display()
Gets subtotal - subtotal is shown before discounts, but with localised taxes.
public
get_subtotal_to_display([bool $compound = false ][, string $tax_display = '' ]) : string
Parameters
- $compound : bool = false
-
(default: false).
- $tax_display : string = ''
-
(default: the tax_display_cart value).
Return values
string —get_tax_totals()
Get taxes, merged by code, formatted ready for output.
public
get_tax_totals() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_taxable_location()
Public wrapper for exposing get_tax_location() method, enabling 3rd parties to get the tax location for an order.
public
get_taxable_location([array<string|int, mixed> $args = array() ]) : array<string|int, mixed>
Parameters
- $args : array<string|int, mixed> = array()
-
array Override the location.
Tags
Return values
array<string|int, mixed> —get_taxes()
Return an array of taxes within this order.
public
get_taxes() : array<string|int, WC_Order_Item_Tax>
Return values
array<string|int, WC_Order_Item_Tax> —get_title()
Get order title.
public
get_title() : string
Return values
string — Order title.get_total()
Gets order grand total including taxes, shipping cost, fees, and coupon discounts. Used in gateways.
public
get_total([string $context = 'view' ]) : float
Parameters
- $context : string = 'view'
-
View or edit context.
Return values
float —get_total_discount()
Gets the total discount amount.
public
get_total_discount([bool $ex_tax = true ]) : float
Parameters
- $ex_tax : bool = true
-
Show discount excl any tax.
Return values
float —get_total_fees()
Calculate fees for all line items.
public
get_total_fees() : float
Return values
float — Fee total.get_total_shipping()
Gets shipping total. Alias of WC_Order::get_shipping_total().
public
get_total_shipping() : float
Tags
Return values
float —get_total_tax()
Get total tax amount. Alias for get_order_tax().
public
get_total_tax([string $context = 'view' ]) : float
Parameters
- $context : string = 'view'
-
View or edit context.
Return values
float —get_type()
Get internal type.
public
get_type() : string
Return values
string —get_used_coupons()
Get coupon codes only.
public
get_used_coupons() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_user()
Get user. Used by orders, not other order types like refunds.
public
get_user() : WP_User|false
Return values
WP_User|false —get_user_id()
Get user ID. Used by orders, not other order types like refunds.
public
get_user_id([string $context = 'view' ]) : int
Parameters
- $context : string = 'view'
-
View or edit context.
Return values
int —get_version()
Get order_version.
public
get_version([string $context = 'view' ]) : string
Parameters
- $context : string = 'view'
-
View or edit context.
Return values
string —has_free_item()
Returns true if the order contains a free product.
public
has_free_item() : bool
Tags
Return values
bool —has_meta()
has_meta function for order items. This is different to the WC_Data version and should be removed in future versions.
public
has_meta(int $order_item_id) : array<string|int, mixed>
Parameters
- $order_item_id : int
Tags
Return values
array<string|int, mixed> — of meta data.has_shipping_method()
Check whether this order has a specific shipping method or not.
public
has_shipping_method(string $method_id) : bool
Parameters
- $method_id : string
-
Method ID to check.
Return values
bool —has_status()
Checks the order status against a passed in status.
public
has_status(array<string|int, mixed>|string $status) : bool
Parameters
- $status : array<string|int, mixed>|string
-
Status to check.
Return values
bool —hold_applied_coupons()
Check and records coupon usage tentatively so that counts validation is correct. Display an error if coupon usage limit has been reached.
public
hold_applied_coupons(string $billing_email) : mixed
If you are using this method, make sure to release_held_coupons
in case an Exception is thrown.
Parameters
- $billing_email : string
-
Billing email of order.
Tags
Return values
mixed —increase_coupon_usage_counts()
Increase applied coupon counts.
public
increase_coupon_usage_counts() : mixed
Tags
Return values
mixed —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 —legacy_set_total()
Set an order total.
public
legacy_set_total(float $amount[, string $total_type = 'total' ]) : bool
Parameters
- $amount : float
- $total_type : string = 'total'
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 —populate()
Populates an order from the loaded post data.
public
populate(mixed $result) : mixed
Parameters
- $result : mixed
Tags
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 —recalculate_coupons()
Apply all coupons in this order again to all line items.
public
recalculate_coupons() : mixed
This method is public since WooCommerce 3.8.0.
Tags
Return values
mixed —record_product_sales()
Record sales.
public
record_product_sales() : mixed
Tags
Return values
mixed —reduce_order_stock()
Reduce stock levels for all line items in the order.
public
reduce_order_stock() : mixed
Tags
Return values
mixed —remove_coupon()
Remove a coupon from the order and recalculate totals.
public
remove_coupon(string $code) : bool
Coupons affect line item totals, but there is no relationship between coupon and line total, so to remove a coupon we need to work from the line subtotal (price before discount) and re-apply all coupons in this order.
Manual discounts are not affected; those are separate and do not affect stored line totals.
Parameters
- $code : string
-
Coupon code.
Tags
Return values
bool — TRUE if coupon was removed, FALSE otherwise.remove_item()
Remove item from the order.
public
remove_item(int $item_id) : false|void
Parameters
- $item_id : int
-
Item ID to delete.
Return values
false|void —remove_order_items()
Remove all line items (products, coupons, shipping, taxes) from the order.
public
remove_order_items([string $type = null ]) : mixed
Parameters
- $type : string = null
-
Order item type. Default null.
Return values
mixed —round_item_subtotal()
Apply rounding to item subtotal before summing.
public
static round_item_subtotal(float $value) : float
Parameters
- $value : float
-
Item subtotal value.
Tags
Return values
float —save()
Save data to the database.
public
save() : int
Tags
Return values
int — order IDsave_meta_data()
Update Meta Data in the database.
public
save_meta_data() : mixed
Tags
Return values
mixed —send_stock_notifications()
Send the stock notifications.
public
send_stock_notifications( $product, $new_stock, $qty_ordered) : mixed
Parameters
Tags
Return values
mixed —set_address()
Set the customer address.
public
set_address(array<string|int, mixed> $address[, string $type = 'billing' ]) : mixed
Parameters
- $address : array<string|int, mixed>
-
Address data.
- $type : string = 'billing'
-
Type of address; 'billing' or 'shipping'.
Return values
mixed —set_cart_tax()
Set cart tax.
public
set_cart_tax(string $value) : mixed
Parameters
- $value : string
-
Value to set.
Tags
Return values
mixed —set_currency()
Set order_currency.
public
set_currency(string $value) : mixed
Parameters
- $value : string
-
Value to set.
Tags
Return values
mixed —set_date_created()
Set date_created.
public
set_date_created([string|int|null $date = null ]) : mixed
Parameters
- $date : string|int|null = null
-
UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if there is no date.
Tags
Return values
mixed —set_date_modified()
Set date_modified.
public
set_date_modified([string|int|null $date = null ]) : mixed
Parameters
- $date : string|int|null = null
-
UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if there is no date.
Tags
Return values
mixed —set_defaults()
Set all props to default values.
public
set_defaults() : mixed
Tags
Return values
mixed —set_discount_tax()
Set discount_tax.
public
set_discount_tax(string $value) : mixed
Parameters
- $value : string
-
Value to set.
Tags
Return values
mixed —set_discount_total()
Set discount_total.
public
set_discount_total(string $value) : mixed
Parameters
- $value : string
-
Value to set.
Tags
Return values
mixed —set_id()
Set ID.
public
set_id(int $id) : mixed
Parameters
- $id : int
-
ID.
Tags
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_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_parent_id()
Set parent order ID.
public
set_parent_id(int $value) : mixed
Parameters
- $value : int
-
Value to set.
Tags
Return values
mixed —set_prices_include_tax()
Set prices_include_tax.
public
set_prices_include_tax(bool $value) : mixed
Parameters
- $value : bool
-
Value to set.
Tags
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_recorded_coupon_usage_counts()
Stores information about whether the coupon usage were counted.
public
set_recorded_coupon_usage_counts(bool|string $value) : void
Parameters
- $value : bool|string
-
True if counted, false if not.
Return values
void —set_shipping_tax()
Set shipping_tax.
public
set_shipping_tax(string $value) : mixed
Parameters
- $value : string
-
Value to set.
Tags
Return values
mixed —set_shipping_total()
Set shipping_total.
public
set_shipping_total(string $value) : mixed
Parameters
- $value : string
-
Value to set.
Tags
Return values
mixed —set_status()
Set order status.
public
set_status(string $new_status) : array<string|int, mixed>
Parameters
- $new_status : string
-
Status to change the order to. No internal wc- prefix is required.
Tags
Return values
array<string|int, mixed> — details of changeset_total()
Set total.
public
set_total(string $value[, string $deprecated = '' ]) : bool|void
Parameters
- $value : string
-
Value to set.
- $deprecated : string = ''
-
Function used to set different totals based on this.
Tags
Return values
bool|void —set_version()
Set order_version.
public
set_version(string $value) : mixed
Parameters
- $value : string
-
Value to set.
Tags
Return values
mixed —update_coupon()
Update coupon for order. Note this does not update order totals.
public
update_coupon(object|int $item, array<string|int, mixed> $args) : int
Parameters
- $item : object|int
- $args : array<string|int, mixed>
Tags
Return values
int — updated order item IDupdate_fee()
Update fee for order.
public
update_fee(object|int $item, array<string|int, mixed> $args) : int
Note this does not update order totals.
Parameters
- $item : object|int
- $args : array<string|int, mixed>
Tags
Return values
int — updated order item IDupdate_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 —update_product()
Update a line item for the order.
public
update_product(object|int $item, WC_Product $product, array<string|int, mixed> $args) : int
Note this does not update order totals.
Parameters
- $item : object|int
-
order item ID or item object.
- $product : WC_Product
- $args : array<string|int, mixed>
-
data to update.
Tags
Return values
int — updated order item IDupdate_shipping()
Update shipping method for order.
public
update_shipping(object|int $item, array<string|int, mixed> $args) : int
Note this does not update the order total.
Parameters
- $item : object|int
- $args : array<string|int, mixed>
Tags
Return values
int — updated order item IDupdate_tax()
Update tax line on order.
public
update_tax(object|int $item, array<string|int, mixed> $args) : int
Note this does not update order totals.
Parameters
- $item : object|int
- $args : array<string|int, mixed>
Tags
Return values
int — updated order item IDupdate_taxes()
Update tax lines for the order based on the line item taxes themselves.
public
update_taxes() : mixed
Return values
mixed —add_order_item_totals_discount_row()
Add total row for discounts.
protected
add_order_item_totals_discount_row(array<string|int, mixed> &$total_rows, string $tax_display) : mixed
Parameters
- $total_rows : array<string|int, mixed>
-
Reference to total rows array.
- $tax_display : string
-
Excl or incl tax display mode.
Return values
mixed —add_order_item_totals_fee_rows()
Add total row for fees.
protected
add_order_item_totals_fee_rows(array<string|int, mixed> &$total_rows, string $tax_display) : mixed
Parameters
- $total_rows : array<string|int, mixed>
-
Reference to total rows array.
- $tax_display : string
-
Excl or incl tax display mode.
Return values
mixed —add_order_item_totals_shipping_row()
Add total row for shipping.
protected
add_order_item_totals_shipping_row(array<string|int, mixed> &$total_rows, string $tax_display) : mixed
Parameters
- $total_rows : array<string|int, mixed>
-
Reference to total rows array.
- $tax_display : string
-
Excl or incl tax display mode.
Return values
mixed —add_order_item_totals_subtotal_row()
Add total row for subtotal.
protected
add_order_item_totals_subtotal_row(array<string|int, mixed> &$total_rows, string $tax_display) : mixed
Parameters
- $total_rows : array<string|int, mixed>
-
Reference to total rows array.
- $tax_display : string
-
Excl or incl tax display mode.
Return values
mixed —add_order_item_totals_tax_rows()
Add total row for taxes.
protected
add_order_item_totals_tax_rows(array<string|int, mixed> &$total_rows, string $tax_display) : mixed
Parameters
- $total_rows : array<string|int, mixed>
-
Reference to total rows array.
- $tax_display : string
-
Excl or incl tax display mode.
Return values
mixed —add_order_item_totals_total_row()
Add total row for grand total.
protected
add_order_item_totals_total_row(array<string|int, mixed> &$total_rows, string $tax_display) : mixed
Parameters
- $total_rows : array<string|int, mixed>
-
Reference to total rows array.
- $tax_display : string
-
Excl or incl tax display mode.
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_cart_subtotal_for_order()
Helper function.
protected
get_cart_subtotal_for_order() : float
If you add all items in this order in cart again, this would be the cart subtotal (assuming all other settings are same).
Return values
float — Cart subtotal.get_cart_total_for_order()
Helper function.
protected
get_cart_total_for_order() : float
If you add all items in this order in cart again, this would be the cart total (assuming all other settings are same).
Return values
float — Cart total.get_hook_prefix()
Prefix for action and filter hooks on data.
protected
get_hook_prefix() : string
Tags
Return values
string —get_items_key()
Get key for where a certain item type is stored in _items.
protected
get_items_key(string $item) : string
Parameters
- $item : string
-
object Order item (product, shipping, fee, coupon, tax).
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 —get_tax_location()
Get tax location for this order.
protected
get_tax_location([array<string|int, mixed> $args = array() ]) : array<string|int, mixed>
Parameters
- $args : array<string|int, mixed> = array()
-
array Override the location.
Tags
Return values
array<string|int, mixed> —get_tax_rates()
Get tax rates for an order. Use order's shipping or billing address, defaults to base location.
protected
get_tax_rates(string $tax_class[, array<string|int, mixed> $location_args = array() ][, object $customer = null ]) : mixed|void
Parameters
- $tax_class : string
-
Tax class to get rates for.
- $location_args : array<string|int, mixed> = array()
-
Location to compute rates for. Should be in form: array( country, state, postcode, city).
- $customer : object = null
-
Only used to maintain backward compatibility for filter
woocommerce-matched_rates
.
Return values
mixed|void — Tax rates.get_valid_statuses()
Get all valid statuses for this order
protected
get_valid_statuses() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> — Internal status keys e.g. 'wc-processing'get_values_for_total()
Return array of values for calculations.
protected
get_values_for_total(string $field) : array<string|int, mixed>
Parameters
- $field : string
-
Field name to return.
Return values
array<string|int, mixed> — Array of values.handle_exception()
Log an error about this order is exception is encountered.
protected
handle_exception(Exception $e[, string $message = 'Error' ]) : mixed
Parameters
- $e : Exception
-
Exception object.
- $message : string = 'Error'
-
Message regarding exception thrown.
Tags
Return values
mixed —init()
Load the order object. Called from the constructor.
protected
init(int|object|WC_Order $order) : mixed
Parameters
- $order : int|object|WC_Order
-
Order to init.
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 —round_at_subtotal()
Should always round at subtotal?
protected
static round_at_subtotal() : bool
Tags
Return values
bool —round_line_tax()
Apply rounding to an array of taxes before summing. Rounds to store DP setting, ignoring precision.
protected
static round_line_tax(float $value[, bool $in_cents = true ]) : float
Parameters
- $value : float
-
Tax value.
- $in_cents : bool = true
-
Whether precision of value is in cents.
Tags
Return values
float —save_items()
Save all order items which are part of this order.
protected
save_items() : mixed
Return values
mixed —set_coupon_discount_amounts()
After applying coupons via the WC_Discounts class, update or create coupon items.
protected
set_coupon_discount_amounts(WC_Discounts $discounts) : mixed
Parameters
- $discounts : WC_Discounts
-
Discounts class.
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_item_discount_amounts()
After applying coupons via the WC_Discounts class, update line items.
protected
set_item_discount_amounts(WC_Discounts $discounts) : mixed
Parameters
- $discounts : WC_Discounts
-
Discounts class.
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 DB later.
Parameters
- $prop : string
-
Name of prop to set.
- $value : mixed
-
Value of the prop.
Tags
Return values
mixed —set_total_tax()
Sets order tax (sum of cart and shipping tax). Used internally only.
protected
set_total_tax(string $value) : mixed
Parameters
- $value : string
-
Value to set.
Tags
Return values
mixed —type_to_group()
Convert a type to a types group.
protected
type_to_group(string $type) : string
Parameters
- $type : string
-
type to lookup.
Return values
string —get_billing_and_current_user_aliases()
Helper method to get all aliases for current user and provide billing email.
private
get_billing_and_current_user_aliases(string $billing_email) : array<string|int, mixed>
Parameters
- $billing_email : string
-
Billing email provided in form.
Tags
Return values
array<string|int, mixed> — Array of all aliases.get_temporary_coupon()
Get a coupon object populated from order line item metadata, to be used when reapplying coupons if the original coupon no longer exists.
private
get_temporary_coupon(WC_Order_Item_Coupon $coupon_item) : WC_Coupon
Parameters
- $coupon_item : WC_Order_Item_Coupon
-
The order item corresponding to the coupon to reapply.
Tags
Return values
WC_Coupon —hold_coupon()
Hold coupon if a global usage limit is defined.
private
hold_coupon(WC_Coupon $coupon) : string
Parameters
- $coupon : WC_Coupon
-
Coupon object.
Tags
Return values
string — Meta key which indicates held coupon.hold_coupon_for_users()
Hold coupon if usage limit per customer is defined.
private
hold_coupon_for_users(WC_Coupon $coupon, array<string|int, mixed> $user_ids_and_emails, string $user_alias) : string
Parameters
- $coupon : WC_Coupon
-
Coupon object.
- $user_ids_and_emails : array<string|int, mixed>
-
Array of user Id and emails to check for usage limit.
- $user_alias : string
-
User ID or email to use to record current usage.