Skip to content

Instantly share code, notes, and snippets.

@danielbitzer
Last active September 14, 2022 11:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielbitzer/20ff4efbb7c1fefe16f8e0deaeb44775 to your computer and use it in GitHub Desktop.
Save danielbitzer/20ff4efbb7c1fefe16f8e0deaeb44775 to your computer and use it in GitHub Desktop.
[Refer A Friend] Advocate rewards based on their user role and percentage of order
<?php
add_filter( 'automatewoo/referrals/reward_amount', 'my_automatewoo_referral_reward_amount', 10, 3 );
/**
* @param $reward_amount
* @param AW_Model_Referral_Advocate $advocate
* @param WC_Order $order
* @return mixed
*/
function my_automatewoo_referral_reward_amount( $reward_amount, $advocate, $order ) {
$advocate_user = $advocate->get_user();
$role = current( $advocate_user->roles );
if ( $role == 'administrator' ) {
$reward_percentage = 50;
}
else {
$reward_percentage = 10;
}
return $order->get_total() * $reward_percentage / 100;
}
@rayice
Copy link

rayice commented Jul 27, 2021

Above is percentage based amount, but is it possible to set the different fixed amount for advokat based on his role which he will earn only when customer reffered to website and purchased.

Because by default automatewoo refer a freind allow to add 1 price for advokat and 1 for person who reffered, we want to keep same settings but want to change retail price for advokat to something else then the mentioned in setting and 0 earning for customer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment