/** * Collect the donor's National ID # in the donation form. * * Fields are added as a PHP array that define the field. You can customize the * following fields: * * label: The label that will be displayed alongside the field. * placeholder: Optionally, you can display a placeholder value to be shown inside the field. * type: The type of field. Options: text, checkbox, datepicker, editor, file, multi-checkbox, number, picture, radio, select, textarea, url * priority: The priority of the field. This determines where in the form the field is displayed. * value: The current/default value of the field. * required: Whether the field is required. Set to `true` or `false`. * data_type: How the field is saved in the database. The simplest option is to use `user` as in the example below, which will automatically save the field to the user meta table. * * @param array[] $fields * @param Charitable_Donation_Form $form * @return array[] */ function ed_collect_national_id_number($fields, Charitable_Donation_Form $form) { /** * If you only want to collect a certain field on a certain campaign's * donation form, uncomment this next section and replace 1234 with the * ID of your campaign. */ // if ( 1234 != $form->get_campaign()->ID ) { // return $fields; // } $fields['national_id_number'] = array('label' => __('National ID Number', 'your-namespace'), 'type' => 'text', 'priority' => 24, 'value' => $form->get_user_value('donor_national_id_number'), 'required' => true, 'data_type' => 'user'); return $fields; }
/** * Set up callbacks for actions and filters. * * @return void * @access protected * @since 1.0.0 */ protected function attach_hooks_and_filters() { parent::attach_hooks_and_filters(); remove_filter('charitable_donation_form_gateway_fields', array($this, 'add_credit_card_fields'), 10, 2); remove_action('charitable_donation_form_after_user_fields', array($this, 'add_password_field')); do_action('charitable_donation_amount_form_start', $this); }
/** * Collect the donor's National ID # in the donation form. * * @param array[] $fields * @param Charitable_Donation_Form $form * @return array[] */ function ed_collect_national_id_number($fields, Charitable_Donation_Form $form) { $fields['national_id_number'] = array('label' => __('National ID Number', 'your-namespace'), 'type' => 'text', 'priority' => 24, 'value' => $form->get_user_value('donor_national_id_number'), 'required' => true, 'data_type' => 'user'); return $fields; }
/** * Save the submitted donation. * * @return int|false If successful, this returns the donation ID. If unsuccessful, returns false. * @access public * @since 1.0.0 */ public function save_donation() { $campaign_id = charitable_get_current_campaign_id(); if (!$campaign_id) { return 0; } if (!$this->validate_nonce()) { return 0; } /* Set the donation amount */ $campaign_id = $this->get_campaign()->ID; $amount = parent::get_donation_amount(); if (0 == $amount && !apply_filters('charitable_permit_empty_donations', false)) { charitable_get_notices()->add_error(__('No donation amount was set.', 'charitable')); return false; } /* Create or update the donation object in the session, with the current campaign ID. */ charitable_get_session()->add_donation($campaign_id, $amount); do_action('charitable_donation_amount_form_submit', $campaign_id, $amount); return true; }
/** * Add a password field to the end of the form. * * @param Charitable_Donation_Form $form * @return void * @access public * @since 1.0.0 */ public function add_password_field($form) { if (!$form->is_current_form($this->id)) { return; } /** * Make sure we are not logged in. */ if (0 !== wp_get_current_user()->ID) { return; } charitable_template('donation-form/user-login-fields.php'); }