Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Easy Digital Downloads Custom Fields
- Plugin URI: http://www.netthrilldesigns.com
- Description: Custom fields added for Easy Digital Downloads
- Version: 1.0
- Author: netTHRILLdesigns
- Author URI: http://www.netthrilldesigns.com
- License: Proprietary
- */
- // output our custom field HTML
- function tcwf_edd_custom_checkout_fields() {
- ?>
- <p>
- <label class="edd-label" for="edd-phone"><?php _e('Phone Number', 'edd'); ?></label>
- <input class="edd-input required" type="text" name="edd_phone" id="edd-phone" placeholder="<?php _e('Phone Number', 'edd'); ?>" value=""/>
- </p>
- <p>
- <label class="edd-label" for="edd-company"><?php _e('Company Name', 'edd'); ?></label>
- <input class="edd-input required" type="text" name="edd_company" id="edd-company" placeholder="<?php _e('Company Name', 'edd'); ?>" value=""/>
- </p>
- <p>
- <label class="edd-label" for="edd-address"><?php _e('Address', 'edd'); ?></label>
- <input class="edd-input required" type="text" name="edd_address" id="edd-address" placeholder="<?php _e('Shipping Address', 'edd'); ?>" value=""/>
- </p>
- <?php
- }
- add_action('edd_purchase_form_user_info', 'tcwf_edd_custom_checkout_fields');
- check for errors with out custom fields
- function tcwf_edd_validate_custom_fields($data) {
- if(!isset($data['edd_phone']) || $data['edd_phone'] == '') {
- // check for a phone number
- edd_set_error( 'invalid_phone', __('You must provide your phone number.', 'tcwf_edd') );
- }
- if(!isset($data['edd_company']) || $data['edd_company'] == '') {
- // check for a valid company name
- edd_set_error( 'invalid_company', __('You must provide a valid company name.', 'tcwf_edd') );
- }
- if(!isset($data['edd_address']) || $data['edd_address'] == '') {
- // check for a valid address
- edd_set_error( 'invalid_address', __('You must provide a valid shipping address.', 'tcwf_edd') );
- }
- }
- add_action('edd_checkout_error_checks', 'tcwf_edd_validate_custom_fields');
- // store the custom field data in the payment meta
- function tcwf_edd_store_custom_fields($payment_meta) {
- $payment_meta['phone'] = isset($_POST['edd_phone']) ? $_POST['edd_phone'] : '';
- $payment_meta['company'] = isset($_POST['edd_company']) ? $_POST['edd_company'] : '';
- $payment_meta['address'] = isset($_POST['edd_address']) ? $_POST['edd_address'] : '';
- return $payment_meta;
- }
- add_filter('edd_payment_meta', 'tcwf_edd_store_custom_fields');
- // show the custom fields in the "View Order Details" popup
- function tcwf_edd_purchase_details($payment_meta, $user_info) {
- $phone = isset($payment_meta['phone']) ? $payment_meta['phone'] : 'none';
- $company = isset($payment_meta['company']) ? $payment_meta['company'] : 'none';
- $address = isset($payment_meta['address']) ? $payment_meta['address'] : 'none';
- ?>
- <li><?php echo __('Phone:', 'tcwf') . ' ' . $phone; ?></li>
- <li><?php echo __('Company:', 'tcwf') . ' ' . $company; ?></li>
- <li><?php echo __('Shipping Address:', 'tcwf') . ' ' . $address; ?></li>
- <?php
- }
- add_action('edd_payment_personal_details_list', 'tcwf_edd_purchase_details', 10, 2);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement