Event Organiser Discount Codes 1.1

The discount codes extension for Event Organiser was released earlier today. This is a fairly minor update which fixes a minor JavaScript bug and adds four filters (2 client site, 2 server side):

  • eventorganiser.is_discount_valid – filters whether a discount is valid, client side
  • eventorganiser_is_discount_code_valid – filters whether a discount is valid, server side
  • eventorganiser.discount filters the discount object, client side
  • eventorganiser_discount_amount filters the discount’s amount, server side

(Don’t worry if this doesn’t mean anything to you – these are intended for developers). These hooks allow you to alter the behaviour of the discount code. For example, client side we have:

 jQuery(document).ready(function($) {
      wp.hooks.addFilter( 'eventorganiser.is_discount_valid', function( discounted, discount, cart ){
          //discount is an object, e.g. discount.code is the discount code: e.g "10PERCENT"

          //discounted should be a boolean allowing you to toggle where the discount code is valid
          return discounted;
      }, 5 );

      wp.hooks.addFilter( 'eventorganiser.discount', function( discount, cart ){
          //discount is an object, e.g. discount.code is the discount code: e.g "10PERCENT"
          return discount;
      }, 5 );
 });

(this will modify the effect of the discount code on the booking form).

Client scripts are only for user experience, to alter the behaviour of the discount code on the booking the you’ll need to use the server-side hooks:

function my_is_discount_code_valid( $is_valid, $discount, $booking_id = 0 ){
     //$discount is an array, e.g.  $discount['discount_code']  is the discount code

     //$is_valid is a boolean indicating whether the discount is valid.
     return $is_valid;
}
add_filter( 'eventorganiser_is_discount_code_valid', 'my_is_discount_code_valid', 10, 3 );

function my_discount_amount( $amount, $discount, $booking_id = 0 ){
     //$discount is an array, e.g.  $discount['discount_code']  is the discount code

     //$amount is a float - the discounted amount
     return $is_valid;
}
add_filter( 'eventorganiser_discount_amount', 'my_discount_amount', 10, 3 );