eventsmanager

Adding Donation or Surcharge to Payment Gateways

Aug 8th, 2019
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. <?php
  2. /*
  3. This snippet will allow you to add a donation text field to your Events Manager Pro booking form, which will then add that amount to the total payment when redirected to PayPal, Stripe or Offline Payment Gateways.
  4.  
  5. Instructions:
  6.  
  7. 1. in your Forms Editor, create a new field
  8. – label => Donation Amount
  9. – field id => donation_amount
  10. – type => select; then under option you can add the amount per line
  11.  
  12. 2. In your theme functions.php; paste the following snippet or for complete guide you can visit http://wp-events-plugin.com/tutorials/how-to-safely-add-php-code-to-wordpress/
  13.  
  14. Reference: https://eventsmanagerpro.com/support/questions/donation-option-3/
  15.  
  16. */
  17.  
  18. function my_em_price_adjustments( $EM_Event, $EM_Booking, $post_validation ){
  19.     if( $post_validation ){
  20.  
  21.         if( empty($EM_Booking->booking_meta['surcharges']) ) $EM_Booking->booking_meta['surcharges'] = array();
  22.        
  23.         //donation_amount = Field Id from Events > Forms Editor
  24.         $amount = ( !empty($EM_Booking->booking_meta['booking']['donation_amount']) ) ? $EM_Booking->booking_meta['booking']['donation_amount']:1;
  25.        
  26.         $label = "Test Surcharge";
  27.        
  28.         $EM_Booking->booking_meta['surcharges'][] = array(
  29.                 'name' => $label,
  30.                 //'desc' => 'Some type of surcharge description',
  31.                 'type' => '#', //numerical discount i.e. $10.00 off
  32.                 'amount' => $amount,
  33.                 'tax' => 'pre' //discount applied BEFORE taxes have been added, and IS taxable
  34.         );
  35.        
  36.    
  37.     }//END - if( $post_validation ){
  38. }
  39. add_action('em_booking_add', 'my_em_price_adjustments', 10, 3);
Add Comment
Please, Sign In to add comment