Also delete when order type is placehoder, since it was created by HPOS. (#37287)

This commit is contained in:
Barry Hughes 2023-03-17 05:16:46 -07:00 committed by GitHub
commit b13e56e08f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Also delete when order type is placehoder, since it was created by HPOS.

View File

@ -1790,9 +1790,14 @@ FROM $order_meta_table
$order->set_id( 0 );
// Only delete post data if the posts table is authoritative and synchronization is enabled.
/** We can delete the post data if:
* 1. The HPOS table is authoritative and synchronization is enabled.
* 2. The post record is of type `shop_order_placehold`, since this is created by the HPOS in the first place.
*
* In other words, we do not delete the post record when HPOS table is authoritative and synchronization is disabled but post record is a full record and not just a placeholder, because it implies that the order was created before HPOS was enabled.
*/
$data_synchronizer = wc_get_container()->get( DataSynchronizer::class );
if ( $data_synchronizer->data_sync_is_enabled() && $order->get_data_store()->get_current_class_name() === self::class ) {
if ( $data_synchronizer->data_sync_is_enabled() || get_post_type( $order_id ) === 'shop_order_placehold' ) {
// Delete the associated post, which in turn deletes order items, etc. through {@see WC_Post_Data}.
// Once we stop creating posts for orders, we should do the cleanup here instead.
wp_delete_post( $order_id );