Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Custom Checkout Form

By: a guest on Dec 5th, 2012  |  syntax: None  |  size: 16.32 KB  |  views: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. /*
  4.  
  5. Plugin Name: edd-addons
  6.  
  7. Plugin URI:
  8.  
  9. Description:
  10.  
  11. Version:
  12.  
  13. Author:
  14.  
  15. Author URI:
  16.  
  17. License:
  18.  
  19. License URI:
  20.  
  21. */
  22.  
  23. /**
  24.  
  25.  *
  26.  
  27.  * Outputs Custom fields
  28.  
  29.  *
  30.  
  31. */
  32.  
  33. function pippin_edd_custom_checkout_fields() {
  34.  
  35. ?>
  36.  
  37. <p>Please indicate your membership:</p>
  38.   <table>
  39.   <tr>
  40.   <td>
  41.     <input name="membertype" type="radio" value="new_pract" id="new_pract" />
  42.     </td>
  43.     <td>
  44.     <label for="new_pract">New Practioner</label>
  45.     </td>
  46.     </tr>
  47.     <tr>
  48.     <td>
  49.     <input name="membertype" type="radio" value="renew_prac" id="renew_prac" />
  50.     </td>
  51.     <td>
  52.     <label for="renew_prac">Renewing Practioner</label>
  53.   </td>
  54.   </tr>
  55.   <tr>
  56.     <td>
  57.     <input name="membertype" type="radio" value="renew_updated" id="renew_prac_updated" />
  58.     </td>
  59.     <td>
  60.     <label for="renew_prac_updated">Renewing Practioner with Updated Contact Information</label>
  61.   </td>
  62.   </tr>
  63.   <tr>
  64.     <td>
  65.     <input name="membertype" type="radio" value="friend" id="friend" />
  66.     </td>
  67.     <td>
  68.     <label for="friend">Renewing Friend without updated contact information</label>
  69.   </td>
  70.   </tr>
  71.   <tr>
  72.     <td>
  73.     <input name="membertype" type="radio" value="new-friend" id="new-friend" />
  74.     </td>
  75.     <td>
  76.     <label for="new-friend">New or Renewing Friend with updated contact information</label>
  77.   </td>
  78.   </tr>
  79.   <tr>
  80.     <td>
  81.     <input name="membertype" type="radio" value="student" id="student" />
  82.     </td>
  83.     <td>
  84.     <label for="student">Student</label>
  85.   </td>
  86.   </tr>
  87.   </table>
  88.  
  89. <div id="contact_data">
  90. <p>
  91.   <label class="edd-label" for="edd-phone">
  92.     <?php _e('Phone Number', 'edd'); ?>
  93.   </label>
  94.   <input class="edd-input required" type="text" name="edd_phone" id="edd-phone" placeholder="<?php _e('Phone Number', 'edd'); ?>" value=""/>
  95.  
  96.   <label class="edd-label" for="edd-address">
  97.     <?php _e('Address', 'edd'); ?>
  98.   </label>
  99.   <input class="edd-input required" type="text" name="edd_address" id="edd-address" placeholder="<?php _e('Address', 'edd'); ?>" value=""/>
  100.  
  101.   <label class="edd-label" for="edd-city">
  102.     <?php _e('City', 'edd'); ?>
  103.   </label>
  104.   <input class="edd-input required" type="text" name="edd_city" id="edd-city" placeholder="<?php _e('City', 'edd'); ?>" value=""/>
  105.  
  106.   <label class="edd-label" for="edd-state">
  107.     <?php _e('State', 'edd'); ?>
  108.   </label>
  109.   <input class="edd-input required" type="text" name="edd_state" id="edd-state" placeholder="<?php _e('State', 'edd'); ?>" value=""/>
  110.  
  111.    <label class="edd-label" for="edd-zip">
  112.     <?php _e('Zip', 'edd'); ?>
  113.   </label>
  114.   <input class="edd-input required" type="text" name="edd_zip" id="edd-zip" placeholder="<?php _e('Zip', 'edd'); ?>" value=""/>
  115.   </p>
  116. </div>
  117.  
  118. <div id="new_pract_fields">
  119. <label>Name of Instructor and Feng Shui School or Program</label><input type="text" placeholder="<?php _e('Progarm Complete', 'edd'); ?>" name="edd_program_complete" id="edd-program_complete" />
  120. <label>Program Completion Date</label><input type="text" placeholder="<?php _e('Progarm Complete Date', 'edd'); ?>" name="edd_program_complete_date" id="edd-program_complete_date" />
  121. <label>Total Program hours</label><input type="text" placeholder="<?php _e('Progarm Total Hours', 'edd'); ?>" name="edd_program_total_hours" id="edd-program_total_hours" />
  122. </div>
  123.  
  124. <div id="new-renew_pract_fields">
  125.     <label class="edd-label" for="edd-business">
  126.       <?php _e('Business Name', 'edd'); ?>
  127.     </label>
  128.     <input class="edd-input" type="text" name="edd_business" id="edd-business" placeholder="<?php _e('Business Name', 'edd'); ?>" value=""/>
  129.    <strong>Feng Shui Speciality</strong>
  130.   <table class="hours" border="0">
  131.     <tr>
  132.       <td><input type="radio" class="edd-input" name="edd_speciality" value="Residential"></td>
  133.         <td><label>Residential</label></td>
  134.     </tr>
  135.     <tr>
  136.       <td><input type="radio" name="edd_speciality" class="edd-input" value="Business/Commercial" style="float:left;"></td>
  137.         <td><label>Business/Commercial</label></td>
  138.     </tr>
  139.   </table>
  140.     <label class="edd-label" for="edd-description">
  141.       <?php _e('Business description for website directory', 'edd'); ?>
  142.     </label>
  143.     <textarea class="edd-input" rows="4" cols="50" name="edd_description" id="edd-description"><?php _e('Business description', 'edd'); ?>
  144. </textarea>
  145. </div>
  146.  
  147. <div id="edd_credits">
  148.   <p>6 hours of continuing education credits are required for practitioner membership renewal. Please list CEUs below. <a href="http://fsim.org.s2956.gridserver.com/membership-info/renewal-forms/" target="_blank"><br>
  149.         <em>See Continuing Education Requirements for course eligibility requirements</em></a>.</p>
  150. <p>
  151.   <label class="edd-label" for="edd-meetings">
  152.     <?php _e('FSIM Membership Meetings attended in 2012', 'edd'); ?>
  153.   </label>
  154. <table class="hours" width="70%" border="0">
  155.   <tr>
  156.     <td colspan="2"><strong>Continuing Education Units (CEUs)</strong></td>
  157.   </tr>
  158.   <tr>
  159.     <td><input type="checkbox" name="edd_meetings[]" class="edd-meetings" value="January 10 2012 1.5" <?php
  160.                                 if ($_POST && in_array('January 10, 2012 1.5', $_POST['edd_meetings'])) {
  161.                                   echo 'checked';
  162.                                 } ?>>
  163.       January 10, 2012</td>
  164.     <td>1.5 hours</td>
  165.   </tr>
  166.   <tr>
  167.     <td><input type="checkbox" name="edd_meetings[]" class="edd-meetings" value="April 10 2012 1.5" <?php
  168.                                 if ($_POST && in_array('April 10, 2012 1.5', $_POST['edd_meetings'])) {
  169.                                   echo 'checked';
  170.                                 } ?>>
  171.       April 10, 2012</td>
  172.     <td>1.5 hours</td>
  173.   </tr>
  174.   <tr>
  175.     <td><input type="checkbox" name="edd_meetings[]" class="edd-meetings" value="July 10 2012 1.5"<?php
  176.                                 if ($_POST && in_array('July 10, 2012 1.5', $_POST['edd_meetings'])) {
  177.                                   echo 'checked';
  178.                                 } ?>>
  179.       July 10, 2012</td>
  180.     <td>1.5 hours</td>
  181.   </tr>
  182.   <tr>
  183.     <td><input type="checkbox" name="edd_meetings[]" class="edd-meetings" value="November 3 2012 Field Trip 1.5"  <?php
  184.                                 if ($_POST && in_array('November 3, 2012 Field Trip 1.5', $_POST['edd_meetings'])) {
  185.                                   echo 'checked';
  186.                                 } ?>>
  187.       November 3, 2012 Field Trip</td>
  188.     <td>1.5 hours</td>
  189.   </tr>
  190.   <tr>
  191.     <td colspan="3"><input type="checkbox" id="additional_edd" style="float:left;" />
  192.       <label>Check if you attended a session other than the ones listed above</label></td>
  193.   </tr>
  194. </table>
  195. <div id="additional_edd_fields">
  196.   <table>
  197.     <tr>
  198.       <td> Date </td>
  199.       <td> Course </td>
  200.       <td> Hours </td>
  201.     </tr>
  202.     <tr>
  203.       <td><input type="text" class="edd_date" id="ed_date-text-1" name="ed_date-text-1" /></td>
  204.       <td><input type="text" class="edd_course" id="ed_course-text-1" name="ed_course-text-1" /></td>
  205.       <td><input type="text" class="edd_hours" id="ed_hours-text-1" name="ed_hours-text-1" /></td>
  206.     </tr>
  207.     <tr>
  208.       <td><input type="text" class="edd_date" id="ed_date-text-2" name="ed_date-text-2" /></td>
  209.       <td><input type="text" class="edd_course" id="ed_course-text-2" name="ed_course-text-2" /></td>
  210.       <td><input type="text" class="edd_hours" id="ed_hours-text-2" name="ed_hours-text-2" /></td>
  211.     </tr>
  212.     <tr>
  213.       <td><input type="text" class="edd_date" id="ed_date-text-3" name="ed_date-text-3" /></td>
  214.       <td><input type="text" class="edd_course" id="ed_course-text-3" name="ed_course-text-3" /></td>
  215.       <td><input type="text" class="edd_hours" id="ed_hours-text-3" name="ed_hours-text-3" /></td>
  216.     </tr>
  217.   </table>
  218.   <table>
  219.     <tr>
  220.       <td>
  221.         <input type="text" name="edd-meetings_total" id="edd-meetings_total" style="display:none;" value="" /></td>
  222.     </tr>
  223.   </table>
  224.   </p>
  225. </div>
  226. </div>
  227.  
  228. <?php
  229.  
  230. }
  231.  
  232. add_action('edd_purchase_form_user_info', 'pippin_edd_custom_checkout_fields');
  233.  
  234.  
  235.  
  236. // check for errors with out custom fields
  237.  
  238. function pippin_edd_validate_custom_fields($data) {
  239.  
  240.         if(!isset($data['edd_phone']) || $data['edd_phone'] == '') {
  241.  
  242.                 // check for a phone number
  243.  
  244.                 edd_set_error( 'invalid_phone', __('Please provide your phone number.', 'pippin_edd') );
  245.  
  246.         }
  247.  
  248.         if(!isset($data['edd_address']) || $data['edd_address'] == '') {
  249.  
  250.                 // check for an address
  251.  
  252.                 edd_set_error( 'invalid_address', __('Please provide your mailing address.', 'pippin_edd') );
  253.  
  254.         }
  255.         if(!isset($data['edd_city']) || $data['edd_city'] == '') {
  256.  
  257.                 // check for a city
  258.  
  259.                 edd_set_error( 'invalid_city', __('Please provide your city.', 'pippin_edd') );
  260.  
  261.         }
  262.         if(!isset($data['edd_state']) || $data['edd_state'] == '') {
  263.  
  264.                 // check for a state
  265.  
  266.                 edd_set_error( 'invalid_state', __('Please provide your state.', 'pippin_edd') );
  267.  
  268.         }
  269.         if(!isset($data['edd_zip']) || $data['edd_zip'] == '') {
  270.  
  271.                 // check for a zip
  272.  
  273.                 edd_set_error( 'invalid_zip', __('Please provide your zip code.', 'pippin_edd') );
  274.  
  275.         }
  276.  
  277.  
  278. }
  279.  
  280. add_action('edd_checkout_error_checks', 'pippin_edd_validate_custom_fields');
  281.  
  282. //print data for edd-meeting array
  283. //if(is_array ($_POST['edd_meetings'])) {
  284.         //foreach ($_POST['edd_meetings'] as $meeting) {
  285.                 //print "$meeting <br />\n";
  286.                 //}
  287.         //};
  288.  
  289. // store the custom field data in the payment meta
  290.  
  291. function pippin_edd_store_custom_fields($payment_meta) {
  292.         $payment_meta['firstName'] = isset($_POST['edd_first']) ? $_POST['edd_first'] : '';
  293.         $payment_meta['lastName'] = isset($_POST['edd_last']) ? $_POST['edd_last'] : '';
  294.         $payment_meta['address'] = isset($_POST['edd_address']) ? $_POST['edd_address'] : '';
  295.         $payment_meta['city'] = isset($_POST['edd_city']) ? $_POST['edd_city'] : '';
  296.         $payment_meta['state'] = isset($_POST['edd_state']) ? $_POST['edd_state'] : '';
  297.         $payment_meta['zip'] = isset($_POST['edd_zip']) ? $_POST['edd_zip'] : '';
  298.         $payment_meta['email'] = isset($_POST['edd_email']) ? $_POST['edd_email'] : '';
  299.         $payment_meta['phone'] = isset($_POST['edd_phone']) ? $_POST['edd_phone'] : '';
  300.         $payment_meta['edd_program_complete'] = isset($_POST['edd_program_complete']) ? $_POST['edd_program_complete'] : '';
  301.         $payment_meta['edd_program_complete_date'] = isset($_POST['edd_program_complete_date']) ? $_POST['edd_program_complete_date'] : '';
  302.         $payment_meta['edd_program_total_hours'] = isset($_POST['edd_program_total_hours']) ? $_POST['edd_program_total_hours'] : '';
  303.         $payment_meta['business'] = isset($_POST['edd_business']) ? $_POST['edd_business'] : '';
  304.         $payment_meta['speciality'] = isset($_POST['edd_speciality']) ? $_POST['edd_speciality'] : '';
  305.         $payment_meta['description'] = isset($_POST['edd_description']) ? $_POST['edd_description'] : '';
  306.         $payment_meta['meetings'] =  isset($_POST['edd_meetings']) ? $_POST['edd_meetings'] : '';      
  307.         $payment_meta['addCreditsDateField1'] = isset($_POST['ed_date-text-1']) ? $_POST['ed_date-text-1'] : '';
  308.         $payment_meta['addCreditsCourseField1'] = isset($_POST['ed_course-text-1']) ? $_POST['ed_course-text-1'] : '';
  309.         $payment_meta['addCreditsHoursField1'] = isset($_POST['ed_hours-text-1']) ? $_POST['ed_hours-text-1'] : '';
  310.         $payment_meta['addCreditsDateField2'] = isset($_POST['ed_date-text-2']) ? $_POST['ed_date-text-2'] : '';
  311.         $payment_meta['addCreditsCourseField2'] = isset($_POST['ed_course-text-2']) ? $_POST['ed_course-text-2'] : '';
  312.         $payment_meta['addCreditsHoursField2'] = isset($_POST['ed_hours-text-2']) ? $_POST['ed_hours-text-2'] : '';
  313.         $payment_meta['addCreditsDateField3'] = isset($_POST['ed_date-text-3']) ? $_POST['ed_date-text-3'] : '';
  314.         $payment_meta['addCreditsCourseField3'] = isset($_POST['ed_course-text-3']) ? $_POST['ed_course-text-3'] : '';
  315.         $payment_meta['addCreditsHoursField3'] = isset($_POST['ed_hours-text-3']) ? $_POST['ed_hours-text-3'] : '';
  316.         return $payment_meta;
  317. }
  318.  
  319. add_filter('edd_payment_meta', 'pippin_edd_store_custom_fields');
  320.  
  321. // show the custom fields in the "View Order Details" popup
  322.  
  323. function pippin_edd_purchase_details($payment_meta, $user_info) {
  324.  
  325.         $firstName = isset($payment_meta['firstName']) ? $payment_meta['firstName'] : 'none';
  326.         $lastName = isset($payment_meta['lastName']) ? $payment_meta['lastName'] : 'none';
  327.         $address = isset($payment_meta['address']) ? $payment_meta['address'] : 'none';
  328.         $city = isset($payment_meta['city']) ? $payment_meta['city'] : 'none';
  329.         $state = isset($payment_meta['state']) ? $payment_meta['state'] : 'none';
  330.         $zip = isset($payment_meta['zip']) ? $payment_meta['zip'] : 'none';
  331.         $email = isset($payment_meta['email']) ? $payment_meta['email'] : 'none';
  332.         $phone = isset($payment_meta['phone']) ? $payment_meta['phone'] : 'none';
  333.         $edd_program_complete = isset($payment_meta['edd_program_complete']) ? $payment_meta['edd_program_complete'] : 'none';
  334.         $edd_program_complete_date = isset($payment_meta['edd_program_complete_date']) ? $payment_meta['edd_program_complete_date'] : 'none';
  335.         $edd_program_total_hours = isset($payment_meta['edd_program_total_hours']) ? $payment_meta['edd_program_total_hours'] : 'none';
  336.         $business = isset($payment_meta['business']) ? $payment_meta['business'] : 'none';     
  337.         $speciality = isset($payment_meta['speciality']) ? $payment_meta['speciality'] : 'none';       
  338.         $description = isset($payment_meta['description']) ? $payment_meta['description'] : 'none';    
  339.         $meetings = isset($payment_meta['meetings']) ? $payment_meta['meetings'] : 'none';     
  340.         $addCreditsDateField1 = isset($payment_meta['addCreditsDateField1']) ? $payment_meta['addCreditsDateField1'] : 'none';
  341.         $addCreditsDateField2 = isset($payment_meta['addCreditsDateField2']) ? $payment_meta['addCreditsDateField2'] : 'none';
  342.         $addCreditsDateField3 = isset($payment_meta['addCreditsDateField3']) ? $payment_meta['addCreditsDateField3'] : 'none';
  343.         $addCreditsCourseField1 = isset($payment_meta['addCreditsCourseField1']) ? $payment_meta['addCreditsCourseField1'] : 'none';
  344.         $addCreditsCourseField2 = isset($payment_meta['addCreditsCourseField2']) ? $payment_meta['addCreditsCourseField2'] : 'none';
  345.         $addCreditsCourseField3 = isset($payment_meta['addCreditsCourseField3']) ? $payment_meta['addCreditsCourseField3'] : 'none';
  346.         $addCreditsHoursField1 = isset($payment_meta['addCreditsHoursField1']) ? $payment_meta['addCreditsHoursField1'] : 'none';
  347.         $addCreditsHoursField2 = isset($payment_meta['addCreditsHoursField2']) ? $payment_meta['addCreditsHoursField2'] : 'none';
  348.         $addCreditsHoursField3 = isset($payment_meta['addCreditsHoursField3']) ? $payment_meta['addCreditsHoursField3'] : 'none';
  349.         ?>
  350.    
  351. <li><?php echo __('First Name:', 'pippin') . ' ' . $firstName; ?></li>
  352. <li><?php echo __('Last Name:', 'pippin') . ' ' . $lastName; ?></li>
  353. <li><?php echo __('Address:', 'pippin') . ' ' . $address; ?></li>
  354. <li><?php echo __('City:', 'pippin') . ' ' . $city; ?></li>
  355. <li><?php echo __('State:', 'pippin') . ' ' . $state; ?></li>
  356. <li><?php echo __('Zip:', 'pippin') . ' ' . $zip; ?></li>
  357. <li><?php echo __('Email:', 'pippin') . ' ' . $email; ?></li>
  358. <li><?php echo __('Phone:', 'pippin') . ' ' . $phone; ?></li>
  359. <li><?php echo __('Program Completed:', 'pippin') . ' ' . $edd_program_complete; ?></li>
  360. <li><?php echo __('Program Completion Date:', 'pippin') . ' ' . $edd_program_complete_date; ?></li>
  361. <li><?php echo __('Total Hours:', 'pippin') . ' ' . $edd_program_total_hours; ?></li>
  362. <li><?php echo __('Business:', 'pippin') . ' ' . $business; ?></li>
  363. <li><?php echo __('Feng Shui Speciality:', 'pippin') . ' ' . $speciality; ?></li>
  364. <li><?php echo __('Business description:', 'pippin') . ' ' . $description; ?></li>
  365. <li><?php echo __('Meetings attended:', 'pippin') . '' . $meetings; ?></li>
  366. <li><?php echo __('Meetings attended:', 'pippin') . ' ' . $meetings; ?></li>
  367. <li><?php echo __('Meetings attended:', 'pippin') . ' ' . $meetings; ?></li>
  368. <li><?php echo __('Additional Meetings 1:', 'pippin') . ' ' . $addCreditsDateField1; ?></li>
  369. <li><?php echo __('Additional Meetings 1:', 'pippin') . ' ' . $addCreditsCourseField1; ?></li>
  370. <li><?php echo __('Additional Meetings 1:', 'pippin') . ' ' . $addCreditsHoursField1; ?></li>
  371. <li><?php echo __('Additional Meetings 2:', 'pippin') . ' ' . $addCreditsDateField2; ?></li>
  372. <li><?php echo __('Additional Meetings 2:', 'pippin') . ' ' . $addCreditsCourseField2; ?></li>
  373. <li><?php echo __('Additional Meetings 2:', 'pippin') . ' ' . $addCreditsHoursField2; ?></li>
  374. <li><?php echo __('Additional Meetings 3:', 'pippin') . ' ' . $addCreditsDateField3; ?></li>
  375. <li><?php echo __('Additional Meetings 3:', 'pippin') . ' ' . $addCreditsCourseField3; ?></li>
  376. <li><?php echo __('Additional Meetings 3:', 'pippin') . ' ' . $addCreditsHoursField3; ?></li>
  377. <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
  378.  
  379. <?php
  380.  
  381. }
  382.  
  383. add_action('edd_payment_personal_details_list', 'pippin_edd_purchase_details', 10, 2);