Skip to content

Instantly share code, notes, and snippets.

@samikeijonen
Created November 9, 2013 10:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samikeijonen/7383928 to your computer and use it in GitHub Desktop.
Save samikeijonen/7383928 to your computer and use it in GitHub Desktop.
How to remove and add own address fields in checkout for EDD.
function edd_paytrail_address_fields() {
$logged_in = is_user_logged_in();
if( $logged_in ) {
$user_address = get_user_meta( get_current_user_id(), '_edd_user_address', true );
}
$line1 = $logged_in && ! empty( $user_address['line1'] ) ? $user_address['line1'] : '';
$city = $logged_in && ! empty( $user_address['city'] ) ? $user_address['city'] : '';
$zip = $logged_in && ! empty( $user_address['zip'] ) ? $user_address['zip'] : '';
ob_start(); ?>
<fieldset id="edd_cc_address" class="cc-address">
<span><legend><?php _e( 'Billing Details', 'edd-paytrail' ); ?></legend></span>
<?php do_action( 'edd_cc_billing_top' ); ?>
<p id="edd-card-address-wrap">
<label for="card_address" class="edd-label">
<?php _e( 'Billing Address', 'edd-paytrail' ); ?>
<span class="edd-required-indicator">*</span>
</label>
<span class="edd-description"><?php _e( 'This is your billing address.', 'edd-paytrail' ); ?></span>
<input type="text" id="card_address" name="card_address" class="card-address edd-input required" placeholder="<?php _e( 'Address line', 'edd-paytrail' ); ?>" value="<?php echo $line1; ?>" />
</p>
<p id="edd-card-zip-wrap">
<label for="card_zip" class="edd-label">
<?php _e( 'Billing Zip / Postal Code', 'edd-paytrail' ); ?>
<span class="edd-required-indicator">*</span>
</label>
<span class="edd-description"><?php _e( 'The zip or postal code for your billing address.', 'edd-paytrail' ); ?></span>
<input type="text" size="4" name="card_zip" class="card-zip edd-input required" placeholder="<?php _e( 'Zip / Postal code', 'edd-paytrail' ); ?>" value="<?php echo $zip; ?>" />
</p>
<p id="edd-card-city-wrap">
<label for="card_city" class="edd-label">
<?php _e( 'Billing City', 'edd-paytrail' ); ?>
<span class="edd-required-indicator">*</span>
</label>
<span class="edd-description"><?php _e( 'The city for your billing address.', 'edd-paytrail' ); ?></span>
<input type="text" id="card_city" name="card_city" class="card-city edd-input required" placeholder="<?php _e( 'City', 'edd-paytrail' ); ?>" value="<?php echo $city; ?>" />
</p>
<p id="edd-card-country-wrap">
<label for="billing_country" class="edd-label">
<?php _e( 'Billing Country', 'edd-paytrail' ); ?>
<span class="edd-required-indicator">*</span>
</label>
<span class="edd-description"><?php _e( 'The country for your billing address.', 'edd-paytrail' ); ?></span>
<select id="billing_country" name="billing_country" id="billing_country" class="billing_country edd-select required">
<?php
$selected_country = edd_get_shop_country();
if( $logged_in && ! empty( $user_address['country'] ) && '*' !== $user_address['country'] ) {
$selected_country = $user_address['country'];
}
$countries = edd_get_country_list();
foreach( $countries as $country_code => $country ) {
echo '<option value="' . $country_code . '"' . selected( $country_code, $selected_country, false ) . '>' . $country . '</option>';
}
?>
</select>
</p>
<p id="edd-card-company-wrap">
<label for="card_company" class="edd-label"><?php _e( 'Company', 'edd-paytrail' ); ?></label>
<span class="edd-description"><?php _e( 'The name of your company.', 'edd-paytrail' ); ?></span>
<input type="text" id="card_company" name="card_company" class="card-company edd-input required" placeholder="<?php _e( 'Company', 'edd-paytrail' ); ?>" value="" />
</p>
<?php do_action( 'edd_cc_billing_bottom' ); ?>
</fieldset>
<?php
echo ob_get_clean();
}
remove_action( 'edd_purchase_form_after_cc_form', 'edd_checkout_tax_fields', 999 ); // Remove original address fields.
add_action( 'edd_purchase_form_after_cc_form', 'edd_paytrail_address_fields', 999 ); // Add own address fields.
add_action( 'edd_paytrail_cc_form', '__return_false' ); // Remove credit card info.
@wbijster
Copy link

Many thanks! I only needed the remove_action (to get a lean EDD check out with just name and email) and not knowing PHP I was really struggling... -> the remove_action works perfect, I am very happy with that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment