I’m using Easy Digital Downloads for my Wordpress webshop. After someone buy a item it needs to add data to the SQL database. I got this working by adding PHP code to shortcode-receipt.php. This is working correct but when I reload the receipt via browser or mail the PHP code will fire again.

I figured out that there was a hook in EDD, but i'm not sure how to use them. I figured out that the function needs to be added to functions.php.

file: /wp-content/themes/twentytwenty/functions.php

function pw_edd_on_complete_purchase( $payment_id ) {
## write data to the database ##
add_action( 'edd_complete_purchase', 'pw_edd_on_complete_purchase' );

But in what file do i place

do_action( 'edd_complete_purchase', $payment_id ); ?

2 Answers 2


You don't put do_action() anywhere. The plugin runs that when that action occurs. You just need to hook into it with add_action(). The way hooks work is documented here.

If you're not sure when or how a plugin's own hooks, such as this one, are fired, then you'll need to contact the plugin developer, or consult its developer documentation.


Just to add on top of what @Jacob Peattie said: the do_action is already in the EDD code somewhere, you don't have to add that part. That's the point that you your new function will get called from. Wordpress takes care of wiring up the two things for you, as per the docs link in Jacob's post.

As you wrote in your post, you need to add the add_action to your functions.php, or it can go in a plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.