Skip to content

Instantly share code, notes, and snippets.

@wpmudev-sls
Created July 31, 2018 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpmudev-sls/2721432af9fe1e7b4a4e4305fd255c84 to your computer and use it in GitHub Desktop.
Save wpmudev-sls/2721432af9fe1e7b4a4e4305fd255c84 to your computer and use it in GitHub Desktop.
Affiliate - limit affiliate commission period with in m2p addons
<?php
/**
* Plugin Name: Affiliate - limit affiliate commission period with in m2p addons
* Plugin URI: https://premium.wpmudev.org/
* Description: This will help to limit the affiliate commission with a specific time like 1 year from the initial subscription
* Author: Ariful Islam @ WPMUDEV
* Author URI: https://premium.wpmudev.org/profile/itsarifulislam
* License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_filter( 'affiliate_process_payment', function( $status, $user_id_referrer, $reward, $user_id, $meta ) {
if ( ! class_exists('MS_Factory') ) return $status;
$subscription = MS_Factory::load( 'MS_Model_Relationship', $meta['subscription_id'] );
$start_date = $subscription->start_date;
$end_date = date("Y-m-d", strtotime(date("Y-m-d", strtotime($start_date)) . " + 1 year"));
$end_date = DateTime::createFromFormat('Y-m-d', $end_date);
$today = new DateTime();
return $today < $end_date;
}, 10, 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment