WooCommerce Code Reference

Search results

WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implements WC_Object_Data_Store_Interface, WC_Order_Data_Store_Interface

WC Order Data Store: Stored in CPT.

Table of Contents

$internal_meta_keys Data stored in meta keys, but not considered "meta" for an order. array
$meta_type Meta type. This should match up with the types available at https://developer.wordpress.org/reference/functions/add_metadata/. string
$internal_meta_keys Data stored in meta keys, but not considered "meta" for an object. array
$object_id_field_for_meta This only needs set if you are using a custom metadata type (for example payment tokens. string
$must_exist_meta_keys Meta data which should exist in the DB, even if empty. array
create() Method to create a new order in the database. mixed
read_order_data() Read order data. Can be overridden by child classes to load other props. mixed
update() Method to update an order in the database. mixed
update_post_meta() Helper method that updates all the post meta for an order based on it's settings in the WC_Order class. mixed
get_post_excerpt() Excerpt for post. string
get_order_key() Get order key. string
get_total_refunded() Get amount already refunded. float
get_total_tax_refunded() Get the total tax refunded. float
get_total_shipping_refunded() Get the total shipping refunded. float
get_order_id_by_order_key() Finds an Order ID based on an order key. int
get_order_count() Return count of orders with a specific status. int
get_orders() Get all orders matching the passed in args. array|object
get_orders_generate_customer_meta_query() Generate meta query for wc_get_orders. array
get_unpaid_orders() Get unpaid orders after a certain date, array
search_orders() Search order data for a term and return ids. array
get_download_permissions_granted() Gets information about whether permissions were generated yet. bool
set_download_permissions_granted() Stores information about whether permissions were generated yet. mixed
get_recorded_sales() Gets information about whether sales were recorded. bool
set_recorded_sales() Stores information about whether sales were recorded. mixed
get_recorded_coupon_usage_counts() Gets information about whether coupon counts were updated. bool
set_recorded_coupon_usage_counts() Stores information about whether coupon counts were updated. mixed
get_coupon_held_keys() Return array of coupon_code => meta_key for coupon which have usage limit and have tentative keys. array|string
get_coupon_held_keys_for_users() Return array of coupon_code => meta_key for coupon which have usage limit per customer and have tentative keys. mixed
set_coupon_held_keys() Add/Update list of meta keys that are currently being used by this order to hold a coupon. mixed
release_held_coupons() Release all coupons held by this order. mixed
get_stock_reduced() Gets information about whether stock was reduced. bool
set_stock_reduced() Stores information about whether stock was reduced. mixed
get_order_type() Get the order type based on Order ID. string
get_wp_query_args() Get valid WP_Query args from a WC_Order_Query's query variables. array
query() Query for Orders matching specific criteria. array|object
get_order_item_type() Return the order type of a given item which belongs to WC_Order. string
create() Method to create a new order in the database. mixed
read() Method to read an order from the database. mixed
update() Method to update an order in the database. mixed
delete() Method to delete an order from the database. void
get_post_status() Get the status to save to the post object. string
get_post_excerpt() Excerpt for post. string
get_post_title() Get a title for the new post type. string
get_order_key() Get order key. string
read_order_data() Read order data. Can be overridden by child classes to load other props. mixed
update_post_meta() Helper method that updates all the post meta for an order based on it's settings in the WC_Order class. mixed
clear_caches() Clear any caches. mixed
read_items() Read order items of a specific type from the database for this order. array
delete_items() Remove all line items (products, coupons, shipping, taxes) from the order. mixed
get_payment_token_ids() Get token ids for an order. array
update_payment_token_ids() Update token ids for an order. mixed
get_term_ids() Get and store terms from a taxonomy. array
read_meta() Returns an array of meta for an object. array
delete_meta() Deletes meta based on meta ID. mixed
add_meta() Add new piece of meta. int
update_meta() Update meta. mixed
get_db_info() Table structure is slightly different between meta types, this function will return what we need to know. array
prefix_key() Internal meta keys we don't want exposed as part of meta_data. This is in addition to all data props with _ prefix. string
exclude_internal_meta_keys() Callback to remove unwanted meta data. bool
get_props_to_update() Gets a list of props and meta keys that need updated based on change state or if they are present in the database or not. array
update_or_delete_post_meta() Update meta data in, or delete it from, the database. bool
get_wp_query_args() Get valid WP_Query args from a WC_Object_Query's query variables. array
parse_date_for_wp_query() Map a valid date query var to WP_Query arguments. array
get_internal_meta_keys() Return list of internal meta keys. array
get_valid_search_terms() Check if the terms are suitable for searching. array
get_search_stopwords() Retrieve stopwords used when parsing search terms. array
get_data_for_lookup_table() Get data to save to a lookup table. array
get_primary_key_for_lookup_table() Get primary key name for lookup table. string
update_lookup_table() Update a lookup table for an object. null
delete_from_lookup_table() Delete lookup table data for an ID. mixed

Properties

$internal_meta_keys

Data stored in meta keys, but not considered "meta" for an order.

protected array $internal_meta_keys = array('_customer_user', '_order_key', '_order_currency', '_billing_first_name', '_billing_last_name', '_billing_company', '_billing_address_1', '_billing_address_2', '_billing_city', '_billing_state', '_billing_postcode', '_billing_country', '_billing_email', '_billing_phone', '_shipping_first_name', '_shipping_last_name', '_shipping_company', '_shipping_address_1', '_shipping_address_2', '_shipping_city', '_shipping_state', '_shipping_postcode', '_shipping_country', '_completed_date', '_paid_date', '_edit_lock', '_edit_last', '_cart_discount', '_cart_discount_tax', '_order_shipping', '_order_shipping_tax', '_order_tax', '_order_total', '_payment_method', '_payment_method_title', '_transaction_id', '_customer_ip_address', '_customer_user_agent', '_created_via', '_order_version', '_prices_include_tax', '_date_completed', '_date_paid', '_payment_tokens', '_billing_address_index', '_shipping_address_index', '_recorded_sales', '_recorded_coupon_usage_counts', '_download_permissions_granted', '_order_stock_reduced')

$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 = 'post'
WP defines 'post', 'user', 'comment', and 'term'.

$internal_meta_keys

Data stored in meta keys, but not considered "meta" for an object.

protected array $internal_meta_keys = array()

$object_id_field_for_meta

This only needs set if you are using a custom metadata type (for example payment tokens.

protected string $object_id_field_for_meta = ''
This should be the name of the field your table uses for associating meta with objects. For example, in payment_tokenmeta, this would be payment_token_id.

$must_exist_meta_keys

Meta data which should exist in the DB, even if empty.

protected array $must_exist_meta_keys = array()

Methods

read_order_data()

Read order data. Can be overridden by child classes to load other props.

protected read_order_data( &$order : WC_Order , $post_object : object ) : mixed
Parameters
$order : WC_Order

Order object.

$post_object : object

Post object.

Tags
since
Return values
mixed

update_post_meta()

Helper method that updates all the post meta for an order based on it's settings in the WC_Order class.

protected update_post_meta( &$order : WC_Order ) : mixed
Parameters
$order : WC_Order

Order object.

Tags
since
Return values
mixed

get_order_key()

Get order key.

protected get_order_key( $order : WC_order ) : string
Parameters
$order : WC_order

Order object.

Tags
since
Return values
string

get_order_id_by_order_key()

Finds an Order ID based on an order key.

public get_order_id_by_order_key( $order_key : string ) : int
Parameters
$order_key : string

An order key has generated by.

Return values
int

The ID of an order, or 0 if the order could not be found

get_order_count()

Return count of orders with a specific status.

public get_order_count( $status : string ) : int
Parameters
$status : string

Order status. Function wc_get_order_statuses() returns a list of valid statuses.

Return values
int

get_orders()

Get all orders matching the passed in args.

public get_orders( [ $args : array = array() ] ) : array|object
Parameters
$args : array = array()

List of args passed to wc_get_orders().

Tags
deprecated
  • Use wc_get_orders instead.
see
Return values
array|object

get_orders_generate_customer_meta_query()

Generate meta query for wc_get_orders.

private get_orders_generate_customer_meta_query( $values : array [, $relation : string = 'or' ] ) : array
Parameters
$values : array

List of customers ids or emails.

$relation : string = 'or'

'or' or 'and' relation used to build the WP meta_query.

Return values
array

get_unpaid_orders()

Get unpaid orders after a certain date,

public get_unpaid_orders( $date : int ) : array
Parameters
$date : int

Timestamp.

Return values
array

search_orders()

Search order data for a term and return ids.

public search_orders( $term : string ) : array
Parameters
$term : string

Searched term.

Return values
array

of ids

get_download_permissions_granted()

Gets information about whether permissions were generated yet.

public get_download_permissions_granted( $order : WC_Order|int ) : bool
Parameters
$order : WC_Order|int

Order ID or order object.

Return values
bool

set_download_permissions_granted()

Stores information about whether permissions were generated yet.

public set_download_permissions_granted( $order : WC_Order|int , $set : bool ) : mixed
Parameters
$order : WC_Order|int

Order ID or order object.

$set : bool

True or false.

Return values
mixed

get_recorded_sales()

Gets information about whether sales were recorded.

public get_recorded_sales( $order : WC_Order|int ) : bool
Parameters
$order : WC_Order|int

Order ID or order object.

Return values
bool

set_recorded_sales()

Stores information about whether sales were recorded.

public set_recorded_sales( $order : WC_Order|int , $set : bool ) : mixed
Parameters
$order : WC_Order|int

Order ID or order object.

$set : bool

True or false.

Return values
mixed

get_recorded_coupon_usage_counts()

Gets information about whether coupon counts were updated.

public get_recorded_coupon_usage_counts( $order : WC_Order|int ) : bool
Parameters
$order : WC_Order|int

Order ID or order object.

Return values
bool

set_recorded_coupon_usage_counts()

Stores information about whether coupon counts were updated.

public set_recorded_coupon_usage_counts( $order : WC_Order|int , $set : bool ) : mixed
Parameters
$order : WC_Order|int

Order ID or order object.

$set : bool

True or false.

Return values
mixed

get_coupon_held_keys()

Return array of coupon_code => meta_key for coupon which have usage limit and have tentative keys.

public get_coupon_held_keys( $order : WC_Order [, $coupon_id : int = null ] ) : array|string

Pass $coupon_id if key for only one of the coupon is needed.

Parameters
$order : WC_Order

Order object.

$coupon_id : int = null

If passed, will return held key for that coupon.

Return values
array|string

Key value pair for coupon code and meta key name. If $coupon_id is passed, returns meta_key for only that coupon.

get_coupon_held_keys_for_users()

Return array of coupon_code => meta_key for coupon which have usage limit per customer and have tentative keys.

public get_coupon_held_keys_for_users( $order : WC_Order [, $coupon_id : int = null ] ) : mixed
Parameters
$order : WC_Order

Order object.

$coupon_id : int = null

If passed, will return held key for that coupon.

Return values
mixed

set_coupon_held_keys()

Add/Update list of meta keys that are currently being used by this order to hold a coupon.

public set_coupon_held_keys( $order : WC_Order , $held_keys : array , $held_keys_for_user : array ) : mixed

This is used to figure out what all meta entries we should delete when order is cancelled/completed.

Parameters
$order : WC_Order

Order object.

$held_keys : array

Array of coupon_code => meta_key.

$held_keys_for_user : array

Array of coupon_code => meta_key for held coupon for user.

Return values
mixed

release_held_coupons()

Release all coupons held by this order.

public release_held_coupons( $order : WC_Order [, $save : bool = true ] ) : mixed
Parameters
$order : WC_Order

Current order object.

$save : bool = true

Whether to delete keys from DB right away. Could be useful to pass false if you are building a bulk request.

Return values
mixed

get_stock_reduced()

Gets information about whether stock was reduced.

public get_stock_reduced( $order : WC_Order|int ) : bool
Parameters
$order : WC_Order|int

Order ID or order object.

Return values
bool

set_stock_reduced()

Stores information about whether stock was reduced.

public set_stock_reduced( $order : WC_Order|int , $set : bool ) : mixed
Parameters
$order : WC_Order|int

Order ID or order object.

$set : bool

True or false.

Return values
mixed

get_order_type()

Get the order type based on Order ID.

public get_order_type( $order_id : int ) : string
Parameters
$order_id : int

Order ID.

Tags
since
Return values
string

get_wp_query_args()

Get valid WP_Query args from a WC_Order_Query's query variables.

protected get_wp_query_args( $query_vars : array ) : array
Parameters
$query_vars : array

query vars from a WC_Order_Query.

Tags
since
Return values
array

query()

Query for Orders matching specific criteria.

public query( $query_vars : array ) : array|object
Parameters
$query_vars : array

query vars from a WC_Order_Query.

Tags
since
Return values
array|object

get_order_item_type()

Return the order type of a given item which belongs to WC_Order.

public get_order_item_type( $order : WC_Order , $order_item_id : int ) : string
Parameters
$order : WC_Order

Order Object.

$order_item_id : int

Order item id.

Tags
since
Return values
string

Order Item type

delete()

Method to delete an order from the database.

public delete( &$order : WC_Order [, $args : array = array() ] ) : void
Parameters
$order : WC_Order

Order object.

$args : array = array()

Array of args to pass to the delete method.

get_post_status()

Get the status to save to the post object.

protected get_post_status( $order : WC_order ) : string

Plugins extending the order classes can override this to change the stored status/add prefixes etc.

Parameters
$order : WC_order

Order object.

Tags
since
Return values
string

get_post_excerpt()

Excerpt for post.

protected get_post_excerpt( $order : WC_order ) : string
Parameters
$order : WC_order

Order object.

Return values
string

get_order_key()

Get order key.

protected get_order_key( $order : WC_order ) : string
Parameters
$order : WC_order

Order object.

Tags
since
Return values
string

read_order_data()

Read order data. Can be overridden by child classes to load other props.

protected read_order_data( &$order : WC_Order , $post_object : object ) : mixed
Parameters
$order : WC_Order

Order object.

$post_object : object

Post object.

Tags
since
Return values
mixed

update_post_meta()

Helper method that updates all the post meta for an order based on it's settings in the WC_Order class.

protected update_post_meta( &$order : WC_Order ) : mixed
Parameters
$order : WC_Order

Order object.

Tags
since
Return values
mixed

read_items()

Read order items of a specific type from the database for this order.

public read_items( $order : WC_Order , $type : string ) : array
Parameters
$order : WC_Order

Order object.

$type : string

Order item type.

Return values
array

delete_items()

Remove all line items (products, coupons, shipping, taxes) from the order.

public delete_items( $order : WC_Order [, $type : string = null ] ) : mixed
Parameters
$order : WC_Order

Order object.

$type : string = null

Order item type. Default null.

Return values
mixed

update_payment_token_ids()

Update token ids for an order.

public update_payment_token_ids( $order : WC_Order , $token_ids : array ) : mixed
Parameters
$order : WC_Order

Order object.

$token_ids : array

Payment token ids.

Return values
mixed

get_term_ids()

Get and store terms from a taxonomy.

protected get_term_ids( $object : WC_Data|int , $taxonomy : string ) : array
Parameters
$object : WC_Data|int

WC_Data object or object ID.

$taxonomy : string

Taxonomy name e.g. product_cat.

Tags
since
Return values
array

of terms

read_meta()

Returns an array of meta for an object.

public read_meta( &$object : WC_Data ) : array
Parameters
$object : WC_Data

WC_Data object.

Tags
since
Return values
array

delete_meta()

Deletes meta based on meta ID.

public delete_meta( &$object : WC_Data , $meta : stdClass ) : mixed
Parameters
$object : WC_Data

WC_Data object.

$meta : stdClass

(containing at least ->id).

Tags
since
Return values
mixed

add_meta()

Add new piece of meta.

public add_meta( &$object : WC_Data , $meta : stdClass ) : int
Parameters
$object : WC_Data

WC_Data object.

$meta : stdClass

(containing ->key and ->value).

Tags
since
Return values
int

meta ID

update_meta()

Update meta.

public update_meta( &$object : WC_Data , $meta : stdClass ) : mixed
Parameters
$object : WC_Data

WC_Data object.

$meta : stdClass

(containing ->id, ->key and ->value).

Tags
since
Return values
mixed

get_db_info()

Table structure is slightly different between meta types, this function will return what we need to know.

protected get_db_info( ) : array
Tags
since
Return values
array

Array elements: table, object_id_field, meta_id_field

prefix_key()

Internal meta keys we don't want exposed as part of meta_data. This is in addition to all data props with _ prefix.

protected prefix_key( $key : string ) : string
Parameters
$key : string

Prefix to be added to meta keys.

Tags
since
Return values
string

exclude_internal_meta_keys()

Callback to remove unwanted meta data.

protected exclude_internal_meta_keys( $meta : object ) : bool
Parameters
$meta : object

Meta object to check if it should be excluded or not.

Return values
bool

get_props_to_update()

Gets a list of props and meta keys that need updated based on change state or if they are present in the database or not.

protected get_props_to_update( $object : WC_Data , $meta_key_to_props : array [, $meta_type : string = 'post' ] ) : array
Parameters
$object : WC_Data

The WP_Data object (WC_Coupon for coupons, etc).

$meta_key_to_props : array

A mapping of meta keys => prop names.

$meta_type : string = 'post'

The internal WP meta type (post, user, etc).

Return values
array

A mapping of meta keys => prop names, filtered by ones that should be updated.

update_or_delete_post_meta()

Update meta data in, or delete it from, the database.

protected update_or_delete_post_meta( $object : WC_Data , $meta_key : string , $meta_value : mixed ) : bool

Avoids storing meta when it's either an empty string or empty array. Other empty values such as numeric 0 and null should still be stored. Data-stores can force meta to exist using must_exist_meta_keys.

Note: WordPress get_metadata function returns an empty string when meta data does not exist.

Parameters
$object : WC_Data

The WP_Data object (WC_Coupon for coupons, etc).

$meta_key : string

Meta key to update.

$meta_value : mixed

Value to save.

Tags
since

Added to prevent empty meta being stored unless required.

Return values
bool

True if updated/deleted.

get_wp_query_args()

Get valid WP_Query args from a WC_Object_Query's query variables.

protected get_wp_query_args( $query_vars : array ) : array
Parameters
$query_vars : array

query vars from a WC_Object_Query.

Tags
since
Return values
array

parse_date_for_wp_query()

Map a valid date query var to WP_Query arguments.

public parse_date_for_wp_query( $query_var : mixed , $key : string [, $wp_query_args : array = array() ] ) : array

Valid date formats: YYYY-MM-DD or timestamp, possibly combined with an operator from $valid_operators. Also accepts a WC_DateTime object.

Parameters
$query_var : mixed

A valid date format.

$key : string

meta or db column key.

$wp_query_args : array = array()

WP_Query args.

Tags
since
Return values
array

Modified $wp_query_args

get_internal_meta_keys()

Return list of internal meta keys.

public get_internal_meta_keys( ) : array
Tags
since
Return values
array

get_valid_search_terms()

Check if the terms are suitable for searching.

protected get_valid_search_terms( $terms : array ) : array

Uses an array of stopwords (terms) that are excluded from the separate term matching when searching for posts. The list of English stopwords is the approximate search engines list, and is translatable.

Parameters
$terms : array

Terms to check.

Tags
since
Return values
array

Terms that are not stopwords.

get_search_stopwords()

Retrieve stopwords used when parsing search terms.

protected get_search_stopwords( ) : array
Tags
since
Return values
array

Stopwords.

get_data_for_lookup_table()

Get data to save to a lookup table.

protected get_data_for_lookup_table( $id : int , $table : string ) : array
Parameters
$id : int

ID of object to update.

$table : string

Lookup table name.

Tags
since
Return values
array

get_primary_key_for_lookup_table()

Get primary key name for lookup table.

protected get_primary_key_for_lookup_table( $table : string ) : string
Parameters
$table : string

Lookup table name.

Tags
since
Return values
string

update_lookup_table()

Update a lookup table for an object.

protected update_lookup_table( $id : int , $table : string ) : null
Parameters
$id : int

ID of object to update.

$table : string

Lookup table name.

Tags
since
Return values
null

delete_from_lookup_table()

Delete lookup table data for an ID.

public delete_from_lookup_table( $id : int , $table : string ) : mixed
Parameters
$id : int

ID of object to update.

$table : string

Lookup table name.

Tags
since
Return values
mixed
Back to the top