php 会员2在付款后做一些事情

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 会员2在付款后做一些事情相关的知识,希望对你有一定的参考价值。

<?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;

}

以上是关于php 会员2在付款后做一些事情的主要内容,如果未能解决你的问题,请参考以下文章

在元素消失/加载完成后做一些事情

在 fetch 和 mount 完成后做一些事情

PHP Paypal 定期付款

安装Debian后做的一些事情

Laravel 5.2:用户登录后做了什么?

高挑战事情先做还是后做?