Skip to content

Instantly share code, notes, and snippets.

@corsonr
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corsonr/35dbc4ea73a1708ea69c to your computer and use it in GitHub Desktop.
Save corsonr/35dbc4ea73a1708ea69c to your computer and use it in GitHub Desktop.
WPdonations: Add a New Custom field
// Add your own function to filter the fields
add_filter( 'submit_donation_form_fields', 'add_submit_donation_form_fields' );
// This is your function which takes the fields, modifies them, and returns them
// You can see the fields which can be changed in: includes/forms/class-wpdonations-form-submit-donation.php
function add_submit_donation_form_fields( $fields ) {
// Here we register the new field
$fields['donor']['donor_phone'] = array(
'label' => __('Phone', 'wpdonations'),
'placeholder' => _x('Phone', 'placeholder', 'wpdonations'),
'type' => 'text',
'required' => true,
'priority' => 6
);
// And return the modified fields
return $fields;
}
// Hook function that save field(s) data
add_action( 'wpdonations_update_donation_data', 'frontend_add_fields_save', 10, 2 );
// Save field(s) data
function frontend_add_fields_save( $donation_id, $values ) {
// Duplicate the following line for each new field added
update_post_meta( $donation_id, '_donor_phone', $values['donor']['donor_phone'] );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment