Skip to content

Instantly share code, notes, and snippets.

@DumahX
Last active November 10, 2022 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DumahX/ae4dd22bd9e614ea5ab99be2d6e0ad02 to your computer and use it in GitHub Desktop.
Save DumahX/ae4dd22bd9e614ea5ab99be2d6e0ad02 to your computer and use it in GitHub Desktop.
Display number of days left on a trial period.
<?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