Advertisement
eventsmanager

adding surcharges

Oct 4th, 2023
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. <?php
  2. function my_em_add_price_adjustments( $EM_Event, $EM_Booking, $post_validation ){
  3. //Only apply surcharge if booking has passed validation and therefore can be saved to database
  4. //You could also do further checks here if you want to give discounts to specific events or bookings
  5. if( $post_validation ){
  6.  
  7. //Ensure we have arrays assigned to booking meta, if not create them to avoid PHP warnings
  8. if( empty($EM_Booking->booking_meta['surcharges']) ) $EM_Booking->booking_meta['surcharges'] = array();
  9.  
  10. //This one adds a fixed $25 surcharge and is applied before taxes
  11. $prix = $EM_Booking->get_price_pre_taxes();
  12. $pourcentage = 3;
  13. $fixe = 0.35;
  14. $amount = ($prix * ($pourcentage/100)) + $fixe;
  15. $EM_Booking->booking_meta['surcharges'][] = array(
  16. 'name' => 'Frais Paypal',
  17. 'desc' => 'Frais Paypal',
  18. 'type' => '#', //numerical discount i.e. $10.00 off
  19. 'amount' => $amount,
  20. 'tax' => 'pre' //discount applied BEFORE taxes have been added, and IS taxable
  21. );
  22. }
  23. }
  24. add_action('em_booking_add', 'my_em_add_price_adjustments', 10, 3);
  25. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement