Created
April 18, 2016 20:16
-
-
Save asharirfan/30a382894b5a62f2c9f8941d250529ea to your computer and use it in GitHub Desktop.
This gist is used to create custom fields in the checkout form of EDD (Easy Digital Downloads).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This gist is used to create custom fields in the | |
* checkout form of EDD (Easy Digital Downloads). | |
*/ | |
/** | |
* Adding HTML for User Contact Form. | |
*/ | |
function add_address_html() { | |
?> | |
<p id="edd-address-wrap"> | |
<label class="edd-label" for="edd-address"> | |
<?php _e( 'Delivery Address', 'edd' ); ?> | |
<span class="edd-required-indicator">*</span> | |
</label> | |
<span class="edd-description"> | |
<?php _e( 'We will deliver this product to this address.', 'edd' ); ?> | |
</span> | |
<textarea class="edd-input required" rows="6" name="edd_address" id="edd-address" placeholder="<?php _e( 'Delivery Address', 'edd' ); ?>" value=""></textarea> | |
</p> | |
<?php | |
} | |
add_action( 'edd_purchase_form_user_info', 'add_address_html' ); | |
/** | |
* Make address field required. | |
*/ | |
function make_address_required( $required_fields ) { | |
$required_fields = array( | |
'edd_address' => array( | |
'error_id' => 'invalid_address', | |
'error_message' => 'Please enter a valid delivery address.' | |
), | |
); | |
return $required_fields; | |
} | |
add_filter( 'edd_purchase_form_required_fields', 'make_address_required' ); | |
/** | |
* Check if address field is empty. | |
*/ | |
function check_address_empty( $valid_data, $data ) { | |
if ( empty( $data['edd_address'] ) ) { | |
edd_set_error( 'invalid_address', 'Please enter your delivery address.' ); | |
} | |
} | |
add_action( 'edd_checkout_error_checks', 'check_address_empty', 10, 2 ); | |
/** | |
* Store the address in the payment meta. | |
*/ | |
function store_address_meta( $payment_meta ) { | |
$payment_meta['address'] = isset($_POST['edd_address']) ? $_POST['edd_address'] : ''; | |
return $payment_meta; | |
} | |
add_filter( 'edd_payment_meta', 'store_address_meta' ); | |
/** | |
* Show the address in the "View Order Details" popup. | |
*/ | |
function address_edit_purchase_details( $payment_meta, $user_info ) { | |
$address = isset( $payment_meta['address'] ) ? $payment_meta['address'] : 'none'; | |
?> | |
<div class="column-container customer-info"> | |
<div class="column"> | |
<p><strong><?php echo __( 'Delivery Address:', 'pippin' ); ?></strong></p> | |
<p><?php printf( '%s', $address ); ?></p> | |
</div> | |
</div> | |
<?php | |
} | |
add_action( 'edd_payment_personal_details_list', 'address_edit_purchase_details', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment