-
-
Save webaware/6f0fd469855e7c2d5b8495b9708c8003 to your computer and use it in GitHub Desktop.
<?php | |
/* | |
Plugin Name: GFeWAY Invoice Reference | |
Plugin URI: https://gist.github.com/webaware/6f0fd469855e7c2d5b8495b9708c8003 | |
Description: specify Invoice Reference for Gravity Forms eWAY transaction | |
Version: 1 | |
Author: WebAware | |
Author URI: https://gfeway.webaware.net.au/ | |
*/ | |
if (!defined('ABSPATH')) { | |
exit; | |
} | |
/** | |
* change the Invoice Reference field to a custom value | |
* @param string $invoiceReference | |
* @param array $form the Gravity Forms form | |
* @return string | |
*/ | |
add_filter('gfeway_invoice_ref', function($invoiceReference, $form) { | |
// set your custom reference here; perhaps a WordPress User ID, or field value | |
$invoiceReference = uniqid(); | |
return $invoiceReference; | |
}, 10, 2); |
This seems like it should be doable, but it seems just the $form object itself is included in the filter, not the entry data? Is that correct?
Yes, in the free add-on (and the pro add-on with Direct mode), the transaction happens before the entry is created. You can catch the form post to get the field value though. Look in $_POST
(e.g. with xdebug, or log to the WP debug.log) to see what to pluck from that array.
cheers,
Ross
Hi @cjwebdev,
Yes, I got it working.
1. I added a 'single-line text' field to the Form so the user could specify a Reference Number.
Note: The field had an ID of 5 - see attached image:
Your field will likely have a different ID. Keep that in mind as you will be using the ID in the filter.
2. I added the following to the functions.php:
add_filter('gfeway_invoice_ref', function($invoiceReference, $form) {
//Check that we are applying the filter for the correct form (form ID 3) using and that the correct field (field ID 5) is set.
if( $form['id'] == 3 && isset($_POST['input_5']) ){
// If it is, set the $invoiceReference to the value of the Field.
$invoiceReference = $_POST['input_5'];
}
return $invoiceReference;
}, 10, 2);
Thanks @samheavyside,
That's great you can access the $_POST object so easily.
Really appreciate you sharing - have a great day!
CJ
Hi.
This looks simple enough, but I am wondering how I would use the data from the submitted form as the invoice reference (I'm using the free version of the GFEway plugin).
Example:
If I have a simple Text field - Invoice Ref: ________
How can I use the value entered as the InvoiceReference?
This seems like it should be doable, but it seems just the $form object itself is included in the filter, not the entry data? Is that correct?