forked from restrictcontentpro/library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrcp-time-based-cancel-link.php
51 lines (41 loc) · 1.62 KB
/
rcp-time-based-cancel-link.php
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
<?php
/**
* Plugin Name: Restrict Content Pro - Time-Based Cancel Link
* Description: Prevents the "Cancel your subscription" link from showing until the member has been subscribed to his or her current subscription for at least 3 months.
* Version: 1.0
* Author: Sandhills Development, LLC
* Author URI: https://sandhillsdev.com
* License: GPL2
*/
/**
* Prevents the "Cancel your membership" link from showing until the membership has been
* active for at least 3 months.
*
* @param bool $can_cancel Whether or not the membership can be cancelled.
* @param int $membership_id ID of the membership being checked.
* @param RCP_Membership $membership Membership object.
*
* @return bool
* @throws Exception
*/
function jp_rcp_membership_can_cancel( $can_cancel, $membership_id, $membership ) {
global $rcp_options;
// Only do this on the Account Page
if ( empty( $rcp_options['account_page'] ) || ! is_page( $rcp_options['account_page'] ) ) {
return $can_cancel;
}
// Return early if other conditions aren't already met.
if ( ! $can_cancel ) {
return false;
}
$timezone = get_option( 'timezone_string' );
$timezone = ! empty( $timezone ) ? $timezone : 'UTC';
$cancel_date = new \DateTime( $membership->get_created_date( false ), new \DateTimeZone( $timezone ) );
$cancel_date->modify( '+3 months'); // change this if you want a different time period
$now = new \DateTime( 'now', new \DateTimeZone( $timezone ) );
if ( $can_cancel && ( $now < $cancel_date ) ) {
$can_cancel = false;
}
return $can_cancel;
}
add_filter( 'rcp_membership_can_cancel', 'jp_rcp_membership_can_cancel', 100, 3 );