<?php
/*
This Snippet shows how to add surcharges and discounts to all bookings. Adjust accordingly.
Requires EM Pro 3.2.10 to work in MB mode.
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/
*/
class EM_Price_Adjustments {
public static function init() {
// Add adjustments to events or a whole MB booking, currently EM will not support adding individual charges to individual bookings in MB mode
if( get_option('dbem_multiple_bookings') ) {
// Add adjustments to a whole Multiple Booking, not individual events
add_action('em_multiple_booking_updated', array('EM_Price_Adjustments', 'add_mb_price_adjustments'), 10, 3);
} else {
// Add adjustments to the inidial default price if there are any pre-selected tickets.
add_filter('em_bookings_get_intent_default', array('EM_Price_Adjustments', 'get_intent_default'), 10);
// Adds price adjustments to individual event bookings, when booking is submitted (or submitted for a summary)
add_filter('em_booking_get_post', array('EM_Price_Adjustments', 'add_price_adjustments'), 1, 2);
}
}
/**
* Example function to show how surcharges and discounts can be added to a booking.
* @param boolean $result If previous post processing woas successful
* @param EM_Booking $EM_Booking The Booking object being modified.
* @return bool
*/
public static function add_price_adjustments( $result, $EM_Booking ){
//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( $result ){
//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();
// Add some adjustments, note that we're adding unique keys to the pricing adjustments, so that if we need to add/recalculate we don't add more than once.
//Example Surcharges
//This one adds a fixed $25 surcharge and is applied before taxes
$EM_Booking->booking_meta['surcharges']['special'] = 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']['handling_fee'] = 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']['handling_fee'] = array(
'name' => 'Handling Fee Discount',
'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']['super_special'] = 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
);
}
$EM_Booking->calculate_price();
return $result;
}
/**
* Example function for handling discounts and surcharges within Multiple Bookings. Adjustments are made (and can currently only be made) to the multiple booking object, not individual bookings.
* @param EM_Multiple_Booking Multiple Booking object, containing individual bookings within.
* @param mixed $booking_data - Supplied information to create EM_Multiple_Booking object.
* @return bool
* @see EM_Price_Adjustments::add_price_adjustments()
*/
public static function add_mb_price_adjustments( $event_id, $EM_Booking, $EM_Multiple_Booking ){
//$bookings_data must be empty here, because otherwise it means this booking object already existed at one point.
return static::add_price_adjustments(true, $EM_Multiple_Booking);
}
/**
* Adds price adjustments to default pre-selected tickets, which is reflected on page load in booking summary.
* @param EM_Booking $EM_Booking
* @return EM_Booking
* @see EM_Price_Adjustments::add_price_adjustments()
*/
public static function get_intent_default( $EM_Booking ){
if( $EM_Booking ) {
static::add_price_adjustments( true, $EM_Booking );
return $EM_Booking;
}
return $EM_Booking;
}
}
EM_Price_Adjustments::init();
Comments
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎