Add discount codes to ticket booking list

WordPress Event Management, Calendars & Registration Forums General Question Add discount codes to ticket booking list

This topic contains 6 replies, has 2 voices, and was last updated by  Alex Steer 9 years, 7 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #17607

    Is there a way to display and record the discount codes used on the bookings list?

    It’s not showing on my list so there is no way to tell which code was use on a transaction without working it out.

    Alex Steer
    #17617

    This one is strange.

    I have the dicount code column on my CSV but no code is in the cell.

    It isn’t in the booking info single view either.

    Alex Steer
    #17637

    Hi Alex,

    Yes, you’re right this should appear in the booking admin. In lieu of a more permanent solution (which will be subject to any potential reorganising of that screen) please us the following snippet which displays the VAT & discount code used on the booking admin page.

    //Add metabox
    add_action( 'admin_menu', function(){
        add_meta_box( 'my-discounts-tax', 'Discounts and tax', 'my_discount_tax_metabox_render', 'event_page_bookings', 'side' );
    });
    
    //Render metabox contents
    function my_discount_tax_metabox_render( $booking ){
    
        //Discount
        $discount = get_post_meta( $booking->ID, '_eo_booking_discount', true );
        $code     = isset( $discount['code'] ) ? $discount['code'] : false; 
        $amount   = get_post_meta( $booking->ID, '_eo_booking_discount_amount', true  );
        printf( '<p>Discount code: %s</p>', esc_html( $code ) );
        printf( '<p>Discount: %s</p>', eo_format_price( floatval( $amount ) ) );
    
        //VAT
        $vat_amount = get_post_meta( $booking->ID, '_eo_booking_vat_amount', true  );
        $vat_rate   = get_post_meta( $booking->ID, '_eo_booking_vat_percent', true  );
        printf( '<p>VAT (%s%%): %s</p>', intval( $vat_rate ), eo_format_price( floatval( $vat_amount ) ) );
    
    }
    

    The fact the discount code doesn’t appear in the CSV is a bug which I’ll look into.

    Stephen Harris
    #17650

    Hi Stephen,

    Thanks for this it looks much better in the admin now.

    I like this box 🙂 could we mod it a little for the benefit of all.

    Idea…

    Is it possible to have the box as a quick breakdown?

    Example:

    Transaction Overview<br>
    Ticket Value (x1): £342<br>
    VAT (20%): £47.88<br>
    Discount Code: 30SOM<br>
    Discount (30%): £102.60<br>
    Grand Total: £287.28<br>

    This would look cool.

    Alex Steer
    #17670

    You can display the tickets with:

     $tickets = eo_get_booking_tickets( $booking->ID );
     if( $tickets ){
          foreach( $tickets as $ticket ){
          printf( 
               '<p>%s : %s (x%d)</p>',
               esc_html( $ticket->ticket_name ),
               eo_format_price( $ticket->ticket_price ),
               intval( $ticket->ticket_quantity )
          );
     }
    

    and the total with

    $total = eo_get_booking_meta( $booking->ID, 'booking_amount' );
    echo eo_format_price( $total );
    
    Stephen Harris
    #17707

    Thanks Stephen that worked a treat!

    I have taken it further for anyone interested – please feel free to tidy or amend.

    function my_discount_tax_metabox_render( $booking ){ 
    // Tickets
    $tickets = eo_get_booking_tickets( $booking->ID );
                if( $tickets ){
                    $ticketsum = 0;
                    foreach( $tickets as $ticket ){
                    printf( 
                         '

    %s : %s (x%d)

    ', esc_html( $ticket->ticket_name ), eo_format_price( $ticket->ticket_price ), intval( $ticket->ticket_quantity ) ); $ticketsum+= $ticket->ticket_price; } printf('<hr>'); echo 'Booking value: ' . eo_format_price( $ticketsum ); } // VAT $vat_amount = get_post_meta( $booking->ID, '_eo_booking_vat_amount', true ); $vat_rate = get_post_meta( $booking->ID, '_eo_booking_vat_percent', true ); printf( '

    VAT (%s%%): %s

    ', intval( $vat_rate ), eo_format_price( floatval( $vat_amount ) ) ); // VAT Total $vat_total = $ticketsum + $vat_amount; printf('

    Subtotal: ' . eo_format_price( $vat_total ) . '

    <hr>'); // Discount code $discount = get_post_meta( $booking->ID, '_eo_booking_discount', true ); $code = isset( $discount['code'] ) ? $discount['code'] : false; $amount = get_post_meta( $booking->ID, '_eo_booking_discount_amount', true ); printf( '

    Discount code: %s

    ', esc_html( $code ) ); // Discount type amount $distype = isset( $discount['code'] ) ? ' (' . $discount['discount_type'] : false; $disamt = isset( $discount['code'] ) ? $discount['discount'] . ') ' : false; printf( '

    Discount:'. $distype . ' ' . $disamt .' - %s

    <hr>', eo_format_price( floatval( $amount ) ) ); // Final amount $total = eo_get_booking_meta( $booking->ID, 'booking_amount' ); printf('

    Final total: ' . eo_format_price( $total ) . '

    '); }
    Alex Steer
    #18044

    Stephen,

    The discount code is still not showing on the CSV… Is this due to be fixed?

    Also in the CSV, is it possible to report:
    Discount value (eg. -£35)
    Discount type (eg. 40%)
    VAT amount and percentage

    Thanks

    Alex Steer
Viewing 7 posts - 1 through 7 (of 7 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.