-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathrcp-pending-payment-reminder.php
More file actions
77 lines (60 loc) · 2.03 KB
/
rcp-pending-payment-reminder.php
File metadata and controls
77 lines (60 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* Plugin Name: Restrict Content Pro - Pending Payment Reminder
* Description: Sends an email to a member when their payment has remained "Pending" for 24 hours.
* Version: 1.0
* Author: Sandhills Development, LLC
* Author URI: https://sandhillsdev.com
* License: GPL2
*/
/**
* Sends an email to a member when their payment has remained "Pending" for 24 hours.
* This can help remind users that their payment has not completed and prompt them to
* complete their signup.
*/
/**
* Set up a cron job to run our email task once a day.
*
* @return void
*/
function ag_rcp_setup_pending_payment_cron() {
if ( ! wp_next_scheduled( 'ag_rcp_send_pending_payment_reminders' ) ) {
wp_schedule_event( current_time( 'timestamp' ), 'daily', 'ag_rcp_send_pending_payment_reminders' );
}
}
add_action( 'wp', 'ag_rcp_setup_pending_payment_cron' );
/**
* Find all pending payments that are 24 hours old and email the user.
*
* @return void
*/
function ag_rcp_send_pending_payment_reminders() {
/**
* @var RCP_Payments $rcp_payments_db
*/
global $rcp_payments_db;
$args = array(
'number' => 9999,
'status' => 'pending',
'date' => array(
'end' => date( 'Y-m-d', strtotime( '-1 day', current_time( 'timestamp' ) ) )
)
);
$payments = $rcp_payments_db->get_payments( $args );
if ( $payments ) {
foreach ( $payments as $payment ) {
$user = get_userdata( $payment->user_id );
// Set up the RCP_Emails class and properties.
$emails = new RCP_Emails;
$emails->member_id = $payment->user_id;
$emails->payment_id = $payment->id;
// Set up the email subject and message. You'll want to customize these!
$subject = __( 'Your payment has not been completed' );
$message = __( 'Hello %name%, your last payment of %amount% has not been completed.' );
// Send the email.
$emails->send( $user->user_email, $subject, $message );
// Add a note to the user's account so we know this email was sent.
rcp_add_member_note( $user->ID, __( 'Pending payment reminder emailed to user.' ) );
}
}
}