Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- Any feedback on ways to improve on this approach appreciated!
- ___1. Added to header.php above wp_head();___
- <script src="http://code.jquery.com/jquery-latest.js"></script>
- ___2. Created three coupon fields in the form___
- a) Available coupon codes (admin only)
- This is a set of valid coupon codes admins can update through the form editor
- Type = Radio buttons
- Properties tab:
- Label = any coupon code (case-insensitive)
- Value = discount amount (flat, not percentage) (check enable values)
- Advanced tab:
- Admin Label = coupon_codes
- Visibility = Admin Only
- b) Coupon Code
- This is the field website visitors will type the coupon code into
- Type = Single Line Text
- default settings
- c) Coupon Code Amount
- This is where the discount $ amount will show/update
- Type = Product
- Properties tab:
- Field Type = Single Product
- Disable quantity field = checked
- Advanced tab:
- 'Allow field to be populated dynamically' = checked, no parameters, needed to allow negative prices
- ___3. Added code functions.php___
- This processes the ajax call from the template
- Code here: http://pastebin.com/WAry41pz
- ___4. Added code to template, right above `wp_footer()`___
- This updates pricing depending on what is entered. The adminLabel could be changed to pull other admin-only data out too,
- 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.
- Code here: http://pastebin.com/fEidLpUW
- ___Unresolved issues___
- * If post the form and there are errors, coupon code field won't update when edited
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement