Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // add the following lines to change the label for Offline Donations
- function my_custom_gateway_labels( $gateways ) {
- // add the following 4 lines to change the label for Offline Donations
- $gateways['offline'] = array(
- 'admin_label' => 'Offline Donation',
- 'checkout_label' => __( 'Mail a Check', 'give' ),
- );
- // add the following 4 lines to change the label for PayPal Standard
- $gateways['paypal'] = array(
- 'admin_label' => 'PayPal Standard',
- 'checkout_label' => __( 'Credit/Debit Card or PayPal', 'give' ),
- );
- return $gateways;
- }
- add_filter( 'give_payment_gateways', 'my_custom_gateway_labels', 10 );
- /**
- * Validation donation amount. Note: Give handles validation minimum amount out-of-the-box.
- *
- * Check that a donation is above or below a maximum amount.
- *
- * @param $valid_data
- * @param $data
- */
- function give_donations_validate_donation_amount( $valid_data, $data ) {
- // Only validate the form with the IDs "754" and "586";
- // Remove "If" statement to validation for all forms
- // For a single form, use this instead:
- // $forms = array( 1425 );
- // if ( ! in_array( $data['give-form-id'], $forms ) ) {
- // return;
- // }
- $sanitized_amount = (int) give_sanitize_amount( $data['give-amount'] );
- $max_amount = 190;
- //Check for message data
- if ( $sanitized_amount > $max_amount ) {
- give_set_error( 'give_message', sprintf( __( 'Sorry, we can\'t accept donations more than %s.', 'give' ), give_currency_filter( give_format_amount( $max_amount ) ) ) );
- }
- }
- add_action( 'give_checkout_error_checks', 'give_donations_validate_donation_amount', 10, 2 );
- /**
- * Add Custom Donation Form Fields
- *
- * @param $form_id
- */
- function give_myprefix_custom_form_fields( $form_id ) {
- // Only display for forms with the IDs "754" and "578";
- // Remove "If" statement to display on all forms
- // For a single form, use this instead:
- // if ( $form_id == 754) {
- ( $form_id == 128); ?>
- <div id="give-referral-wrap">
- <label class="give-label" for="give-referral"><?php _e( 'Occupation and Employer? Required by California Law.:', 'give' ); ?> <span class="give-tooltip icon icon-question" data-tooltip="<?php _e( 'Please take a second to tell us how you first heard about Girl Develop It.', 'give' ) ?>"></span>
- </label>
- <textarea class="give-textarea" name="give_referral" id="give-referral"></textarea>
- </div>
- <?php
- }
- add_action( 'give_donation_form_after_email', 'give_myprefix_custom_form_fields', 10, 1 );
- /**
- * Validate Custom Field
- *
- * Check for errors without custom fields
- *
- * @param $valid_data
- * @param $data
- */
- function give_myprefix_validate_custom_fields( $valid_data, $data ) {
- // Only validate the form with the IDs "754" and "578";
- // Remove "If" statement to display on all forms
- // For a single form, use this instead:
- // if ( $form_id == 754) {
- ( $form_id == 128);
- {
- $required_fields['give_referral'] = array(
- 'error_id' => 'invalid_give_referral',
- 'error_message' => __( 'Please tell us your occupation and employer (required by California state law).', 'give' ),
- );
- }
- return $required_fields;
- }
- add_filter( 'give_donation_form_required_fields', 'give_myprefix_validate_custom_fields', 10, 2 );
- /**
- * Add Field to Payment Meta
- *
- * Store the custom field data custom post meta attached to the `give_payment` CPT.
- *
- * @param $payment_id
- * @param $payment_data
- *
- * @return mixed
- */
- function myprefix123_give_donations_save_custom_fields( $payment_id, $payment_data ) {
- if ( isset( $_POST['give_referral'] ) ) {
- $message = implode( "\n", array_map( 'sanitize_text_field', explode( "\n", $_POST['give_referral'] ) ) );
- add_post_meta( $payment_id, 'give_referral', $message );
- }
- }
- add_action( 'give_insert_payment', 'myprefix123_give_donations_save_custom_fields', 10, 2 );
- /**
- * Show Data in Payment Details
- *
- * Show the custom field(s) on the payment details page in wp-admin
- *
- * @param $payment_meta
- * @param $user_info
- */
- function give_myprefix_purchase_details( $payment_meta, $user_info ) {
- // Bounce out if no data for this transaction
- $give_referral = get_post_meta( $payment_id, 'give_referral', true );
- if ( $give_referral ) : ?>
- <div class="referral-data">
- <label><?php _e( 'Referral:', 'give' ); ?></label>
- <?php echo wpautop( $give_referral ); ?>
- </div>
- <?php endif;
- }
- add_action( 'give_payment_personal_details_list', 'give_myprefix_purchase_details', 10, 2 );
- /**
- * Require Last Name Snippet.
- *
- * Adds asterisk and error validation to the last name field of all Give forms.
- *
- * @param $required_fields
- * @param $form_id
- *
- * @return mixed
- */
- function give_require_last_name( $required_fields, $form_id ) {
- $required_fields['give_last'] = array(
- 'error_id' => 'invalid_last_name',
- 'error_message' => __( 'Please enter your last name', 'give' )
- );
- return $required_fields;
- }
- add_filter( 'give_donation_form_required_fields', 'give_require_last_name', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement