WC_Order::set_status PHP Method

set_status() public method

Set order status.
Since: 2.7.0
public set_status ( string $new_status, string $note = '', boolean $manual_update = false )
$new_status string Status to change the order to. No internal wc- prefix is required.
$note string (default: '') Optional note to add.
$manual_update boolean is this a manual order status change?
    public function set_status($new_status, $note = '', $manual_update = false)
    {
        $result = parent::set_status($new_status);
        if (!empty($result['from']) && $result['from'] !== $result['to']) {
            $this->status_transition = array('from' => !empty($this->status_transition['from']) ? $this->status_transition['from'] : $result['from'], 'to' => $result['to'], 'note' => $note, 'manual' => (bool) $manual_update);
            if ('pending' === $result['from'] && !$manual_update) {
                $this->set_date_paid(current_time('timestamp'));
            }
            if ('completed' === $result['to']) {
                $this->set_date_completed(current_time('timestamp'));
            }
        }
        return $result;
    }

Usage Example

Beispiel #1
0
 /**
  * Test: needs_payment
  */
 function test_needs_payment()
 {
     $object = new WC_Order();
     $object->set_status('pending');
     $this->assertFalse($object->needs_payment());
     $object->set_total(100);
     $this->assertTrue($object->needs_payment());
     $object->set_status('processing');
     $this->assertFalse($object->needs_payment());
 }
All Usage Examples Of WC_Order::set_status
WC_Order