Block affiliate to receive revenue

Hello,

I am trying to create a rule that blocks the user from receiving revenues if haven’t sold more than for example 1000$.
After the client sold 1000$ in one or more orders that user will receive a rate for every product.

In order to do that I tried to use an action filter like this:
add_action( ‘affiliates_referral’, ‘my_affiliates_referral’, 10, 2 );
function my_affiliates_referral( $referral_id, $data ) {
$referral = new Affiliates_Referral();
if ( $referral->read( $referral_id ) ) {
// $referral->reference contains the order ID
if ( $referral->referral_items !== null ) {
foreach ( $referral->referral_items as $item ) {
// $item->reference contains the order item ID
if ( $item->type === ‘product’ ) {
$product_id = $item->object_id;
if ( $product_id === 123 ) {
error_log(
‘Item amount is ‘ . $item->amount . ‘ … reducing by 1’
);
$item->amount -= 1;
}
}
}
$referral->compute(); // calculates the total
$referral->update(); // persists the changes
}
}
}
My idea is to update the amount of the referral if the affiliate does not reach the total amount of orders of 1000$.
However, I cannot get the previous orders associated with this affiliate.
There is any way to list the total of orders for the affiliate?

Thanks in advance,
Vania.

One Response to Block affiliate to receive revenue

  1. George August 24, 2021 at 5:28 pm #

    Hi Vania,

    Welcome back to our support forum.

    In order to get the orders referred by an affiliate you need to fetch them directly from the database. A nice example you can use as a basis for your implementation is the function
    affiliates_get_affiliate_referrals
    located in affiliates-enterprise/lib/core/wp-init.php file.
    Each referral entry includes information on the order id which has been referred. However, apart from that you need to get all the previously recorded referrals each time a new referral is recorded, so that you can check the order amounts and then give a commission if the total sum has reached the desired sum.

    The best way I can think at the moment would be to keep track of the accumulative order total each time an order is referred and then when the limit is reached add a referral with the proper commission. This obviously requires you to store ie in the database the accumulative order total.

    Another approach if you’re not interested in orders that haven’t reached that sum limit or all the previous orders, is to use a custom formula and set the commission to zero each time the order amount doesn’t reach the desired limit.

    Kind regards,
    George

We use cookies to optimize your experience on our site and assume you're OK with that if you stay.
OK, hide this message.

Affiliates · Contact · Jobs · Terms & Conditions · Privacy Policy · Documentation · Downloads · Useful Plugins · My Account

Share