Woocommerce: Programmatically Updating Order Status
<p>When I try to programmatically update an order during a <code>WP_Ajax</code> hook. IE.</p>

<pre><code>$order = wc_create_order($order_data);
$order-&gt;add_product( get_product( $membership_product_ids[0] ), 1 );
$order-&gt;set_address( $address, 'billing' );
$order-&gt;set_address( $address, 'shipping' );
$order_id = $order-&gt;id;
$order-&gt;update_status('completed');
</code></pre>

<p>I get the following errors:</p>

<blockquote>
  <p>Warning: DOMXPath::query(): Invalid expression in /wp-content/plugins/woocommerce/includes/libraries/class-emogrifier.php on line 299</p>
  
  <p>Warning: DOMXPath::query(): Invalid expression in /wp-content/plugins/woocommerce/includes/libraries/class-emogrifier.php on line 299</p>
  
  <p>Warning: Invalid argument supplied for foreach() in /wp-content/plugins/woocommerce/includes/libraries/class-emogrifier.php on line 302</p>
  
  <p>Warning: DOMXPath::query(): Invalid expression in /wp-content/plugins/woocommerce/includes/libraries/class-emogrifier.php on line 299</p>
  
  <p>Warning: DOMXPath::query(): Invalid expression in /wp-content/plugins/woocommerce/includes/libraries/class-emogrifier.php on line 299</p>
  
  <p>Warning: Invalid argument supplied for foreach() in /wp-content/plugins/woocommerce/includes/libraries/class-emogrifier.php on line 302</p>
</blockquote>

<p>If I remove that <code>update_status</code> function it does not errors.</p>