Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2017
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.01 KB | None | 0 0
  1. <?php
  2. // add the following lines to change the label for Offline Donations
  3. function my_custom_gateway_labels( $gateways ) {
  4. // add the following 4 lines to change the label for Offline Donations
  5. $gateways['offline'] = array(
  6. 'admin_label' => 'Offline Donation',
  7. 'checkout_label' => __( 'Mail a Check', 'give' ),
  8. );
  9. // add the following 4 lines to change the label for PayPal Standard
  10. $gateways['paypal'] = array(
  11. 'admin_label' => 'PayPal Standard',
  12. 'checkout_label' => __( 'Credit/Debit Card or PayPal', 'give' ),
  13. );
  14.  
  15. return $gateways;
  16. }
  17. add_filter( 'give_payment_gateways', 'my_custom_gateway_labels', 10 );
  18.  
  19. /**
  20. * Validation donation amount. Note: Give handles validation minimum amount out-of-the-box.
  21. *
  22. * Check that a donation is above or below a maximum amount.
  23. *
  24. * @param $valid_data
  25. * @param $data
  26. */
  27. function give_donations_validate_donation_amount( $valid_data, $data ) {
  28. // Only validate the form with the IDs "754" and "586";
  29. // Remove "If" statement to validation for all forms
  30. // For a single form, use this instead:
  31.  
  32. // $forms = array( 1425 );
  33. // if ( ! in_array( $data['give-form-id'], $forms ) ) {
  34. // return;
  35. // }
  36.  
  37. $sanitized_amount = (int) give_sanitize_amount( $data['give-amount'] );
  38. $max_amount = 190;
  39.  
  40. //Check for message data
  41. if ( $sanitized_amount > $max_amount ) {
  42. give_set_error( 'give_message', sprintf( __( 'Sorry, we can\'t accept donations more than %s.', 'give' ), give_currency_filter( give_format_amount( $max_amount ) ) ) );
  43. }
  44.  
  45. }
  46.  
  47. add_action( 'give_checkout_error_checks', 'give_donations_validate_donation_amount', 10, 2 );
  48.  
  49. /**
  50. * Add Custom Donation Form Fields
  51. *
  52. * @param $form_id
  53. */
  54. function give_myprefix_custom_form_fields( $form_id ) {
  55. // Only display for forms with the IDs "754" and "578";
  56. // Remove "If" statement to display on all forms
  57. // For a single form, use this instead:
  58. // if ( $form_id == 754) {
  59. ( $form_id == 128); ?>
  60. <div id="give-referral-wrap">
  61. <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>
  62. </label>
  63. <textarea class="give-textarea" name="give_referral" id="give-referral"></textarea>
  64. </div>
  65. <?php
  66. }
  67.  
  68. add_action( 'give_donation_form_after_email', 'give_myprefix_custom_form_fields', 10, 1 );
  69.  
  70. /**
  71. * Validate Custom Field
  72. *
  73. * Check for errors without custom fields
  74. *
  75. * @param $valid_data
  76. * @param $data
  77. */
  78. function give_myprefix_validate_custom_fields( $valid_data, $data ) {
  79. // Only validate the form with the IDs "754" and "578";
  80. // Remove "If" statement to display on all forms
  81. // For a single form, use this instead:
  82. // if ( $form_id == 754) {
  83. ( $form_id == 128);
  84. {
  85. $required_fields['give_referral'] = array(
  86. 'error_id' => 'invalid_give_referral',
  87. 'error_message' => __( 'Please tell us your occupation and employer (required by California state law).', 'give' ),
  88. );
  89. }
  90.  
  91. return $required_fields;
  92. }
  93.  
  94. add_filter( 'give_donation_form_required_fields', 'give_myprefix_validate_custom_fields', 10, 2 );
  95.  
  96. /**
  97. * Add Field to Payment Meta
  98. *
  99. * Store the custom field data custom post meta attached to the `give_payment` CPT.
  100. *
  101. * @param $payment_id
  102. * @param $payment_data
  103. *
  104. * @return mixed
  105. */
  106. function myprefix123_give_donations_save_custom_fields( $payment_id, $payment_data ) {
  107. if ( isset( $_POST['give_referral'] ) ) {
  108. $message = implode( "\n", array_map( 'sanitize_text_field', explode( "\n", $_POST['give_referral'] ) ) );
  109. add_post_meta( $payment_id, 'give_referral', $message );
  110. }
  111. }
  112.  
  113. add_action( 'give_insert_payment', 'myprefix123_give_donations_save_custom_fields', 10, 2 );
  114.  
  115. /**
  116. * Show Data in Payment Details
  117. *
  118. * Show the custom field(s) on the payment details page in wp-admin
  119. *
  120. * @param $payment_meta
  121. * @param $user_info
  122. */
  123. function give_myprefix_purchase_details( $payment_meta, $user_info ) {
  124. // Bounce out if no data for this transaction
  125. $give_referral = get_post_meta( $payment_id, 'give_referral', true );
  126. if ( $give_referral ) : ?>
  127. <div class="referral-data">
  128. <label><?php _e( 'Referral:', 'give' ); ?></label>
  129. <?php echo wpautop( $give_referral ); ?>
  130. </div>
  131. <?php endif;
  132. }
  133.  
  134. add_action( 'give_payment_personal_details_list', 'give_myprefix_purchase_details', 10, 2 );
  135.  
  136. /**
  137. * Require Last Name Snippet.
  138. *
  139. * Adds asterisk and error validation to the last name field of all Give forms.
  140. *
  141. * @param $required_fields
  142. * @param $form_id
  143. *
  144. * @return mixed
  145. */
  146. function give_require_last_name( $required_fields, $form_id ) {
  147. $required_fields['give_last'] = array(
  148. 'error_id' => 'invalid_last_name',
  149. 'error_message' => __( 'Please enter your last name', 'give' )
  150. );
  151. return $required_fields;
  152. }
  153. add_filter( 'give_donation_form_required_fields', 'give_require_last_name', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement