Skip to content

Instantly share code, notes, and snippets.

@codelion7
Last active October 17, 2017 09:08
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 codelion7/71787af8dedceebe611612cbf4a0cb77 to your computer and use it in GitHub Desktop.
Save codelion7/71787af8dedceebe611612cbf4a0cb77 to your computer and use it in GitHub Desktop.
AffiliateWP MLM - Apply a 30% Direct Commission Rate for Affiliates without Sub Affiliates
/**
* Apply a 30% direct commission rate for affiliates without Sub Affiliates
*/
function affwp_mlm_get_non_parent_rate( $rate, $affiliate_id, $type, $reference ) {
// If a per-affiliate rate is set, use that
if ( affiliate_wp()->affiliates->get_column( 'rate', $affiliate_id ) ) {
return $rate;
}
// Stop if the affiliate has sub affiliates
if ( affwp_mlm_is_parent_affiliate( $affiliate_id ) ) {
return $rate;
} else {
$rate = 30; // The non-parent rate to apply
// Format percentage rates
$rate = ( 'percentage' === $type ) ? $rate / 100 : $rate;
}
return $rate;
}
add_filter( 'affwp_get_affiliate_rate', 'affwp_mlm_get_non_parent_rate', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment