Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gspice/42b66e325e43fd7aef68231421b2848c to your computer and use it in GitHub Desktop.
Save gspice/42b66e325e43fd7aef68231421b2848c to your computer and use it in GitHub Desktop.
Allows you to restrict referral creation to specific PMS subscription plans
<?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