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, if the user has permission.
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.
get_variation_summaries_sync_threshold()  : int
Gets the threshold for synchronous regeneration of variation summaries.
handle_attribute_term_deleted()  : mixed
Hook called after a term is deleted to handle updates for product variations.
handle_attribute_term_updated()  : mixed
Hook called after a term is updated to handle updates for product variations.
handle_global_attribute_updated()  : mixed
Handles updates to a global attribute by triggering variation summary regeneration.
init()  : mixed
Hook in methods.
on_product_attributes_updated()  : mixed
Handles regeneration of variation summaries when a variable product's attributes are updated.
process_product_file_download_paths()  : mixed
Update changed downloads.
product_type_changed()  : mixed
Handle type changes.
regenerate_attribute_variation_summaries()  : mixed
Regenerates variation summaries for all variations using a specific attribute taxonomy.
regenerate_product_variation_summaries()  : mixed
Regenerates variation summaries for all variations of a variable product.
regenerate_term_variation_summaries()  : mixed
Regenerates variation summaries for all variations using a specific term.
regenerate_variation_attribute_summary()  : mixed
Regenerates the attribute summary for a single variation.
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.
clear_global_unique_id_if_necessary()  : mixed
Clear global unique id if it's not unique.
get_post_type()  : string
Get the post type for a given post.
regenerate_variation_summaries()  : mixed
Regenerates attribute summaries for a list of variations.
schedule_variation_summary_regeneration()  : void
Schedule an asynchronous action to regenerate product variation summaries.

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, if the user has permission.

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

get_variation_summaries_sync_threshold()

Gets the threshold for synchronous regeneration of variation summaries.

public static get_variation_summaries_sync_threshold() : int
Tags
since
10.2.0
Return values
int

handle_attribute_term_deleted()

Hook called after a term is deleted to handle updates for product variations.

public static handle_attribute_term_deleted(int $term_id, int $tt_id, string $taxonomy, WP_Term $deleted_term) : mixed
Parameters
$term_id : int

Term ID.

$tt_id : int

Term taxonomy ID.

$taxonomy : string

Taxonomy slug.

$deleted_term : WP_Term

Copy of the already-deleted term.

Return values
mixed

handle_attribute_term_updated()

Hook called after a term is updated to handle updates for product variations.

public static handle_attribute_term_updated(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

handle_global_attribute_updated()

Handles updates to a global attribute by triggering variation summary regeneration.

public static handle_global_attribute_updated(int $attribute_id, string $attribute, string $old_slug) : mixed
Parameters
$attribute_id : int

Attribute ID.

$attribute : string

Attribute name.

$old_slug : string

Old attribute slug.

Tags
since
10.2.0
Return values
mixed

on_product_attributes_updated()

Handles regeneration of variation summaries when a variable product's attributes are updated.

public static on_product_attributes_updated(WC_Product $product) : mixed
Parameters
$product : WC_Product

The variable product whose attributes were updated.

Tags
since
10.2.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

regenerate_attribute_variation_summaries()

Regenerates variation summaries for all variations using a specific attribute taxonomy.

public static regenerate_attribute_variation_summaries(string $taxonomy) : mixed
Parameters
$taxonomy : string

Attribute taxonomy.

Tags
since
10.2.0
Return values
mixed

regenerate_product_variation_summaries()

Regenerates variation summaries for all variations of a variable product.

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

Variable product ID.

Tags
since
10.2.0
Return values
mixed

regenerate_term_variation_summaries()

Regenerates variation summaries for all variations using a specific term.

public static regenerate_term_variation_summaries(string $taxonomy, string $term_slug) : mixed
Parameters
$taxonomy : string

Taxonomy slug.

$term_slug : string

Term slug.

Tags
since
10.2.0
Return values
mixed

regenerate_variation_attribute_summary()

Regenerates the attribute summary for a single variation.

public static regenerate_variation_attribute_summary(int $variation_id) : mixed
Parameters
$variation_id : int

Variation ID.

Tags
since
10.2.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

clear_global_unique_id_if_necessary()

Clear global unique id if it's not unique.

private static clear_global_unique_id_if_necessary(mixed $id) : mixed
Parameters
$id : mixed

Post ID.

Return values
mixed

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.

regenerate_variation_summaries()

Regenerates attribute summaries for a list of variations.

private static regenerate_variation_summaries(array<string|int, mixed> $variation_ids) : mixed
Parameters
$variation_ids : array<string|int, mixed>

Array of variation IDs.

Tags
since
10.2.0
Return values
mixed

schedule_variation_summary_regeneration()

Schedule an asynchronous action to regenerate product variation summaries.

private static schedule_variation_summary_regeneration(string $action_name, array<string|int, mixed> $args, string $warning_message[, string $group = 'woocommerce' ]) : void

This method uses the WooCommerce Action Scheduler to queue a single regeneration action for product variation summaries. It first checks whether an identical action with the given arguments is already scheduled to avoid duplicate jobs. If the Action Scheduler is not available, a warning is logged instead.

Parameters
$action_name : string

The name/identifier of the scheduled action (hook name).

$args : array<string|int, mixed>

Arguments to pass to the scheduled action callback.

$warning_message : string

Message to log when the Action Scheduler is unavailable.

$group : string = 'woocommerce'

Optional. The Action Scheduler group to associate with the scheduled action. Default 'woocommerce'.

Return values
void