Skip to content

Commit

Permalink
Merge pull request #110 from dparker1005/subs-table-compat
Browse files Browse the repository at this point in the history
Adding basic compatibility with subs table
  • Loading branch information
dparker1005 committed Dec 11, 2023
2 parents 6fc4edc + 83db67a commit 6905ecf
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pmpro-pay-by-check.php
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,14 @@ function pmpropbc_send_invoice_email( $morder ) {
return;
}

// If using PMPro v3.0+, update the subscription data.
if ( method_exists( $morder, 'get_subscription' ) ) {
$subscription = $morder->get_subscription();
if ( ! empty( $subscription ) ) {
$subscription->update();
}
}

// Check order meta to see if an invoice email has already been sent for this order.
if ( function_exists( 'get_pmpro_membership_order_meta' ) && get_pmpro_membership_order_meta( $morder->id, 'pmpropbc_invoice_email_sent', true ) ) {
return;
Expand Down Expand Up @@ -877,6 +885,15 @@ function pmpropbc_recurring_orders()
foreach($orders as $order_id)
{
$order = new MemberOrder($order_id);

// If using PMPro v3.0+, only create a pending order if the subscription is still active.
if ( method_exists( $order, 'get_subscription' ) ) {
$subscription = $order->get_subscription();
if ( ! empty( $subscription ) && 'active' !== $subscription->get_status() ) {
continue;
}
}

$user = get_userdata($order->user_id);
if ( $user ) {
$user->membership_level = pmpro_getSpecificMembershipLevelForUser( $order->user_id, $level->id );
Expand Down Expand Up @@ -1055,6 +1072,15 @@ function pmpropbc_reminder_emails()
{
//get some data
$order = new MemberOrder($order_id);

// If using PMPro v3.0+, only send reminders if the subscription is still active.
if ( method_exists( $order, 'get_subscription' ) ) {
$subscription = $order->get_subscription();
if ( ! empty( $subscription ) && 'active' !== $subscription->get_status() ) {
continue;
}
}

$user = get_userdata($order->user_id);
if ( $user ) {
$user->membership_level = pmpro_getSpecificMembershipLevelForUser( $order->user_id, $level->id );
Expand Down Expand Up @@ -1205,6 +1231,15 @@ function pmpropbc_cancel_overdue_orders()
{
//get the order and user data
$order = new MemberOrder($order_id);

// If using PMPro v3.0+, only process overdue orders if the subscription is still active.
if ( method_exists( $order, 'get_subscription' ) ) {
$subscription = $order->get_subscription();
if ( ! empty( $subscription ) && 'active' !== $subscription->get_status() ) {
continue;
}
}

$user = get_userdata($order->user_id);
if ( $user ) {
$user->membership_level = pmpro_getSpecificMembershipLevelForUser( $order->user_id, $level->id );
Expand Down

0 comments on commit 6905ecf

Please sign in to comment.