<?php
/**
* Plugin Name: Membership2 do something after payment
* Plugin URI: https://premium.wpmudev.org/
* Description: Membership2 do something after payment
* Author: Ariful Islam @ WPMUDEV
* Author URI: https://premium.wpmudev.org/profile/itsarifulislam
* License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_filter( 'ms_model_pages_redirect_to', 'my_custom_things', 10, 2 );
function my_custom_things( $url, $page_type ) {
if ( $page_type != 'registration-complete' && ! is_user_logged_in() ) {
return $url;
}
$id = get_current_user_id();
$member = MS_Factory::load( 'MS_Model_Member', $id );
$has_paid_membership = $has_paid_invoice = $has_trial_invoice = false;
if ( $member->subscriptions ) {
foreach ( $member->subscriptions as $subscription ) {
if ( $subscription->is_system() ) { continue; }
$membership = $subscription->get_membership();
if ( ! $membership->is_free() ) {
$has_paid_membership = true;
}
$invoices = $subscription->get_invoices();
if ( $invoices ) {
foreach ( $invoices as $invoice ) {
if ( $invoice->is_paid() ) {
$has_paid_invoice = true;
}
if ( $invoice->uses_trial ) {
$has_trial_invoice = true;
}
}
}
}
}
if ( $has_paid_membership && $has_paid_invoice ) {
// Do Something for only paid membership.
// Do it from your self: If data alredy not added in the table, add it.
}
if ( $has_paid_membership && $has_trial_invoice ) {
// Do Something for only trail membership.
// Do it from your self: If data alredy not added in the table, add it.
}
if ( $has_paid_membership ) {
// Do Something for both of paid or trail membership.
// Do it from your self: If data alredy not added in the table, add it.
}
return $url;
}