Last active
May 14, 2018 10:25
-
-
Save wpmudev-sls/54e308e66d822dff1c96cd838aaed8b1 to your computer and use it in GitHub Desktop.
Membership2 do something after payment
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 | |
/** | |
* 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment