• Resolved AaronOverton

    (@aaronoverton)


    I see you’re following a lot of the structure of WooCommerce, so now I wonder if you are using an API call (like $give->getDonation() or some such) for accessing the underlying data or if I should just be using a WP get_post() with the donation ID and access post metadata to get the information I need. I’d like to do this in a way that is most likely to be consistent with your expected methods and most durable over time.

    Yes, I have read the documentation. It is still a work in progress and this question does not yet appear to be covered.

    It does not make sense to connect to the REST API when I’m already using a plugin in the same WordPress installation, so I’m hoping that’s not the answer.

    https://www.ads-software.com/plugins/give/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Devin Walker

    (@dlocc)

    Hi there,

    We are actually following more closely the structure of Easy Digital Downloads. Check out the Give_DB_Customers class and the methods within such as get_customer_by which will grab the details for donors by ID or email and provide you with their info and donor details.

    Thread Starter AaronOverton

    (@aaronoverton)

    So I looked at what you said. I was actually looking for details about the donation, not the customer, in this case.

    What I’ve implemented is that I can use the “give_complete_purchase” action hook to add my functionality:

    add_action('give_complete_purchase', array($this,'postDonationToImis'));

    (For the benefit of other readers, the reason the callback function is in an array is that I’m using the object-oriented plugin methodology. It provides a way to better contain your code and is far less likely to induce conflicts between plugins. Learn it, love it, use it!)

    That action callback receives the donation ID as an argument. I ended up needing detail about the donation, like the total donated. I can use get_post($donationId) to get the donation custom post type, but what I needed for the total was in the post meta. So I ended up with a function like this:

    function postDonationToImis($donationId) {
      $total = get_post_meta($donationId, '_give_payment_total', true);
      // Do stuff with ID and total
    }

    “_give_payment_total” was the metadata I wanted, true indicated I wanted a single value rather than an array of values. There’s other metadata in there, if you need it.

    Maybe you have a wrapper class similar to Give_DB_Customers that abstracts this access? If so, it would be good to reply to this post with that detail. The above works, though.

    Plugin Author Devin Walker

    (@dlocc)

    Ah, so it sounds like I misunderstood your request a bit. Sorry about that! I’m glad you got it figured out anyways though. Perhaps what you’re looking for is give_get_payment_meta() which allows you to grab the total and a lot of other useful info.

    Please let me know if you have any other questions and thanks again for using Give!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘What is the best way to access donation details from another plugin?’ is closed to new replies.