Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Gravity Forms coupon code - steps

redearth May 17th, 2012 186 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Agree that showing coupon codes in the source code is not ideal. Was able to work out a way to add valid codes as a radio button selections in the form editor, set it to admin-only, and retrieve them with ajax for validation against a coupon code input.
  2.  
  3. Any feedback on ways to improve on this approach appreciated!
  4.  
  5.  
  6. ___1. Added to header.php above wp_head();___
  7. <script src="http://code.jquery.com/jquery-latest.js"></script>
  8.  
  9.  
  10. ___2. Created three coupon fields in the form___
  11.  
  12. a) Available coupon codes (admin only)
  13.    This is a set of valid coupon codes admins can update through the form editor
  14.  
  15.    Type = Radio buttons
  16.    Properties tab:
  17.       Label = any coupon code (case-insensitive)
  18.       Value = discount amount (flat, not percentage) (check enable values)
  19.    Advanced tab:
  20.       Admin Label = coupon_codes
  21.       Visibility = Admin Only
  22.  
  23.  
  24. b) Coupon Code
  25.    This is the field website visitors will type the coupon code into
  26.  
  27.    Type = Single Line Text
  28.  
  29.    default settings
  30.  
  31.  
  32. c) Coupon Code Amount
  33.    This is where the discount $ amount will show/update
  34.  
  35.    Type = Product
  36.  
  37.    Properties tab:
  38.       Field Type = Single Product
  39.       Disable quantity field = checked
  40.    Advanced tab:
  41.       'Allow field to be populated dynamically' = checked, no parameters, needed to allow negative prices
  42.  
  43.  
  44.  
  45. ___3. Added code functions.php___
  46. This processes the ajax call from the template
  47.  
  48. Code here: http://pastebin.com/WAry41pz
  49.  
  50.  
  51. ___4. Added code to template, right above `wp_footer()`___
  52. This updates pricing depending on what is entered. The adminLabel could be changed to pull other admin-only data out too,
  53.  
  54. Change the variables to match your form id, the field id of the coupon amount field (product field id) and the $("input_3_18") to match your form id and the coupon input field id.
  55.  
  56. Code here: http://pastebin.com/fEidLpUW
  57.  
  58.  
  59. ___Unresolved issues___
  60. * If post the form and there are errors, coupon code field won't update when edited
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top