OrderUtil
in package
A class of utilities for dealing with orders.
Table of Contents
- custom_orders_table_data_sync_is_enabled() : bool
- Checks whether the real-time data sync between the posts and orders tables is enabled.
- custom_orders_table_datastore_cache_enabled() : bool
- Helper function to get whether custom order tables are enabled or not.
- custom_orders_table_usage_is_enabled() : bool
- Helper function to get whether custom order tables are enabled or not.
- get_count_for_type() : array<string, int>
- Counts number of orders of a given type.
- get_order_admin_edit_url() : string
- Helper method to generate admin url for an order.
- get_order_admin_new_url() : string
- Helper method to generate admin URL for new order.
- get_order_admin_screen() : string
- Helper function to get screen name of orders page in wp-admin.
- get_order_type() : string|null
- Returns type pf passed id, post or order object.
- get_post_or_object_meta() : array<string|int, mixed>|mixed|string
- Gets value of a meta key from WC_Data object if passed, otherwise from the post object.
- get_post_or_order_id() : int
- Helper function to id from an post or order object.
- get_table_for_order_meta() : string
- Get the name of the database table that's currently in use for orders.
- get_table_for_orders() : string
- Get the name of the database table that's currently in use for orders.
- init_theorder_object() : bool|WC_Order|WC_Order_Refund
- Helper function to initialize the global $theorder object, mostly used during order meta boxes rendering.
- is_custom_order_tables_in_sync() : bool
- Checks if posts and order custom table sync is enabled and there are no pending orders.
- is_new_order_screen() : bool
- Check if the current admin screen is adding a new order.
- is_order() : bool
- Checks if passed id, post or order object is a WC_Order object.
- is_order_edit_screen() : bool
- Check if the current admin screen is for editing an order.
- is_order_list_table_screen() : bool
- Check if the current admin screen is an order list table.
- orders_cache_usage_is_enabled() : bool
- Helper function to get whether the orders cache should be used or not.
- remove_status_prefix() : string
- Removes the 'wc-' prefix from status.
- unknown_orders_data_store_in_use() : bool
- Checks if the data store currently in use for orders is unknown (none of the ones managed by WooCommerce core).
- uses_new_full_refund_data() : bool
- Checks if the new full refund data is used.
Methods
custom_orders_table_data_sync_is_enabled()
Checks whether the real-time data sync between the posts and orders tables is enabled.
public
static custom_orders_table_data_sync_is_enabled() : bool
Unlike is_custom_order_tables_in_sync(), this only reflects whether the sync setting is enabled (a cheap option read) and does not run a query to check whether the tables are currently fully synchronized. Use this when you only need to know if sync is turned on, not whether every order is currently in sync.
Tags
Return values
bool — True if data sync is enabled, false otherwise.custom_orders_table_datastore_cache_enabled()
Helper function to get whether custom order tables are enabled or not.
public
static custom_orders_table_datastore_cache_enabled() : bool
Return values
bool —custom_orders_table_usage_is_enabled()
Helper function to get whether custom order tables are enabled or not.
public
static custom_orders_table_usage_is_enabled() : bool
Return values
bool —get_count_for_type()
Counts number of orders of a given type.
public
static get_count_for_type(string $order_type) : array<string, int>
Parameters
- $order_type : string
-
Order type.
Tags
Return values
array<string, int> — Array of order counts indexed by order type.get_order_admin_edit_url()
Helper method to generate admin url for an order.
public
static get_order_admin_edit_url(int $order_id) : string
Parameters
- $order_id : int
-
Order ID.
Return values
string — Admin url for an order.get_order_admin_new_url()
Helper method to generate admin URL for new order.
public
static get_order_admin_new_url() : string
Return values
string — Link for new order.get_order_admin_screen()
Helper function to get screen name of orders page in wp-admin.
public
static get_order_admin_screen() : string
Return values
string —get_order_type()
Returns type pf passed id, post or order object.
public
static get_order_type(int|WP_Post|WC_Order $order_id) : string|null
Parameters
- $order_id : int|WP_Post|WC_Order
-
Order ID, post object or order object.
Return values
string|null — Type of the order.get_post_or_object_meta()
Gets value of a meta key from WC_Data object if passed, otherwise from the post object.
public
static get_post_or_object_meta(WP_Post|null $post, WC_Data|null $data, string $key, bool $single) : array<string|int, mixed>|mixed|string
This helper function support backward compatibility for meta box functions, when moving from posts based store to custom tables.
Parameters
- $post : WP_Post|null
-
Post object, meta will be fetched from this only when
$datais not passed. - $data : WC_Data|null
-
WC_Data object, will be preferred over post object when passed.
- $key : string
-
Key to fetch metadata for.
- $single : bool
-
Whether metadata is single.
Return values
array<string|int, mixed>|mixed|string — Value of the meta key.get_post_or_order_id()
Helper function to id from an post or order object.
public
static get_post_or_order_id(WP_Post $post_or_order_object) : int
Parameters
- $post_or_order_object : WP_Post
-
WP_Post/WC_Order object to get ID for.
Return values
int — Order or post ID.get_table_for_order_meta()
Get the name of the database table that's currently in use for orders.
public
static get_table_for_order_meta() : string
Return values
string —get_table_for_orders()
Get the name of the database table that's currently in use for orders.
public
static get_table_for_orders() : string
Return values
string —init_theorder_object()
Helper function to initialize the global $theorder object, mostly used during order meta boxes rendering.
public
static init_theorder_object(WC_Order|WP_Post $post_or_order_object) : bool|WC_Order|WC_Order_Refund
Parameters
- $post_or_order_object : WC_Order|WP_Post
-
Post or order object.
Return values
bool|WC_Order|WC_Order_Refund — WC_Order object.is_custom_order_tables_in_sync()
Checks if posts and order custom table sync is enabled and there are no pending orders.
public
static is_custom_order_tables_in_sync() : bool
Return values
bool —is_new_order_screen()
Check if the current admin screen is adding a new order.
public
static is_new_order_screen([string $order_type = 'shop_order' ]) : bool
Parameters
- $order_type : string = 'shop_order'
-
Optional. The order type to check for. Default shop_order.
Return values
bool —is_order()
Checks if passed id, post or order object is a WC_Order object.
public
static is_order(int|WP_Post|WC_Order $order_id[, array<string|int, string> $types = array('shop_order') ]) : bool
Parameters
- $order_id : int|WP_Post|WC_Order
-
Order ID, post object or order object.
- $types : array<string|int, string> = array('shop_order')
-
Types to match against.
Return values
bool — Whether the passed param is an order.is_order_edit_screen()
Check if the current admin screen is for editing an order.
public
static is_order_edit_screen([string $order_type = 'shop_order' ]) : bool
Parameters
- $order_type : string = 'shop_order'
-
Optional. The order type to check for. Default shop_order.
Return values
bool —is_order_list_table_screen()
Check if the current admin screen is an order list table.
public
static is_order_list_table_screen([string $order_type = 'shop_order' ]) : bool
Parameters
- $order_type : string = 'shop_order'
-
Optional. The order type to check for. Default shop_order.
Return values
bool —orders_cache_usage_is_enabled()
Helper function to get whether the orders cache should be used or not.
public
static orders_cache_usage_is_enabled() : bool
Return values
bool — True if the orders cache should be used, false otherwise.remove_status_prefix()
Removes the 'wc-' prefix from status.
public
static remove_status_prefix(string $status) : string
Parameters
- $status : string
-
The status to remove the prefix from.
Tags
Return values
string — The status without the prefix.unknown_orders_data_store_in_use()
Checks if the data store currently in use for orders is unknown (none of the ones managed by WooCommerce core).
public
static unknown_orders_data_store_in_use() : bool
Return values
bool — True if the data store currently in use for orders is neither the HPOS one nor the CPT one.uses_new_full_refund_data()
Checks if the new full refund data is used.
public
static uses_new_full_refund_data() : bool
