Advertisement
Guest User

EDD Custom Fields Code

a guest
Apr 24th, 2014
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.04 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Easy Digital Downloads Custom Fields
  4. Plugin URI: http://www.netthrilldesigns.com
  5. Description: Custom fields added for Easy Digital Downloads
  6. Version: 1.0
  7. Author: netTHRILLdesigns
  8. Author URI: http://www.netthrilldesigns.com
  9. License: Proprietary
  10. */
  11.  
  12. // output our custom field HTML
  13. function tcwf_edd_custom_checkout_fields() {
  14.     ?>
  15.     <p>
  16.         <label class="edd-label" for="edd-phone"><?php _e('Phone Number', 'edd'); ?></label>
  17.         <input class="edd-input required" type="text" name="edd_phone" id="edd-phone" placeholder="<?php _e('Phone Number', 'edd'); ?>" value=""/>
  18.     </p>
  19.     <p>
  20.         <label class="edd-label" for="edd-company"><?php _e('Company Name', 'edd'); ?></label>
  21.         <input class="edd-input required" type="text" name="edd_company" id="edd-company" placeholder="<?php _e('Company Name', 'edd'); ?>" value=""/>
  22.     </p>
  23.     <p>
  24.         <label class="edd-label" for="edd-address"><?php _e('Address', 'edd'); ?></label>
  25.         <input class="edd-input required" type="text" name="edd_address" id="edd-address" placeholder="<?php _e('Shipping Address', 'edd'); ?>" value=""/>
  26.     </p>   
  27.     <?php
  28. }
  29. add_action('edd_purchase_form_user_info', 'tcwf_edd_custom_checkout_fields');
  30.  
  31.  check for errors with out custom fields
  32.  function tcwf_edd_validate_custom_fields($data) {
  33.     if(!isset($data['edd_phone']) || $data['edd_phone'] == '') {
  34.         // check for a phone number
  35.         edd_set_error( 'invalid_phone', __('You must provide your phone number.', 'tcwf_edd') );
  36.     }
  37.     if(!isset($data['edd_company']) || $data['edd_company'] == '') {
  38.         // check for a valid company name
  39.         edd_set_error( 'invalid_company', __('You must provide a valid company name.', 'tcwf_edd') );
  40.     }
  41.     if(!isset($data['edd_address']) || $data['edd_address'] == '') {
  42.         // check for a valid address
  43.         edd_set_error( 'invalid_address', __('You must provide a valid shipping address.', 'tcwf_edd') );
  44.     }
  45.  }
  46.  add_action('edd_checkout_error_checks', 'tcwf_edd_validate_custom_fields');
  47.  
  48. // store the custom field data in the payment meta
  49. function tcwf_edd_store_custom_fields($payment_meta) {
  50.     $payment_meta['phone'] = isset($_POST['edd_phone']) ? $_POST['edd_phone'] : '';
  51.     $payment_meta['company'] = isset($_POST['edd_company']) ? $_POST['edd_company'] : '';
  52.     $payment_meta['address'] = isset($_POST['edd_address']) ? $_POST['edd_address'] : '';
  53.     return $payment_meta;
  54. }
  55. add_filter('edd_payment_meta', 'tcwf_edd_store_custom_fields');
  56.  
  57. // show the custom fields in the "View Order Details" popup
  58. function tcwf_edd_purchase_details($payment_meta, $user_info) {
  59.     $phone = isset($payment_meta['phone']) ? $payment_meta['phone'] : 'none';
  60.     $company = isset($payment_meta['company']) ? $payment_meta['company'] : 'none';
  61.     $address = isset($payment_meta['address']) ? $payment_meta['address'] : 'none';
  62.     ?>
  63.     <li><?php echo __('Phone:', 'tcwf') . ' ' . $phone; ?></li>
  64.     <li><?php echo __('Company:', 'tcwf') . ' ' . $company; ?></li>
  65.     <li><?php echo __('Shipping Address:', 'tcwf') . ' ' . $address; ?></li>
  66.     <?php
  67. }
  68. add_action('edd_payment_personal_details_list', 'tcwf_edd_purchase_details', 10, 2);
  69.  
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement