Last active
August 29, 2015 14:01
-
-
Save corsonr/35dbc4ea73a1708ea69c to your computer and use it in GitHub Desktop.
WPdonations: Add a New Custom field
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
// 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