On one of my WordPress sites, I have a Gravity Form which uses the Authorize.net Gravity Form add-on for credit card processing.
All works well until I try to add in the Gravity Forms Coupons add-on. The coupon add-on seems to work just fine until I make the discounted amount 100%.
Actually, the coupon code works fine. The problem is that I don’t want to have to collect credit card information if my user has a zero balance owed. If their coupon code gives them the product or membership for free, then I shouldn’t ask them for credit card information.
But, the credit card information is required so that they can’t get past the form if there is a balance. In other words, if they don’t have a coupon code which zeros out the balance owed, I don’t want them to get in without credit card information entered.
The first problem is that Gravity Forms won’t let me have a conditional based on the coupon field. 🙁
I got past that problem by adding javascript to the page which will hide the credit card fields when a free coupon code is entered. But, since I added the code with javascript, it doesn’t take away the fact that the credit card is still required.
// $('#input_1_22').change(function() { // form 1 total field if ( $('#input_1_22').val() == 0) { // if total = 0 $('#field_1_18').hide(); // hide the credit card fields } }); //
I can get past that problem by adding code in the Gravity Forms validation hook to allow the credit card information to be missing if the balance is zero.
// add_filter("gform_field_validation_1_18", "credit_card_validation", 10, 4); function credit_card_validation($result, $value, $form, $field){ if ($_POST['input_22'] == 0) { // if total = 0 $result["is_valid"] = true; // make credit card valid without credit card information } return $result; } //
Now that should work, right? Wrong. The Authorize.net plugin still kicks in and tries to charge the credit card. When it does, it gives an error because the credit card information is missing. So, it’s not the validation code for Gravity Forms causing my problem, but the Authorize.net plugin code which I don’t want to change because an update to the plugin would overwrite my code. I have not been able to find any hooks for the Authorize.net plugin to solve my problem. If you know of any, please let me know in the comments below.
To get around this little problem I decided to create a new form just for my free members. I can still give them a coupon code but they will be sent to a different form that doesn’t have any credit card fields to be filled in on the form.
To keep them from getting in without the coupon code, I made the submit button conditional on the coupon code. Oh, but wait, I can’t have conditionals on coupon codes – at least not the coupon codes in the Coupons add-on for Gravity Forms. Instead I just used the regular single line text field as a coupon field instead of the coupons add-on.
Since I only have one free coupon code this was pretty easy to set up. If they don’t input the correct coupon code, they won’t get a submit button and can’t submit the form.
If they have any other coupon code they will be sent to my original form which uses both the Coupons add-on and the Authorize.net add-on. Any coupon code which isn’t for 100% of the amount will work ok because there will still be a balance which needs to be charged on the credit card.
Nice article. You can also move the total into a hidden field using javascript and base all your conditionals off the hidden field. Makes it easier to handle multiple inputs like biller address etc..
Oooh, good solution! Thanks!