title: How to create woocommerce order in php
body: <p>I am trying to create one plugin for crowdfunding site on wordpress.
  On my site i have different projects (products) and users can donate money. They can choose how much they want to donate. Now i need to create orders from my plugin for some project. I found this code </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
      // This is an existing SIMPLE product
      $order-&gt;add_product( wc_get_product( '5617' ), 100 );
  
      $order-&gt;set_address( $address, 'billing' );
  
      $order-&gt;calculate_totals();
  
      $order-&gt;update_status("Completed", 'Imported order', TRUE);
  
    }
  
    add_action( 'init', 'create_vip_order' );
  </code></pre>
  
  <p>and all works good , but i need to insert also value that user want to donate.</p>
  
  <p>Now this script insert only adress and total 0,00</p>
  
  <p>Please help me to solve this problem.</p>
  
  <p>i did:</p>
  
  <pre><code>$test = 30000;
  $order-&gt; -&gt;set_total($test, 'order_discount');
  </code></pre>
  
  <p>but this didnt helped me</p>