PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Get Total Price Submitted Across All Entries

  1. blueprintds
    Member

    I recently launched a site, http://cyclethecampus.org, that accepts pledges and donations for a fundraiser event. In the header is a thermometer indicating the total amount of all pledges submitted. Is there a way to grab this total dynamically?

    Our pledge form is here, http://cyclethecampus.org/rider-info/pledges/, the amount field is a donation field.

    [BONUS]
    If we switch the thermometer to show actual donations received, is there a way to get the total of all entries, conditionally based on payment status.

    Posted 13 years ago on Tuesday April 5, 2011 | Permalink
  2. Hi Blueprint,

    Paste this function in your theme's functions.php and then you can call the function anywhere you want to display the total like so:

    [php]
    echo get_payments_total(25);
    Posted 13 years ago on Tuesday April 5, 2011 | Permalink
  3. blueprintds
    Member

    Thanks, David! This is a super slick function. I had to mod the table name because this is a network install, but it does indeed work.

    I do face one problem, though, as part of the current value is calculated with via a pledge form (http://cyclethecampus.org/rider-info/pledges/) that has a user-specified donate input and no paypal routing. I poked around the database for my submitted entry and saw no value passed for the payment_amount. Is there a similar way to grab the sum of this donate field across all entries?

    Thanks,
    -Brian

    Posted 13 years ago on Tuesday April 5, 2011 | Permalink
  4. Brian,
    The payment_amount column will only be populated when PayPal is activate for that form. Here is the function to sum your donation field
    http://pastie.org/1759958

    You will need to pass the field ID as well (in your case, it is 7)

    get_pledge_total(3,7);
    Posted 13 years ago on Tuesday April 5, 2011 | Permalink
  5. Actually, the values are stored formatted as currency, so the function above won't work either.
    The one below will work for US dollars.
    http://pastie.org/pastes/1760191/text

    Posted 13 years ago on Tuesday April 5, 2011 | Permalink
  6. blueprintds
    Member

    Except for when commas are thrown in the mix, am I right? It would work for anything less than $1,000, though.

    I think my simple work-around is to use a normal textbox and your initial get_pledge_total() function. I'll just add a note for users to not use commas, and maybe later I'll add some validation to actually prevent them from doing so.

    Thanks for the awesome work, guys!

    Grace and Peace,
    Brian Richards

    Posted 13 years ago on Wednesday April 6, 2011 | Permalink