title: Programmatically creating new order in Woocommerce
body: <p>I am having the hardest time programmatically creating an order in WooCommerce. I am using the code below and is DOES create an order BUT I cannot get customer information OR product line items added to the order. The new order that is create is simply as Guest with no items, user information, etc. </p>
  
  <p>The issue seems to be that once the order object is created, it is failing when trying to add data to the order.</p>
  
  <pre><code>function create_vip_order() {
  
    global $woocommerce;
  
    $address = array(
        'first_name' =&gt; '111Joe',
        'last_name'  =&gt; 'Conlin',
        'company'    =&gt; 'Speed Society',
        'email'      =&gt; 'joe@testing.com',
        'phone'      =&gt; '760-555-1212',
        'address_1'  =&gt; '123 Main st.',
        'address_2'  =&gt; '104',
        'city'       =&gt; 'San Diego',
        'state'      =&gt; 'Ca',
        'postcode'   =&gt; '92121',
        'country'    =&gt; 'US'
    );
  
    // Now we create the order
    $order = wc_create_order();
  
    // The add_product() function below is located in /plugins/woocommerce/includes/abstracts/abstract_wc_order.php
    $order-&gt;add_product( get_product( '275962' ), 1 ); // This is an existing SIMPLE product
    $order-&gt;set_address( $address, 'billing' );
    //
    $order-&gt;calculate_totals();
    $order-&gt;update_status("Completed", 'Imported order', TRUE);
  
  }
  
  add_action( 'woocommerce_init', 'create_vip_order' );
  </code></pre>
  
  <p>Here is the error I am getting in my logs:</p>
  
  <pre><code>[19-Apr-2016 21:16:38 UTC] PHP Fatal error:  Uncaught Error: Call to a member function add_product() on boolean in /Users/joe/Sites/speedsociety-2/wp-content/themes/ss/lib/contests/order.php:107
  Stack trace:
  #0 /Users/joe/Sites/speedsociety-2/wp-includes/plugin.php(525): create_vip_order('')
  #1 /Users/joe/Sites/speedsociety-2/wp-content/plugins/woocommerce/woocommerce.php(330): do_action('woocommerce_ini...')
  #2 /Users/joe/Sites/speedsociety-2/wp-includes/plugin.php(525): WooCommerce-&gt;init('')
  #3 /Users/joe/Sites/speedsociety-2/wp-settings.php(392): do_action('init')
  #4 /Users/joe/Sites/speedsociety-2/wp-config.php(67): require_once('/Users/joe/Site...')
  #5 /Users/joe/Sites/speedsociety-2/wp-load.php(37): require_once('/Users/joe/Site...')
  #6 /Users/joe/Sites/speedsociety-2/wp-admin/admin.php(31): require_once('/Users/joe/Site...')
  #7 /Users/joe/Sites/speedsociety-2/wp-admin/edit.php(10): require_once('/Users/joe/Site...')
  #8 {main}
    thrown in /Users/joe/Sites/speedsociety-2/wp-content/themes/ss/lib/contests/order.php on line 107
  </code></pre>
  
  <p>Any help on this would be MOST appreciated!</p>