Merge pull request #13037 from thenbrent/add_wc_order_get_valid_statuses

Add WC_Abstract_Order::get_valid_statuses()
This commit is contained in:
Claudio Sanches 2017-02-01 09:53:36 +01:00 committed by GitHub
commit 73603ac3cc
1 changed files with 12 additions and 2 deletions

View File

@ -447,6 +447,16 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
return apply_filters( 'woocommerce_order_get_tax_totals', $tax_totals, $this );
}
/**
* Get all valid statuses for this order
*
* @since 2.7.0
* @return array Internal status keys e.g. 'wc-processing'
*/
protected function get_valid_statuses() {
return array_keys( wc_get_order_statuses() );
}
/*
|--------------------------------------------------------------------------
| Setters
@ -484,14 +494,14 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
$new_status = 'wc-' === substr( $new_status, 0, 3 ) ? substr( $new_status, 3 ) : $new_status;
// Only allow valid new status
if ( ! in_array( 'wc-' . $new_status, array_keys( wc_get_order_statuses() ) ) ) {
if ( ! in_array( 'wc-' . $new_status, $this->get_valid_statuses() ) ) {
$new_status = 'pending';
}
$this->set_prop( 'status', $new_status );
// 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, array_keys( wc_get_order_statuses() ) ) ) {
if ( $old_status && ! in_array( 'wc-' . $old_status, $this->get_valid_statuses() ) ) {
$old_status = 'pending';
}