• Resolved coreyharrison79

    (@coreyharrison79)


    Hi ,
    I’m using your plugin with events manager. It’s working perfectly to process event payments, however I’m trying to get events manager to add an additional items check box that will then pass the additional cost through to eway as they register for an event.

    I’m using this code

    function my_em_add_paypal_surcharge($paypal_vars, $EM_Booking, $EM_Gateway_Paypal){
    
    	$EM_Tickets_Bookings = $EM_Booking->get_tickets_bookings();
    	$attendee_datas = EM_Attendees_Form::get_booking_attendees($EM_Booking);
    	$attendee_list = "";
    	$count = 1;
    	foreach( $EM_Tickets_Bookings->tickets_bookings as $EM_Ticket_Booking ){
    
    		$price = $EM_Ticket_Booking->get_price() / $EM_Ticket_Booking->get_spaces();
    		if( $price > 0 ){
    			$paypal_vars['item_name_'.$count] = wp_kses_data($EM_Ticket_Booking->get_ticket()->name);
    			$paypal_vars['quantity_'.$count] = $EM_Ticket_Booking->get_spaces();
    			$paypal_vars['amount_'.$count] = round($price,2);
    		}
    
    		$subitem_count = ($count + 1);
    		for( $i = 0; $i < $EM_Ticket_Booking->ticket_booking_spaces; $i++ ){
    			$fields = $EM_Booking->booking_meta['attendees'][$EM_Ticket_Booking->ticket_id][$i];
    
    			$amount = $fields['tshirt_amount'];
    
    			$paypal_vars['item_name_'.$subitem_count] = wp_kses_data( 'Tshirt' );
    			$paypal_vars['quantity_'.$subitem_count] = 1;
    			$paypal_vars['amount_'.$subitem_count] = round($amount,2);
    			$count = $subitem_count;
    			$subitem_count++;
    		}
    
    		$count++;
    	}	
    
    	return $paypal_vars;
    }
    add_filter('em_gateway_paypal_get_paypal_vars','my_em_add_paypal_surcharge',1,3);
    

    which is from a thread on the EM pro forum. I have modified it here:

    function my_em_add_eway_surcharge($eway_vars, $EM_Booking, $EwayPaymentsEventsManager){
    
    	$EM_Tickets_Bookings = $EM_Booking->get_tickets_bookings();
    	$attendee_datas = EM_Attendees_Form::get_booking_attendees($EM_Booking);
    	$attendee_list = "";
    	$count = 1;
    	foreach( $EM_Tickets_Bookings->tickets_bookings as $EM_Ticket_Booking ){
    
    		$price = $EM_Ticket_Booking->get_price() / $EM_Ticket_Booking->get_spaces();
    		if( $price > 0 ){
    			$eway_vars['item_name_'.$count] = wp_kses_data($EM_Ticket_Booking->get_ticket()->name);
    			$eway_vars['quantity_'.$count] = $EM_Ticket_Booking->get_spaces();
    			$eway_vars['amount_'.$count] = round($price,2);
    		}
    
    		$subitem_count = ($count + 1);
    		for( $i = 0; $i < $EM_Ticket_Booking->ticket_booking_spaces; $i++ ){
    			$fields = $EM_Booking->booking_meta['attendees'][$EM_Ticket_Booking->ticket_id][$i];
    
    			$amount = $fields['tshirt_amount'];
    
    			$eway_vars['item_name_'.$subitem_count] = wp_kses_data( 'Tshirt' );
    			$eway_vars['quantity_'.$subitem_count] = 1;
    			$eway_vars['amount_'.$subitem_count] = round($amount,2);
    			$count = $subitem_count;
    			$subitem_count++;
    		}
    
    		$count++;
    	}	
    
    	return $eway_vars;
    }
    add_filter('em_gateway_eway_get_eway_vars','my_em_add_eway_surcharge',1,3);

    to try and get it to pass the payment on to eway but it isn’t working.

    I’m not sure if I have it right so I thought I’d see if you could see any glaring issues.
    Any help you could give me would be brilliant.

    Thanks

    https://www.ads-software.com/plugins/eway-payment-gateway/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author webaware

    (@webaware)

    G’day Corey,

    I looked at using one of the standard filters to change the price, but it keeps getting reset to the pre-filtered price just before calling the payment process, so I’ve added a new filter to the eWAY plugin. Please update to v3.1.2 to get the new filter.

    Here’s an example of how to use it, based on a checkbox field called extra_fee.

    /**
    * add a fee to the Events Manager booking price for eWAY
    * @param float $price
    * @param EM_Booking $booking
    * @return float
    */
    function my_em_eway_added_fee($price, $EM_Booking) {
        // define your additional fee
        $extra_fee = 2.0;
    
        if (!empty($EM_Booking->booking_meta['booking']['extra_fee'])) {
            $price += $extra_fee;
        }
    
        return $price;
    }
    
    add_filter('em_eway_amount', 'my_em_eway_added_fee', 10, 2);

    cheers,
    Ross

    Thread Starter coreyharrison79

    (@coreyharrison79)

    Hi Ross,
    Thanks so much for this!
    Would I add this code to my theme functions.php or somewhere in the eway gateway plugin?

    Cheers

    Plugin Author webaware

    (@webaware)

    easiest to add it to you theme functions.php file.

    Thread Starter coreyharrison79

    (@coreyharrison79)

    Ok…
    I have tried and tried again, but cannot get this to work!
    I’m sure it’s something I’m doing wrong but can’t work it out.
    I’ll tell you exactly what I’m doing to see if you can spot anything obvious that I’ve missed.

    1. I’ve pasted your code into my theme function.php file.
    2. Created a field in Events Manager Attendees Form with an ID of extra_fee
    (I wasn’t sure if it being in the attendee form was causing it not to pass on but I tried it in the main booking form with no joy.)
    3. Registered for an event and made payment with eWay (sandbox).

    The results were that the ticket price was processed as normal, but the extra fee was not added on.

    I’m just really stuck with this so if you have any thoughts on how I could debug this that would be great.

    Thanks again

    Plugin Author webaware

    (@webaware)

    When you say the extra fee wasn’t added on, do you mean:

    1. it wasn’t added on at eWAY
    2. the recorded ticket total didn’t include it

    I ask because the code you showed for PayPal adds the charge to PayPal but not to the ticket price, and this filter does the same. If you look at a booking in the admin, it should have just the ticket prices recorded for the booking itself, but the transaction below should show the price including extras.

    Also: didn’t realise you wanted extra fees charged per attendee, here’s an updated filter function for that.

    /**
    * add a fee to the Events Manager booking price for eWAY
    * @param float $price
    * @param EM_Booking $booking
    * @return float
    */
    function my_em_eway_added_fee($price, $EM_Booking) {
        // define your additional fee
        $extra_fee = 2.0;
    
        // extra fee on booking
        if (!empty($EM_Booking->booking_meta['booking']['extra_fee'])) {
            $price += $extra_fee;
        }
    
        // extra fee on attendees
        $EM_Ticket_Bookings = $EM_Booking->get_tickets_bookings();
        foreach ($EM_Ticket_Bookings->tickets_bookings as $EM_Ticket_Booking) {
            foreach ($EM_Booking->booking_meta['attendees'][$EM_Ticket_Booking->ticket_id] as $attendee) {
                if (!empty($attendee['extra_fee'])) {
                    $price += $extra_fee;
                }
            }
        }
    
        return $price;
    }
    
    add_filter('em_eway_amount', 'my_em_eway_added_fee', 10, 2);

    cheers,
    Ross

    Thread Starter coreyharrison79

    (@coreyharrison79)

    Hi Ross
    Thanks for getting back to me so quickly.
    No the extra fee wasn’t recorded in eWay either in the EM admin for the transaction or in the eWay admin. I’ll give this a try (hopefully it work).
    If I can’t get it happening I might get quote off you to get it up and running for me if you’d be interested.

    Thanks again
    Corey

    Plugin Author webaware

    (@webaware)

    No worries, hit me via my contact page if you run into problems.

    cheers,
    Ross

    Thread Starter coreyharrison79

    (@coreyharrison79)

    It worked!! Thank you so much.
    I’m just thinking, how complicated would it be if I wanted to add multiple check boxes?
    I’m assuming that I can’t just duplicate this block of code.

    I’m trying to learn a bit of PHP at the moment via codecademy.com, but I’m still yet to fully grasp how to actually do anything.

    Thanks again.

    Plugin Author webaware

    (@webaware)

    Good stuff!

    To add more checkboxes, duplicate this bit of code and change the field name (and fee, if required).

    if (!empty($attendee['extra_fee'])) {
        $price += $extra_fee;
    }

    cheers,
    Ross

    Thread Starter coreyharrison79

    (@coreyharrison79)

    Perfect!
    Thank you so much, You’re a saint!

    Thread Starter coreyharrison79

    (@coreyharrison79)

    ??

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Events Manager Integration’ is closed to new replies.