diff --git a/plugins/woocommerce/changelog/fix-32539-order-autodraft-validation b/plugins/woocommerce/changelog/fix-32539-order-autodraft-validation new file mode 100644 index 00000000000..d283595b90c --- /dev/null +++ b/plugins/woocommerce/changelog/fix-32539-order-autodraft-validation @@ -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. diff --git a/plugins/woocommerce/includes/abstracts/abstract-wc-order.php b/plugins/woocommerce/includes/abstracts/abstract-wc-order.php index abb2e63fbe9..83d59992a42 100644 --- a/plugins/woocommerce/includes/abstracts/abstract-wc-order.php +++ b/plugins/woocommerce/includes/abstracts/abstract-wc-order.php @@ -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'; } }