question regarding Woocommerce payment gateways.
Iâve customized a payment gateway to take purchase orders, and its loading correctly from a plugin, and appearing on the checkout page the way id like it to; I think its a pretty good start.
Anyway, I have a non-standard form entry (purchase order number) that id like people to fill out, but I donât know how to attach it to my custom payment gateway so that it appears on the resulting admin side page.
This all works fine:
function payment_fields(){
if ( $description = $this->get_description() )
echo wpautop( wptexturize( $description ) );
global $woocommerce;
?>
<form class="form-horizontal" role="form" id="bv-form">
<fieldset>
<!-- Form Name -->
<legend>Purchase Order</legend>
<!-- Text input-->
<div class="form-group">
<label class="control-label" for="po_no">PO Number</label>
<div class="">
<input id="po_no" name="po_no" type="text" placeholder="" class="form-control input-md">
</div>
</div>
...
But when I get here, I donât know how to modify process_payment( $order_id )
(or what to add to functions.php
) to grab the form values from the payment fields. I see that there are $order->billingAddress1
etc., how would I submit the extra couple form fields along with the order, and then secondly, how would I access that to get po_no
out of the newly created WC_Order
?
- WP: 3.9.2
- WC: 2.1.11
Thanks for your help!
If you are creating a custom Payment Gateway then you should be implementing
process_payment()
within it. This code will have access to the$_POST
variables were submitted by the payment form, so you can refer to it as:That said it sounds like from your question you may not be actually writing a custom gateway and are instead trying to attach custom fields to the order. If you want to hook into another gateway (like PayPal, Authorize.net, etc) then you should use the WooCommerce action hooks that are called as part of
WC_Order.payment_complete()
which is what the gateway calls after it collects payment. The actions arewoocommerce_pre_payment_complete
which runs before anything else and takes the order id as an argument, andwoocommerce_payment_complete
after stock/statuses/etc are set.You can then display this custom field on the Order Edit page by adding a meta box. You’ll need to hook into
save_post
and change thepo_number
to an input if you want to make it editable.