Merge pull request #32571 from woocommerce/fix/32539/order-autodraft-validation

Normalize auto-draft as a status in the abstract order class
This commit is contained in:
Josh Betz 2022-04-13 13:07:55 -05:00 committed by GitHub
commit dc095300c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Ensure that an existing order with auto-draft status won't be interpreted as pending when determining if the status has changed.

View File

@ -201,7 +201,8 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
} catch ( Exception $e ) {
$message_id = $this->get_id() ? $this->get_id() : __( '(no ID)', 'woocommerce' );
$this->handle_exception( $e,
$this->handle_exception(
$e,
wp_kses_post(
sprintf(
/* translators: 1: Order ID or "(no ID)" if not known. */
@ -551,15 +552,17 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
$old_status = $this->get_status();
$new_status = 'wc-' === substr( $new_status, 0, 3 ) ? substr( $new_status, 3 ) : $new_status;
$status_exceptions = array( 'auto-draft', 'trash' );
// If setting the status, ensure it's set to a valid status.
if ( true === $this->object_read ) {
// Only allow valid new status.
if ( ! in_array( 'wc-' . $new_status, $this->get_valid_statuses(), true ) && 'trash' !== $new_status && 'auto-draft' !== $new_status ) {
if ( ! in_array( 'wc-' . $new_status, $this->get_valid_statuses(), true ) && ! in_array( $new_status, $status_exceptions, true ) ) {
$new_status = 'pending';
}
// If the old status is set but unknown (e.g. draft) assume its pending for action usage.
if ( $old_status && ! in_array( 'wc-' . $old_status, $this->get_valid_statuses(), true ) && 'trash' !== $old_status ) {
if ( $old_status && ! in_array( 'wc-' . $old_status, $this->get_valid_statuses(), true ) && ! in_array( $old_status, $status_exceptions, true ) ) {
$old_status = 'pending';
}
}