Automattic\WooCommerce\Internal\DataStores\Orders

DataSynchronizer::maybe_prevent_deletion_of_post()privateWC 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.

Return

WP_Post|false|null.

Usage

// private - for code of main (parent) class only
$result = $this->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 9.3.3

private 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;
}