Merge pull request #28690 from kevinruscoe/fix/28652

Ensure the orders status is reverted correctly when restoring it.
This commit is contained in:
Roy Ho 2021-01-13 13:54:26 -08:00 committed by GitHub
commit 0d2f478eab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 0 deletions

View File

@ -41,6 +41,7 @@ class WC_Post_Data {
add_filter( 'update_post_metadata', array( __CLASS__, 'update_post_metadata' ), 10, 5 );
add_filter( 'wp_insert_post_data', array( __CLASS__, 'wp_insert_post_data' ) );
add_filter( 'oembed_response_data', array( __CLASS__, 'filter_oembed_response_data' ), 10, 2 );
add_filter( 'wp_untrash_post_status', array( __CLASS__, 'wp_untrash_post_status' ), 10, 3 );
// Status transitions.
add_action( 'transition_post_status', array( __CLASS__, 'transition_post_status' ), 10, 3 );
@ -501,6 +502,24 @@ class WC_Post_Data {
}
}
/**
* Ensure statuses are correctly reassigned when restoring orders and products.
*
* @param string $new_status The new status of the post being restored.
* @param int $post_id The ID of the post being restored.
* @param string $previous_status The status of the post at the point where it was trashed.
* @return string
*/
public static function wp_untrash_post_status( $new_status, $post_id, $previous_status ) {
$post_types = array( 'shop_order', 'shop_coupon', 'product', 'product_variation' );
if ( in_array( get_post_type( $post_id ), $post_types, true ) ) {
$new_status = $previous_status;
}
return $new_status;
}
/**
* When setting stock level, ensure the stock status is kept in sync.
*