Normalize auto-draft as a status in the abstract order class
Ensures that an existing order with auto-draft status won't be interpreted as pending when determining if the status has changed. This also fixes an unrelated phpcs formatting error in order to pass the precommit checks. Fixes #32539
This commit is contained in:
parent
e9e382adf8
commit
ac1ad607b4
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue