Last updated
This is the list of hooks in Refer a Friend 4.4.12, grouped by what they affect. For how to add code, see Add code snippets safely.
A few terms used below:
$referral_id/$referrer_id: who referred the order. It’s the advocate’s user ID for registered advocates, or theirref…code for guest advocates.$type:referrerfor the advocate’s reward,friendfor the friend’s Post-First Purchase coupon,registrationfor a registration reward.
Referral codes and links
| Hook | Type | Parameters | Use it to |
|---|---|---|---|
wpgens_raf_code |
Filter | $referral_code |
Change a customer’s referral code when it’s read or created. |
wpgens_raf_referral_code_created |
Action | $code, $user_id, $user_type, $extra |
React to a new code. $user_type is registered_user or guest_user; $extra has a guest’s email and name. Used by the email integrations. |
wpgens_raf_new_user_referral_id |
Action | $referral_id, $user_id |
React to a new user getting a code. |
wpgens_raf_link |
Filter | $link, $referral_code, $type |
Change the referral link. $type is where it’s shown: account, product_tab or shortcode. |
gens_new_user_registration |
Action | $referral_id, $user_id |
React to a referred friend registering. |
{$shortcode}_shortcode_tag |
Filter | $tag |
Rename a shortcode, for example WOO_GENS_RAF_shortcode_tag. |
Rewards and coupons
| Hook | Type | Parameters | Use it to |
|---|---|---|---|
wpgens_raf_order_status |
Filter | $status |
Set the reward status in code. Only used when Generate Referral Reward On is Default. |
gens_raf_generate_coupon |
Filter | $generate, $order_id |
Return false to stop coupons for an order. Applies to the advocate and friend coupons. |
gens_before_generate_user_coupon |
Action | $user_id, $type, $order |
Run code before a coupon is created. Fires even when coupon generation is turned off, so it’s the place to award points instead. |
gens_after_generate_user_coupon |
Action | $user_id, $type, $order, $coupon_id |
Run code after a coupon is created, for example to change it. |
gens_raf_coupon_prefix |
Filter | $prefix, $type |
Read the coupon settings from a different option prefix. Defaults to gens_raf and gens_raf_friend. |
{$prefix}_coupon_amount |
Filter | $amount, $order_id |
Change the coupon amount, for example gens_raf_coupon_amount. |
{$prefix}_discount_type |
Filter | $discount_type |
Change the coupon type, for example gens_raf_discount_type. |
gens_raf_points_amount |
Filter | $points, $order |
Change the points given through WooCommerce Points and Rewards. |
wpgens_subscription_renewal_coupons_number |
Filter | $number |
Limit how many coupons are checked for a renewal. Default 999. |
Checkout and the friend’s discount
| Hook | Type | Parameters | Use it to |
|---|---|---|---|
gens_raf_disable |
Filter | $disabled, $order_id, $referrer_id |
Return true to ignore the referral on an order. |
gens_raf_minimum_order_amount |
Filter | $amount, $order_id |
Change Minimum referral order per order. |
gens_raf_order_info |
Filter | $raf_info, $order, $referrer_id |
Change the fraud check result saved on the order. See Add your own fraud check. |
gens_raf_custom_message |
Filter | $message |
Add a message to the result saved on the order. |
gens_raf_fraud_order_status |
Filter | $statuses |
Which order statuses count as previous orders in the fraud checks. |
wpgens_user_has_orders_status_list |
Filter | $statuses |
Which statuses count when checking whether a guest is an existing customer. Default Processing and Completed. |
gens_raf_checkout_check |
Action | $coupon_code, $referrer_id |
Run your own checks when the friend coupon is validated. |
gens_raf_should_remove_coupon |
Filter | $remove, $coupon_code, $referrer_id |
Return false to keep the friend’s discount, or true to remove it. |
gens_raf_coupon_removal_message |
Filter | $message |
Change the message shown when the discount is removed for an existing customer. |
gens_raf_self_referral_message |
Filter | $message |
Change the message shown when a customer uses their own code. |
gens_raf_coupon_applied |
Filter | $message |
Change the “Coupon Applied!” message. |
gens_raf_coupon_notice_label |
Filter | $label |
Change the text that replaces the friend coupon code in cart notices. Default “Referral discount”. |
gens_raf_coupon_data |
Filter | $data, $coupon_id, $user_id, $code |
Change the coupon created when a friend types a ref… code. |
gens_raf_auto_apply_coupon |
Action | $referrer_id |
Run code when the friend’s discount is applied automatically. Only on the classic cart and checkout. |
Emails
| Hook | Type | Parameters | Use it to |
|---|---|---|---|
gens_raf_send_referral_coupon |
Action | $email, $coupon_code, $type |
Run code after a coupon email is sent. |
wpgens_raf_email_name |
Filter | $name, $email, $order_id, $user |
Change the name used for {{name}} in emails. |
wpgens_raf_email_language |
Filter | $lang, $email_id, $args, $order |
Choose the WPML language of an email. |
wpgens_raf_disallowed_email_roles |
Filter | $roles |
User roles that never get the reminder email. |
wpgens_raf_max_email_recipients |
Filter | $max |
Recipients per Share via email send. Default 15. |
wpgens_raf_email_rate_limit |
Filter | $limit |
Share emails allowed per visitor IP in the window. Default 30. |
wpgens_raf_email_rate_window |
Filter | $seconds |
Length of that window. Default one hour. |
send_referral_notification_email_event |
Action | $order_id |
The scheduled event that sends the reminder email. |
The plugin also fires wpgens_raf_advocate_coupon_email, wpgens_raf_friend_coupon_email, wpgens_raf_reminder_email and wpgens_raf_share_email to trigger its WooCommerce emails. Don’t call them yourself.
My Account, product tab and templates
| Hook | Type | Parameters | Use it to |
|---|---|---|---|
gens_raf_tab_title |
Filter | $title |
Rename the Refer a Friend tab in My Account and on products. |
wpgens_raf_tab_disable |
Filter | $hide |
Return true to hide the product tab. See Show the product tab on some products only. |
wpgens_raf_title |
Filter | $title |
Change the “Unused Refer a Friend Coupons” and “Track your invites” headings. |
gens_raf_coupons_query |
Filter | $args, $user_email |
Change which coupons My Account lists. |
gens_raf_myaccount_coupon_discount |
Filter | $discount, $coupon_id, $discount_type |
Change how a coupon’s value is shown in My Account. |
wpgens_raf_locate_template |
Filter | $template, $template_path, $guest_view |
Load a template from somewhere else. |
gens_after_referral_url |
Action | none | Output content after the referral link. Only in the legacy look. |
Reports and logs
| Hook | Type | Parameters | Use it to |
|---|---|---|---|
new_raf_data |
Action | $type, $data |
Fires for every Event Logs entry. $type is new_order, new_coupon, email_sent, coupon_applied, email_share, user_referred, guest_referral_created or subscription_renewal. |
wpgens_raf_advocates_order_status |
Filter | $statuses, $days |
Which order statuses the Advocates screen counts. |
Plugin lifecycle
| Hook | Type | Parameters | Use it to |
|---|---|---|---|
before_wpgens_raf_init |
Action | none | Run code before the plugin starts. |
after_wpgens_raf_init |
Action | none | Run code after the plugin has loaded. |
Examples
Only count Completed and Processing orders on the Advocates screen:
add_filter( 'wpgens_raf_advocates_order_status', function () {
return array( 'wc-completed', 'wc-processing' );
} );
Give a bigger advocate reward for large friend orders:
add_filter( 'gens_raf_coupon_amount', function ( $amount, $order_id ) {
$order = wc_get_order( $order_id );
if ( $order && $order->get_total() >= 200 ) {
return $amount * 2;
}
return $amount;
}, 10, 2 );
Rename the My Account and product tab:
add_filter( 'gens_raf_tab_title', function () {
return 'Invite friends';
} );