title: How to get the order id in a custom function
body: <p>I am setting up a WooCommerce payment plugin. I have created a payment field that should display the order id before payments are received. </p>
  
  <p>I have seen this answer <a href="https://stackoverflow.com/questions/43316644/get-the-order-id-in-checkout-page-before-payment-process">Get the order ID in checkout page before payment process</a> however I do not know how to use the custom function.</p>
  
  <pre class="lang-php prettyprint-override"><code>public function payment_fields(){
  global $woocommerce;
  
  $amount = floatval( preg_replace( '#[^\d.]#', '', $woocommerce-&gt;cart-&gt;get_cart_total() ) );
  
  ///This works if the order has been already placed
  $order = new WC_Order($post-&gt;ID);
  $order_id = $order-&gt;get_id();
  
  $shortcode = $this-&gt;shortcode;
  
  $steps="Go to Safaricom Menu on your phone&lt;br&gt;
  Select M-PESA&lt;br&gt;
  Select Lipa na MPESA&lt;br&gt;
  Select Pay Bill&lt;br&gt;
  Enter Business No: $shortcode&lt;br&gt;
  Enter Account No:$order_id&lt;br&gt;
  Enter Amount: $amount &lt;br&gt;
  Enter the transaction code you received from MPESA in the form below&lt;br&gt;";
  echo wpautop( wptexturize( $steps) );
  
  //This add the form field for Pay bill customers 
   woocommerce_form_field( 'mpesaid', array(
                  'title'     =&gt; __( 'MPESA Reference', 'cwoa-authorizenet-aim' ),
                  'type'      =&gt; 'text',
                  'label'       =&gt; 'M-PESA Reference',
                  'required'    =&gt; true,
                  'maxlength'    =&gt; '10'
               )
              );
      }
  </code></pre>
  
  <p>`</p>