Set reward percentages by advocate role

Apply a role-specific percentage to the referred order total. The example gives administrators 50% and all other advocates 10%; adjust both values for your program.

Developer note:

Add custom PHP in a small custom plugin or child theme, and test it on a staging site before production. This example requires ongoing maintenance when extension APIs change.

functions.php

<?php

add_filter( 'automatewoo/referrals/reward_amount', 'my_store_referral_reward_by_role', 10, 3 );

/**
 * Calculate a referral reward from the advocate's role.
 *
 * @param float                          $reward_amount Existing reward amount.
 * @param AutomateWoo\Referrals\Advocate $advocate     Advocate.
 * @param WC_Order                       $order        Referred order.
 * @return float
 */
function my_store_referral_reward_by_role( $reward_amount, $advocate, $order ) {
	$user = $advocate->get_user();

	if ( ! $user instanceof WP_User || ! $order instanceof WC_Order ) {
		return $reward_amount;
	}

	$percentage = in_array( 'administrator', $user->roles, true ) ? 50 : 10;

	return (float) $order->get_total() * $percentage / 100;
}
Use of your personal data
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.