Last active
June 15, 2020 02:05
-
-
Save webaware/6f0fd469855e7c2d5b8495b9708c8003 to your computer and use it in GitHub Desktop.
specify a custom Invoice Reference for Gravity Forms eWAY (Free and Pro) transactions. https://gfeway.webaware.net.au/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @samheavyside,
Did you get this working in the end?
Fancy sharing? ;)
CJ