Created
November 8, 2018 06:10
-
-
Save tubiz/3ccef5613a171db7abcdc079e57506c7 to your computer and use it in GitHub Desktop.
Allows you to restrict referral creation to specific PMS subscription plans
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: AffiliateWP - Restrict Referral Creation To Specific PMS Subscription Plans | |
* Plugin URI: http://affiliatewp.com | |
* Description: Allows you to restrict referral creation to specific PMS subscription plans | |
* Author: Tunbosun Ayinla, tubiz | |
* Author URI: https://bosun.me | |
* Version: 1.0 | |
*/ | |
function _prefix_affwp_restrict_pms_referral_creation( $data ) { | |
if ( 'pms' != $data['context'] ) { | |
return $data; | |
} | |
$subscription_id = false; | |
if ( false !== strpos( $data['reference'], '|' ) ) { | |
$reference_array = explode( '|', $data['reference'] ); | |
$subscription_id = $reference_array[1]; | |
} else { | |
if ( function_exists( 'pms_get_payment' ) ) { | |
$payment = pms_get_payment( $data['reference'] ); | |
$subscription_id = $payment->subscription_id; | |
} | |
} | |
// Enter the ID for the subscription plans that referrals should be created for | |
$allowed_subscription_plans = array( 10, 11 ); | |
if ( ! in_array( $subscription_id, $allowed_subscription_plans ) ) { | |
affiliate_wp()->utils->log( 'Referral creation has been disabled for this PMS Subscription Plan: ' . $subscription_id ); | |
return array(); | |
} | |
return $data; | |
} | |
add_filter( 'affwp_pre_insert_referral_data', '_prefix_affwp_restrict_pms_referral_creation' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment