WooCommerce Code Reference

WC_Post_Data
in package

Post data class.

Table of Contents

$editing_term  : object
Editing term.
before_delete_order()  : mixed
Before deleting an order, do some cleanup.
deferred_product_sync()  : mixed
Sync a product.
delete_order_downloadable_permissions()  : mixed
Remove downloadable permissions on permanent order deletion.
delete_order_items()  : mixed
Remove item meta on permanent deletion.
delete_post()  : mixed
Removes variations etc belonging to a deleted post, and clears transients.
delete_product_query_transients()  : mixed
Delete product view transients when needed e.g. when post status changes, or visibility/stock status is modified.
do_deferred_product_sync()  : mixed
Sync products queued to sync.
edit_term()  : mixed
When editing a term, check for product attributes.
edited_term()  : mixed
When a term is edited, check for product attributes and update variations.
filter_oembed_response_data()  : array<string|int, mixed>
Change embed data for certain post types.
flush_object_meta_cache()  : mixed
Flush meta cache for CRUD objects on direct update.
force_default_term()  : mixed
Ensure default category gets set.
init()  : mixed
Hook in methods.
process_product_file_download_paths()  : mixed
Update changed downloads.
product_type_changed()  : mixed
Handle type changes.
set_object_terms()  : mixed
Delete transients when terms are set.
sync_product_stock_status()  : mixed
When setting stock level, ensure the stock status is kept in sync.
transition_post_status()  : mixed
When a post status changes.
trash_post()  : mixed
Trash post.
untrash_post()  : mixed
Untrash post.
update_order_item_metadata()  : null|bool
Ensure floats are correctly converted to strings based on PHP locale.
update_post_metadata()  : null|bool
Ensure floats are correctly converted to strings based on PHP locale.
variation_post_link()  : string
Link to parent products when getting permalink for variation.
wp_insert_post_data()  : array<string|int, mixed>
Forces the order posts to have a title in a certain format (containing the date).
wp_untrash_post_status()  : string
Ensure statuses are correctly reassigned when restoring orders and products.
get_post_type()  : string
Get the post type for a given post.

Properties

Methods

before_delete_order()

Before deleting an order, do some cleanup.

public static before_delete_order(int $order_id) : mixed
Parameters
$order_id : int

Order ID.

Tags
since
3.2.0
Return values
mixed

deferred_product_sync()

Sync a product.

public static deferred_product_sync(int $product_id) : mixed
Parameters
$product_id : int

Product ID.

Return values
mixed

delete_order_downloadable_permissions()

Remove downloadable permissions on permanent order deletion.

public static delete_order_downloadable_permissions(int $postid) : mixed
Parameters
$postid : int

Post ID.

Return values
mixed

delete_order_items()

Remove item meta on permanent deletion.

public static delete_order_items(int $postid) : mixed
Parameters
$postid : int

Post ID.

Return values
mixed

delete_post()

Removes variations etc belonging to a deleted post, and clears transients.

public static delete_post(mixed $id) : mixed
Parameters
$id : mixed

ID of post being deleted.

Return values
mixed

delete_product_query_transients()

Delete product view transients when needed e.g. when post status changes, or visibility/stock status is modified.

public static delete_product_query_transients() : mixed
Return values
mixed

do_deferred_product_sync()

Sync products queued to sync.

public static do_deferred_product_sync() : mixed
Return values
mixed

edit_term()

When editing a term, check for product attributes.

public static edit_term(int $term_id, int $tt_id, string $taxonomy) : mixed
Parameters
$term_id : int

Term ID.

$tt_id : int

Term taxonomy ID.

$taxonomy : string

Taxonomy slug.

Return values
mixed

edited_term()

When a term is edited, check for product attributes and update variations.

public static edited_term(int $term_id, int $tt_id, string $taxonomy) : mixed
Parameters
$term_id : int

Term ID.

$tt_id : int

Term taxonomy ID.

$taxonomy : string

Taxonomy slug.

Return values
mixed

filter_oembed_response_data()

Change embed data for certain post types.

public static filter_oembed_response_data(array<string|int, mixed> $data, WP_Post $post) : array<string|int, mixed>
Parameters
$data : array<string|int, mixed>

The response data.

$post : WP_Post

The post object.

Tags
since
3.2.0
Return values
array<string|int, mixed>

flush_object_meta_cache()

Flush meta cache for CRUD objects on direct update.

public static flush_object_meta_cache(int $meta_id, int $object_id, string $meta_key, mixed $meta_value) : mixed
Parameters
$meta_id : int

Meta ID.

$object_id : int

Object ID.

$meta_key : string

Meta key.

$meta_value : mixed

Meta value.

Return values
mixed

force_default_term()

Ensure default category gets set.

public static force_default_term(int $object_id, array<string|int, mixed> $terms, array<string|int, mixed> $tt_ids, string $taxonomy, bool $append) : mixed
Parameters
$object_id : int

Product ID.

$terms : array<string|int, mixed>

Terms array.

$tt_ids : array<string|int, mixed>

Term ids array.

$taxonomy : string

Taxonomy name.

$append : bool

Are we appending or setting terms.

Tags
since
3.3.0
Return values
mixed

process_product_file_download_paths()

Update changed downloads.

public static process_product_file_download_paths(int $product_id, int $variation_id, array<string|int, mixed> $downloads) : mixed
Parameters
$product_id : int

Product ID.

$variation_id : int

Variation ID. Optional product variation identifier.

$downloads : array<string|int, mixed>

Newly set files.

Tags
deprecated
3.3.0

No action is necessary on changes to download paths since download_id is no longer based on file hash.

Return values
mixed

product_type_changed()

Handle type changes.

public static product_type_changed(WC_Product $product, string $from, string $to) : mixed
Parameters
$product : WC_Product

Product data.

$from : string

Origin type.

$to : string

New type.

Tags
since
3.0.0
Return values
mixed

set_object_terms()

Delete transients when terms are set.

public static set_object_terms(int $object_id, mixed $terms, array<string|int, mixed> $tt_ids, string $taxonomy, mixed $append, array<string|int, mixed> $old_tt_ids) : mixed
Parameters
$object_id : int

Object ID.

$terms : mixed

An array of object terms.

$tt_ids : array<string|int, mixed>

An array of term taxonomy IDs.

$taxonomy : string

Taxonomy slug.

$append : mixed

Whether to append new terms to the old terms.

$old_tt_ids : array<string|int, mixed>

Old array of term taxonomy IDs.

Tags
deprecated
3.6
Return values
mixed

sync_product_stock_status()

When setting stock level, ensure the stock status is kept in sync.

public static sync_product_stock_status(int $meta_id, int $object_id, string $meta_key, mixed $meta_value) : mixed
Parameters
$meta_id : int

Meta ID.

$object_id : int

Object ID.

$meta_key : string

Meta key.

$meta_value : mixed

Meta value.

Tags
deprecated
3.3
Return values
mixed

transition_post_status()

When a post status changes.

public static transition_post_status(string $new_status, string $old_status, WP_Post $post) : mixed
Parameters
$new_status : string

New status.

$old_status : string

Old status.

$post : WP_Post

Post data.

Return values
mixed

trash_post()

Trash post.

public static trash_post(mixed $id) : mixed
Parameters
$id : mixed

Post ID.

Return values
mixed

untrash_post()

Untrash post.

public static untrash_post(mixed $id) : mixed
Parameters
$id : mixed

Post ID.

Return values
mixed

update_order_item_metadata()

Ensure floats are correctly converted to strings based on PHP locale.

public static update_order_item_metadata(null $check, int $object_id, string $meta_key, mixed $meta_value, mixed $prev_value) : null|bool
Parameters
$check : null

Whether to allow updating metadata for the given type.

$object_id : int

Object ID.

$meta_key : string

Meta key.

$meta_value : mixed

Meta value. Must be serializable if non-scalar.

$prev_value : mixed

If specified, only update existing metadata entries with the specified value. Otherwise, update all entries.

Return values
null|bool

update_post_metadata()

Ensure floats are correctly converted to strings based on PHP locale.

public static update_post_metadata(null $check, int $object_id, string $meta_key, mixed $meta_value, mixed $prev_value) : null|bool
Parameters
$check : null

Whether to allow updating metadata for the given type.

$object_id : int

Object ID.

$meta_key : string

Meta key.

$meta_value : mixed

Meta value. Must be serializable if non-scalar.

$prev_value : mixed

If specified, only update existing metadata entries with the specified value. Otherwise, update all entries.

Return values
null|bool

variation_post_link()

Link to parent products when getting permalink for variation.

public static variation_post_link(string $permalink, WP_Post $post) : string
Parameters
$permalink : string

Permalink.

$post : WP_Post

Post data.

Return values
string

wp_insert_post_data()

Forces the order posts to have a title in a certain format (containing the date).

public static wp_insert_post_data(array<string|int, mixed> $data) : array<string|int, mixed>

Forces certain product data based on the product's type, e.g. grouped products cannot have a parent.

Parameters
$data : array<string|int, mixed>

An array of slashed post data.

Return values
array<string|int, mixed>

wp_untrash_post_status()

Ensure statuses are correctly reassigned when restoring orders and products.

public static wp_untrash_post_status(string $new_status, int $post_id, string $previous_status) : string
Parameters
$new_status : string

The new status of the post being restored.

$post_id : int

The ID of the post being restored.

$previous_status : string

The status of the post at the point where it was trashed.

Return values
string

get_post_type()

Get the post type for a given post.

private static get_post_type(int $id) : string
Parameters
$id : int

The post id.

Return values
stringThe post type.