Easy Digital Downloads – How to use hooks correctly?

Question

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 ); ?

0
Jack 1 year 2020-07-17T04:10:26-05:00 0 Answers 33 views 0

Leave an answer

Browse
Browse