Last active
November 10, 2022 16:50
-
-
Save DumahX/ae4dd22bd9e614ea5ab99be2d6e0ad02 to your computer and use it in GitHub Desktop.
Display number of days left on a trial period.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function mepr_trial_num_days() { | |
$user_id = get_current_user_id(); | |
$content = ''; | |
if ( 0 == $user_id ) { | |
return; | |
} | |
$user = new MeprUser( $user_id ); | |
$txns = $user->active_product_subscriptions( 'transactions' ); | |
$subs = []; | |
if ( is_array( $txns ) ) { | |
foreach ( $txns as $txn ) { | |
if ( ( $sub = $txn->subscription() ) && $sub->in_trial() && ! in_array( $sub->id, $subs ) ) { | |
$subs[] = $sub; | |
} | |
} | |
} | |
foreach ( $subs as $sub ) { | |
$content .= 'Days left on trial period: ' . $sub->days_till_expiration(); | |
} | |
return $content; | |
} | |
add_shortcode('mepr-trial-num-days', 'mepr_trial_num_days'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment