Support

Home Forums Event Espresso Premium Code not working from Partial Payments wiki article

Code not working from Partial Payments wiki article

Posted: January 29, 2014 at 10:36 pm

Viewing 5 reply threads


Erica Neubauer

    January 29, 2014 at 10:36 pm

    Hi,
    I’m trying to get partial payments to work with my event registration. I came across this wiki article:
    http://staging.eventespresso.com/wiki/setting-partial-payments-ee/
    which explains everything very clearly. However, when I copy and paste the raw code for the second function (which starts with <?php
    function espresso_get_total_cost_custom($payment_data) { etc) it just gives an error. I tried it in my functions.php (which made the whole site stop working!) and then tried it in the blank plugin for custom functions, where it said it was deactivated for a fatal error.
    I would really appreciate some help, I’ve got a whole bunch of clients who have already made partial payments and now are struggling with trying to pay the correct amount owing.


    Dean

    • Support Staff

    January 30, 2014 at 6:06 am

    Hi

    “it just gives an error”

    What’s the exact error please.


    Erica Neubauer

      January 30, 2014 at 5:55 pm

      Yeah, sorry that would have been helpful.

      Parse error: syntax error, unexpected ‘<‘ in /home/sites/activateyourlife.org.uk/public_html/wp-content/plugins/CustomFunctionsPlugin/CustomFunctionsPlugin.php on line 12


      Erica Neubauer

        January 30, 2014 at 6:08 pm

        And here’s the part that gave the error:

        <pre class=”brush: php; gutter: true; first-line: 1; highlight: []; html-script: false”><?php
        /**
        * Plugin Name: Custom Functions Plugin
        * Plugin URI: http://staging.eventespresso.com
        * Description: A blank plugin where you can put custom functions
        * Version: 1.0
        * Author: Sidney Harrell
        * Author URI: http://sidneyharrell.com
        * License: GPL2
        */

        <?php
        function espresso_get_total_cost_custom($payment_data) {
        remove_filter(‘filter_hook_espresso_get_total_cost’, ‘espresso_get_total_cost’);
        global $wpdb;
        //if for some reason attendee_session isn’t setin the payment data, set it now
        if(!array_key_exists(‘attendee_session’,$payment_data) || empty($payment_data[‘attendee_session’])){
        $SQL = “SELECT attendee_session FROM ” . EVENTS_ATTENDEE_TABLE . ” WHERE id=%d”;
        $session_id = $wpdb->get_var( $wpdb->prepare( $SQL, $payment_data[‘attendee_id’] ));
        $payment_data[‘attendee_session’]=$session_id;
        }
        //find all the attendee rows
        $sql = “SELECT a.final_price, a.quantity, a.amount_pd FROM ” . EVENTS_ATTENDEE_TABLE . ” a “;
        $sql .= ” WHERE a.attendee_session='” . $payment_data[‘attendee_session’] . “‘ ORDER BY a.id ASC”;
        $tickets = $wpdb->get_results($sql, ARRAY_A);
        $total_cost = 0;
        $total_quantity = 0;
        $amount_pd = 0;

        //sum up their final_prices, as this should already take into account discounts
        foreach ($tickets as $ticket) {
        $total_cost += $ticket[‘quantity’] * $ticket[‘final_price’];
        $total_quantity += $ticket[‘quantity’];
        $amount_pd += $ticket[‘amount_pd’];
        }

        // if (!empty($tickets[0][‘coupon_code_price’])) {
        // if ($tickets[0][‘use_percentage’] == ‘Y’) {
        // $payment_data[‘total_cost’] = $total_cost * (1 – ($tickets[0][‘coupon_code_price’] / 100));
        // } else {
        // $payment_data[‘total_cost’] = $total_cost – $tickets[0][‘coupon_code_price’];
        // }
        // } else {
        // $payment_data[‘total_cost’] = $total_cost;
        // }

        $payment_data[‘total_cost’] = number_format( $total_cost, 2, ‘.’, ” );
        $payment_data[‘quantity’] = $total_quantity;
        $payment_data[‘amount_pd’] = number_format( $amount_pd, 2, ‘.’, ” );
        $payment_data[‘amount_owed’] = number_format( $total_cost-$amount_pd, 2, ‘.’, ”);
        //printr( $payment_data, ‘$payment_data’ );
        return $payment_data;
        }
        add_filter(‘filter_hook_espresso_get_total_cost’, ‘espresso_get_total_cost_custom’,5);


        Erica Neubauer

          January 30, 2014 at 10:28 pm

          Alright, never mind, I got it to work. :) I just deleted the <?php part from right before function espresso_get_total_cost_custom($payment_data) and it stopped the error message. And, I followed the rest of the steps in article and my partial payments are now working beautifully! Thanks so much Event Espresso!


          Dean

          • Support Staff

          January 31, 2014 at 2:36 am

          Well done on fixing it!

          Viewing 5 reply threads

          The support post ‘Code not working from Partial Payments wiki article’ is closed to new replies.

          Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

          Event Espresso - Staging Server