eventsmanager

Surcharges and Discounts

Aug 21st, 2017
1,356
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /* For more information on how to add this snippet, please see http://wp-events-plugin.com/tutorials/how-to-safely-add-php-code-to-wordpress/ */
  3. /**
  4.  * Example function to show how surcharges and discounts can be added to a booking.
  5.  * @param EM_Event $EM_Event Not used, may be passed as false for multiple booking situations.
  6.  * @param EM_Booking $EM_Booking The Booking object being modified.
  7.  * @param boolean $post_validation Whether or not booking has passed validation, and therefore whether we should apply adjustments.
  8.  */
  9. function my_em_add_price_adjustments( $EM_Event, $EM_Booking, $post_validation ){
  10.     //Only apply surcharge if booking has passed validation and therefore can be saved to database
  11.     //You could also do further checks here if you want to give discounts to specific events or bookings
  12.     if( $post_validation ){
  13.         //Ensure we have arrays assigned to booking meta, if not create them to avoid PHP warnings
  14.         if( empty($EM_Booking->booking_meta['surcharges']) ) $EM_Booking->booking_meta['surcharges'] = array();
  15.         if( empty($EM_Booking->booking_meta['discounts']) ) $EM_Booking->booking_meta['discounts'] = array();
  16.        
  17.         //Example Surcharges
  18.        
  19.         //This one adds a fixed $25 surcharge and is applied before taxes
  20.         $EM_Booking->booking_meta['surcharges'][] = array(
  21.                 'name' => 'Special Surcharge',
  22.                 'desc' => 'Some type of surcharge description',
  23.                 'type' => '#', //numerical discount i.e. $10.00 off
  24.                 'amount' => '25.00',
  25.                 'tax' => 'pre' //discount applied BEFORE taxes have been added, and IS taxable
  26.         );
  27.         //This one adds a %3 surcharge, and is applied after taxes.
  28.         $EM_Booking->booking_meta['surcharges'][] = array(
  29.                 'name' => 'Handling Fee',
  30.                 'desc' => 'Some type of surcharge description',
  31.                 'type' => '%', //percentage discount of total price after taxes i.e. %3 extra
  32.                 'amount' => '3.00',
  33.                 'tax' => 'post' //discount applied AFTER taxes have been added, and IS NOT taxable
  34.         );
  35.        
  36.         //Example Discounts
  37.        
  38.         //This one adds a %3 discount before taxes have been applied.
  39.         $EM_Booking->booking_meta['discounts'][] = array(
  40.                 'name' => 'Handling Fee',
  41.                 'desc' => 'Some type of surcharge description',
  42.                 'type' => '%', //percentage discount of total price after taxes i.e. %3 extra
  43.                 'amount' => '3.00',
  44.                 'tax' => 'pre' //discount applied BEFORE taxes have been added, and IS taxable
  45.         );
  46.         //This oadds a $10 discount after taxes have been applied
  47.         $EM_Booking->booking_meta['discounts'][] = array(
  48.                 'name' => 'Super Special Discount',
  49.                 'desc' => 'Some type of discount description',
  50.                 'type' => '#', //numerical discount i.e. $10.00 off
  51.                 'amount' => '10.00',
  52.                 'tax' => 'post' //discount applied AFTER taxes have been added, and IS NOT taxable
  53.         );
  54.     }
  55. }
  56. add_action('em_booking_add', 'my_em_add_price_adjustments', 10, 3);
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×