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