/* USING S2 NOTIFICATIONS API
* ADD SUBSCRIPTION DETAILS FOR USERS WITH 100% DISCOUNTS
* using Signup Notification URL https://wmhca.org/?s2_signup_notification=yes&user_email=%%payer_email%%&coupon=%%coupon_code%%
*/
add_action( 'init', 's2_signup_notification' ) ;
function s2_signup_notification() {
if ( ! empty( $_GET['s2_signup_notification'] ) && $_GET['s2_signup_notification'] === 'yes' ) {
if( ! empty( $_GET['user_email'] ) && ! empty( $_GET['coupon'] ) ) {
$user_id = get_user_by( 'email',$_GET['user_email'] )->ID ;
//use current time as start time
$period_start = date( 'Y/m/d', time() ) ;
//create 1-year subscription term as default (YMMV)
$year_from_now = time() + 31536000 ;
$period_end = date( 'Y/m/d', $year_from_now ) ;
//add coupon name as string (is typically saved by S2 as serialized, not necessary or helpful in many cases
update_user_meta( $user_id, 'wp_s2member_coupon_codes', $_GET['coupon'] ) ;
//create 1-year subscription term as default (YMMV)
update_user_meta( $user_id, 'wp_s2member_auto_eot_time', $year_from_now ) ;
update_user_meta( $user_id, 'current_subscription_start_date', $period_start ) ;
update_user_meta( $user_id, 'current_subscription_end_date', $period_end ) ;
}
exit ; // We can exit here. There's no reason to continue loading WordPress in this case.
}
}