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?
Example #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());
 }
/**
 * Create a new order programmatically.
 *
 * Returns a new order object on success which can then be used to add additional data.
 *
 * @param  array $args
 * @return WC_Order
 */
function wc_create_order($args = array())
{
    $default_args = array('status' => null, 'customer_id' => null, 'customer_note' => null, 'parent' => null, 'created_via' => null, 'cart_hash' => null, 'order_id' => 0);
    $args = wp_parse_args($args, $default_args);
    $order = new WC_Order($args['order_id']);
    // Update props that were set (not null)
    if (!is_null($args['parent'])) {
        $order->set_parent_id(absint($args['parent']));
    }
    if (!is_null($args['status'])) {
        $order->set_status($args['status']);
    }
    if (!is_null($args['customer_note'])) {
        $order->set_customer_note($args['customer_note']);
    }
    if (!is_null($args['customer_id'])) {
        $order->set_customer_id(is_numeric($args['customer_id']) ? absint($args['customer_id']) : 0);
    }
    if (!is_null($args['created_via'])) {
        $order->set_created_via(sanitize_text_field($args['created_via']));
    }
    if (!is_null($args['cart_hash'])) {
        $order->set_cart_hash(sanitize_text_field($args['cart_hash']));
    }
    // Update other order props set automatically
    $order->set_currency(get_woocommerce_currency());
    $order->set_prices_include_tax('yes' === get_option('woocommerce_prices_include_tax'));
    $order->set_customer_ip_address(WC_Geolocation::get_ip_address());
    $order->set_customer_user_agent(wc_get_user_agent());
    $order->save();
    return $order;
}