<?php
/* 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/ */
/**
* Example function to show how surcharges and discounts can be added to a booking.
* @param EM_Event $EM_Event Not used, may be passed as false for multiple booking situations.
* @param EM_Booking $EM_Booking The Booking object being modified.
* @param boolean $post_validation Whether or not booking has passed validation, and therefore whether we should apply adjustments.
*/
function my_em_add_price_adjustments( $EM_Event, $EM_Booking, $post_validation ){
//Only apply surcharge if booking has passed validation and therefore can be saved to database
//You could also do further checks here if you want to give discounts to specific events or bookings
if( $post_validation ){
//Ensure we have arrays assigned to booking meta, if not create them to avoid PHP warnings
if( empty($EM_Booking->booking_meta['surcharges']) ) $EM_Booking->booking_meta['surcharges'] = array();
if( empty($EM_Booking->booking_meta['discounts']) ) $EM_Booking->booking_meta['discounts'] = array();
//Example Surcharges
//This one adds a fixed $25 surcharge and is applied before taxes
$EM_Booking->booking_meta['surcharges'][] = array(
'name' => 'Special Surcharge',
'desc' => 'Some type of surcharge description',
'type' => '#', //numerical discount i.e. $10.00 off
'amount' => '25.00',
'tax' => 'pre' //discount applied BEFORE taxes have been added, and IS taxable
);
//This one adds a %3 surcharge, and is applied after taxes.
$EM_Booking->booking_meta['surcharges'][] = array(
'name' => 'Handling Fee',
'desc' => 'Some type of surcharge description',
'type' => '%', //percentage discount of total price after taxes i.e. %3 extra
'amount' => '3.00',
'tax' => 'post' //discount applied AFTER taxes have been added, and IS NOT taxable
);
//Example Discounts
//This one adds a %3 discount before taxes have been applied.
$EM_Booking->booking_meta['discounts'][] = array(
'name' => 'Handling Fee',
'desc' => 'Some type of surcharge description',
'type' => '%', //percentage discount of total price after taxes i.e. %3 extra
'amount' => '3.00',
'tax' => 'pre' //discount applied BEFORE taxes have been added, and IS taxable
);
//This oadds a $10 discount after taxes have been applied
$EM_Booking->booking_meta['discounts'][] = array(
'name' => 'Super Special Discount',
'desc' => 'Some type of discount description',
'type' => '#', //numerical discount i.e. $10.00 off
'amount' => '10.00',
'tax' => 'post' //discount applied AFTER taxes have been added, and IS NOT taxable
);
}
}
add_action('em_booking_add', 'my_em_add_price_adjustments', 10, 3);
Comments