Automattic\WooCommerce\Internal\DataStores\Orders

DataSynchronizer::maybe_prevent_deletion_of_postpublicWC 8.8.0

Prevents deletion of order backup posts (regardless of sync setting) when HPOS is authoritative and the order still exists in HPOS. This should help with edge cases where wp_delete_post() would delete the HPOS record too or backfill would sync incorrect data from an order with no metadata from the posts table.

Method of the class: DataSynchronizer{}

No Hooks.

Returns

WP_Post|false|null.

Usage

$DataSynchronizer = new DataSynchronizer();
$DataSynchronizer->maybe_prevent_deletion_of_post( $delete, $post );
$delete(WP_Post|false|null) (required)
Whether to go forward with deletion.
$post(WP_Post) (required)
Post object.

Changelog

Since 8.8.0 Introduced.

DataSynchronizer::maybe_prevent_deletion_of_post() code WC 10.3.5

public function maybe_prevent_deletion_of_post( $delete, $post ) {
	if ( self::PLACEHOLDER_ORDER_POST_TYPE !== $post->post_type && $this->custom_orders_table_is_authoritative() && $this->data_store->order_exists( $post->ID ) ) {
		$delete = false;
	}

	return $delete;
}