Easy Digital Downloads - Fire PHP when transaction was successful goes wrong

139 Views Asked by At

I’m using Easy Digital Downloads for my Wordpress webshop. After someone buys a item it needs to add credits to the MySQL 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: php <?php if( edd_is_payment_complete( $payment->ID ) && edd_receipt_show_download_files( $item['id'], $edd_receipt_args, $item ) ) : ?>

  • Could someone help me out here?
  • What is the best method to fire PHP code when a payment is successful?

Thanks in advance!

1

There are 1 best solutions below

0
Pavel Janicek On

There is action edd_complete_purchase which fires when order is completed.

So, in your case, I would remove the code from the shortcode and created an plugin. Inside the plugin should be something like this

function my_edd_receipt( $payment_id ){
if( edd_is_payment_complete( $payment_id ) && edd_receipt_show_download_files( $item['id'], $edd_receipt_args, $item ) ) :
}

add_action( 'edd_complete_purchase', 'my_edd_receipt');