WooCommerce Code Reference

WC_Post_Data
in package

Post data class.

Table of Contents

$editing_term  : object
Editing term.
before_delete_order()  : void
Before deleting an order, do some cleanup.
deferred_product_sync()  : void
Sync a product.
delete_order_downloadable_permissions()  : void
Remove downloadable permissions on permanent order deletion.
delete_order_items()  : void
Remove item meta on permanent deletion.
delete_post()  : void
Removes variations etc. belonging to a deleted post, and clears transients, if the user has permission.
delete_product_query_transients()  : void
Delete product view transients when needed e.g. when post status changes, or visibility/stock status is modified.
do_deferred_product_sync()  : void
Sync products queued to sync.
edit_term()  : void
When editing a term, check for product attributes.
edited_term()  : void
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()  : void
Flush meta cache for CRUD objects on direct update.
force_default_term()  : void
Ensure default category gets set.
get_variation_summaries_sync_threshold()  : int
Gets the threshold for synchronous regeneration of variation summaries.
handle_attribute_term_deleted()  : void
Hook called after a term is deleted to handle updates for product variations.
handle_attribute_term_updated()  : void
Hook called after a term is updated to handle updates for product variations.
handle_global_attribute_updated()  : void
Handles updates to a global attribute by triggering variation summary regeneration.
init()  : void
Hook in methods.
on_product_attributes_updated()  : void
Handles regeneration of variation summaries when a variable product's attributes are updated.
process_product_file_download_paths()  : void
Update changed downloads.
product_type_changed()  : void
Handle type changes.
recount_terms_for_product_visibility_change()  : void
Recounts product terms when product visibility changes affect catalog display.
regenerate_attribute_variation_summaries()  : void
Regenerates variation summaries for all variations using a specific attribute taxonomy.
regenerate_product_variation_summaries()  : void
Regenerates variation summaries for all variations of a variable product.
regenerate_term_variation_summaries()  : void
Regenerates variation summaries for all variations using a specific term.
regenerate_variation_attribute_summary()  : void
Regenerates the attribute summary for a single variation.
set_object_terms()  : void
Delete transients when terms are set.
sync_product_stock_status()  : void
When setting stock level, ensure the stock status is kept in sync.
transition_post_status()  : void
When a post status changes.
trash_post()  : void
Trash post.
untrash_post()  : void
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()  : void
Clear global unique id if it's not unique.
get_post_type()  : string
Get the post type for a given post.
regenerate_variation_summaries()  : void
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) : void
Parameters
$order_id : int

Order ID.

Tags
since
3.2.0
Return values
void

deferred_product_sync()

Sync a product.

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

Product ID.

Return values
void

delete_order_downloadable_permissions()

Remove downloadable permissions on permanent order deletion.

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

Post ID.

Return values
void

delete_order_items()

Remove item meta on permanent deletion.

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

Post ID.

Return values
void

delete_post()

Removes variations etc. belonging to a deleted post, and clears transients, if the user has permission.

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

ID of post being deleted.

Return values
void

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() : void
Return values
void

do_deferred_product_sync()

Sync products queued to sync.

public static do_deferred_product_sync() : void
Return values
void

edit_term()

When editing a term, check for product attributes.

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

Term ID.

$tt_id : int

Term taxonomy ID.

$taxonomy : string

Taxonomy slug.

Return values
void

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) : void
Parameters
$term_id : int

Term ID.

$tt_id : int

Term taxonomy ID.

$taxonomy : string

Taxonomy slug.

Return values
void

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) : void
Parameters
$meta_id : int

Meta ID.

$object_id : int

Object ID.

$meta_key : string

Meta key.

$meta_value : mixed

Meta value.

Return values
void

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) : void
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
void

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) : void
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
void

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) : void
Parameters
$term_id : int

Term ID.

$tt_id : int

Term taxonomy ID.

$taxonomy : string

Taxonomy slug.

Return values
void

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) : void
Parameters
$attribute_id : int

Attribute ID.

$attribute : string

Attribute name.

$old_slug : string

Old attribute slug.

Tags
since
10.2.0
Return values
void

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) : void
Parameters
$product : WC_Product

The variable product whose attributes were updated.

Tags
since
10.2.0
Return values
void

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) : void
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
void

product_type_changed()

Handle type changes.

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

Product data.

$from : string

Origin type.

$to : string

New type.

Tags
since
3.0.0
Return values
void

recount_terms_for_product_visibility_change()

Recounts product terms when product visibility changes affect catalog display.

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

The object ID.

$terms : array<string|int, mixed>

An array of object terms.

$tt_ids : array<string|int, mixed>

An array of term taxonomy IDs.

$taxonomy : string

Taxonomy slug.

$append : bool

Whether to append new terms to the old terms.

$old_tt_ids : array<string|int, mixed>

The old array of term taxonomy IDs.

Tags
since
10.4.0
Return values
void

regenerate_attribute_variation_summaries()

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

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

Attribute taxonomy.

Tags
since
10.2.0
Return values
void

regenerate_product_variation_summaries()

Regenerates variation summaries for all variations of a variable product.

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

Variable product ID.

Tags
since
10.2.0
Return values
void

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) : void
Parameters
$taxonomy : string

Taxonomy slug.

$term_slug : string

Term slug.

Tags
since
10.2.0
Return values
void

regenerate_variation_attribute_summary()

Regenerates the attribute summary for a single variation.

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

Variation ID.

Tags
since
10.2.0
Return values
void

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) : void
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
void

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) : void
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
void

transition_post_status()

When a post status changes.

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

New status.

$old_status : string

Old status.

$post : WP_Post

Post data.

Return values
void

trash_post()

Trash post.

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

Post ID.

Return values
void

untrash_post()

Untrash post.

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

Post ID.

Return values
void

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) : void
Parameters
$id : mixed

Post ID.

Return values
void

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) : void
Parameters
$variation_ids : array<string|int, mixed>

Array of variation IDs.

Tags
since
10.2.0
Return values
void

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