title: How to programatically create order in woocommerce and redirect to payment gateway
body: <p>I'm very new to payment gateway integration. I learned that, orders can be created programmatically without adding products in woocommerce and done that.</p>
  
  <p>Problem now is, I'm not sure how to automate the payment process once submit order button is clicked.</p>
  
  <p>Currently when the order form is submitted, I create order programmatically into woocommerce and expect the user to redirected to selected(currently by default is billPlz) payment gateway page to make payment.</p>
  
  <p>I already had woocomerce and billPlz payment gateway installed. And <code>WC()-&gt;payment_gateways-&gt;get_available_payment_gateways()</code> does return me the billPlz.</p>
  
  <p>However the payment form is not shown from the payment gateway for users to submit the payment into the billPlz.</p>
  
  <p>I see 'success' message and redirected to <code>mydomain/order-received/72?key=wc_order_5a0f8f3ead251</code></p>
  
  <p>I assume this is the Thank you page? </p>
  
  <p>How to redirect to payment gateway when order is created?</p>
  
  <p>Order form (my own, not from woocomerce)</p>
  
  <pre><code>&lt;form action="&lt;?php echo esc_url( admin_url('admin-post.php') ); ?&gt;" method="POST"&gt;
      &lt;input type="text" name="action" value="createOrder"&gt;
      &lt;input type="text" name="booking_id" value="123"&gt;
      &lt;input type="text" name="customer_id" value="1006"&gt;
      &lt;input type="text" name="order_amount" value="180.00"&gt;
      &lt;input type="text" name="order_status" value="1"&gt;
  
      &lt;input type="submit" value="PROCEED TO MAKE PAYMENT"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>create order function</p>
  
  <pre><code>public function createOrder()
      {
  
          $product_id = 222;
          $quantity = 1;
  
          $args = array( 
           'variation' =&gt; array( 'attribute_color' =&gt; 'red'),
           'status' =&gt; 'complete',
           'customer_id'=&gt; 23
          ); 
  
          $order = wc_create_order();
          $order_id = trim(str_replace('#', '', $order-&gt;get_order_number()));
  
  
          $order-&gt;add_product( get_product( $product_id ), $quantity, $args );
  
          $order-&gt;set_status( $args['status'] );
          $order-&gt;set_customer_id( is_numeric( $args['customer_id'] ) ? absint( $args['customer_id'] ) : 0 );
          $order-&gt;set_total( ($discount['amount']/100) , 'order_discount'); // not pennies (use dollar amount)
  
          update_post_meta( $order_id, '_payment_method', 'billplz' );
          update_post_meta( $order_id, '_payment_method_title', 'Billplz Payment Gateway' );
  
          $order-&gt;calculate_totals();
  
  
          // Process Payment
          $available_gateways = WC()-&gt;payment_gateways-&gt;get_available_payment_gateways();
  
          $result = $available_gateways[ 'billplz' ]-&gt;process_payment( $order_id );
  
          // Redirect to success/confirmation/payment page
          if ( $result['result'] == 'success' ) {
  
              $result = apply_filters( 'woocommerce_payment_successful_result', $result, $order_id );
              $return_url = $available_gateways[ 'billplz' ]-&gt;get_return_url( $order );
  
              wp_redirect($return_url);
              exit;
          }
      }
  </code></pre>