awesomemotive / edd-library

EDD Code Snippet Library
http://library.easydigitaldownloads.com/
141 stars 42 forks source link

Update adjust-rate-for-referrals.html code #167

Open mihaijoldis opened 2 years ago

mihaijoldis commented 2 years ago

That code will most likely no longer work as we use custom tables now for commissions. Needs a rewrite to get the data correctly from the DB.

mihaijoldis commented 2 years ago

This is the code snippet that @tubiz provided so that a commission is not recorded if the purchase was a referral

function affwp_eddc_restrict_commission( $commissions_calculated, $payment ) {

    if ( ! function_exists( 'affiliate_wp' ) ) {
        return $commissions_calculated;
    }

    $referral = affiliate_wp()->referrals->get_by_with_context( 'reference', $payment->ID, 'edd' );

    if ( ! empty( $referral ) ) {
        return array();
    }

    return $commissions_calculated;
}
add_filter( 'eddc_commissions_calculated', 'affwp_eddc_restrict_commission', 10, 2 );