Created
July 16, 2021 07:02
-
-
Save JarrydLong/186263bd0044213ff775870496dccf70 to your computer and use it in GitHub Desktop.
This file contains 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 //do not copy | |
/** | |
* This recipe will display the renewal date on the Orders page. This recipe is intended to be used with Stripe. | |
* Notes: | |
* - If a date is returned, we know it's a recurring membership | |
* - If -- is returned, then that specific order is either cancelled or has been renewed (check for a newer order) | |
* - If Unknown is returned, we were unable to calculate the next payment date. | |
* | |
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
* Works for PayPal Express and Stripe payment gateways. | |
* www.paidmembershipspro.com | |
*/ | |
function mypmpro_add_order_heading_renewal( $order_ids ){ | |
echo "<td>Renewal Date</td>"; | |
} | |
add_action( 'pmpro_orders_extra_cols_header', 'mypmpro_add_order_heading_renewal', 10, 1 ); | |
function mypmpro_add_order_renewal_date( $order ){ | |
if ( ! empty( $order->id ) && ! empty( $order->subscription_transaction_id ) && $order->gateway == "stripe" ) { | |
//get the subscription and return the current_period end or false | |
$subscription = $order->Gateway->getSubscription( $order ); | |
if ( ! empty( $subscription ) ) { | |
$customer = $order->Gateway->getCustomer(); | |
if ( ! $customer->delinquent && ! empty ( $subscription->current_period_end ) ) { | |
$offset = get_option( 'gmt_offset' ); | |
$timestamp = $subscription->current_period_end + ( $offset * 3600 ); | |
} elseif ( $customer->delinquent && ! empty( $subscription->current_period_start ) ) { | |
$offset = get_option( 'gmt_offset' ); | |
$timestamp = $subscription->current_period_start + ( $offset * 3600 ); | |
} else { | |
$timestamp = null; // shouldn't really get here | |
} | |
} | |
} | |
if( !empty( $timestamp ) ){ | |
echo "<td>".date_i18n( get_option( 'date_format' ), $timestamp )."</td>"; | |
} else { | |
if( $order->status == 'cancelled' ){ | |
echo "<td>--</td>"; | |
} else { | |
echo "<td>Unknown</td>"; | |
} | |
} | |
} | |
add_action( 'pmpro_orders_extra_cols_body', 'mypmpro_add_order_renewal_date', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment