1 <?php
2 3 4 5 6 7 8 9 10
11
12
13 if ( ! defined( 'ABSPATH' ) ) exit;
14
15 16 17 18 19 20 21 22 23
24 function edd_trigger_purchase_receipt( $payment_id, $new_status, $old_status ) {
25
26 if ( isset( $_POST['edd-action'] ) && $_POST['edd-action'] == 'edit_payment' )
27 return;
28
29
30 if ( $old_status == 'publish' || $old_status == 'complete' )
31 return;
32
33
34 if ( $new_status != 'publish' && $new_status != 'complete' )
35 return;
36
37
38 edd_email_purchase_receipt( $payment_id );
39 }
40 add_action( 'edd_update_payment_status', 'edd_trigger_purchase_receipt', 10, 3 );
41
42 43 44 45 46 47 48
49 function edd_resend_purchase_receipt( $data ) {
50 $purchase_id = $data['purchase_id'];
51 edd_email_purchase_receipt( $purchase_id, false );
52
53
54
55 $downloads = edd_get_payment_meta_downloads( $purchase_id );
56
57 if ( is_array( $downloads ) ) {
58 foreach ( $downloads as $download ) {
59 $limit = edd_get_file_download_limit( $download['id'] );
60 if ( ! empty( $limit ) ) {
61 edd_set_file_download_limit_override( $download['id'], $purchase_id );
62 }
63 }
64 }
65
66 wp_redirect( add_query_arg( array( 'edd-message' => 'email_sent', 'edd-action' => false, 'purchase_id' => false ) ) );
67 exit;
68 }
69 add_action( 'edd_email_links', 'edd_resend_purchase_receipt' );
70
71 72 73 74 75 76 77
78 function edd_send_test_email( $data ) {
79 if ( ! wp_verify_nonce( $data['_wpnonce'], 'edd-test-email' ) )
80 return;
81
82
83 edd_email_test_purchase_receipt();
84 }
85 add_action( 'edd_send_test_email', 'edd_send_test_email' );