Reward advocates with points or store credit

Refer a Friend rewards advocates with coupons by default. This page shows how to give loyalty points or store credit instead, or as well. Pick the section for the plugin you use.

WPGens Loyalty Program

The Loyalty Program plugin awards points for Refer a Friend referrals without any code.

  1. In Loyalty Program, turn on the referral earning action and set the points. You can give a fixed number of points or a percentage of the friend’s order.
  2. In Refer a Friend, go to Settings → Friend Reward and turn off Post-First Purchase Coupon. Otherwise the advocate earns the points twice for one referral.
  3. Points are now added each time Refer a Friend would reward the advocate.

The advocate still gets their coupon too. To give only points, add the snippet under Stop creating coupons below.

Don’t also turn on the Loyalty Program’s own referral feature, and don’t use older snippets that call wpgens_loyalty_update_points for referrals. Both give points twice. See Known compatibility issues.

WooCommerce Points and Rewards

Refer a Friend adds a setting to the WooCommerce Points and Rewards plugin.

  1. Go to WooCommerce → Points & Rewards → Settings.
  2. Under the actions that earn points, enter a number in Points earned for referring users.
  3. Click Save changes.

The advocate gets those points for each successful referral. If Post-First Purchase Coupon is on, the friend also gets the same number of points, as long as they have an account.

Give points as a percentage of the friend’s order

Read Add code snippets safely first. Checked with version 4.4.12.

This gives the advocate 1 point for every 100 spent by the friend. Change 0.01 to your rate.

add_filter( 'gens_raf_points_amount', function ( $points, $order ) {
    if ( ! $order instanceof WC_Order ) {
        return $points;
    }
    return (int) floor( $order->get_total() * 0.01 );
}, 10, 2 );

TeraWallet

TeraWallet support needs a snippet. Read Add code snippets safely first. Both snippets are checked with version 4.4.12.

Add the reward to the advocate’s wallet

This adds the Coupon Amount from Advocate Reward to the advocate’s wallet, and the friend’s Post-First Purchase Coupon amount to the friend’s wallet. It works with fixed amounts, not percentages, and only for customers with an account.

add_action( 'gens_before_generate_user_coupon', function ( $user_id, $type, $order ) {
    if ( ! function_exists( 'woo_wallet' ) || ! $order instanceof WC_Order ) {
        return;
    }

    if ( 'friend' === $type ) {
        $user_id = $order->get_user_id();
        $amount  = get_option( 'gens_raf_friend_coupon_amount' );
    } else {
        $amount = get_option( 'gens_raf_coupon_amount' );
    }

    if ( ! is_numeric( $user_id ) || ! $user_id || ! is_numeric( $amount ) ) {
        return;
    }

    woo_wallet()->wallet->credit( (int) $user_id, (float) $amount, 'Referral reward' );
}, 10, 3 );

Then add the snippet under Stop creating coupons below, so customers don’t get a coupon as well.

Make referral coupons cashback coupons

If you use the TeraWallet Wallet Coupons add-on, this turns every referral coupon into a cashback coupon:

add_action( 'gens_after_generate_user_coupon', function ( $user_id, $type, $order, $coupon_id ) {
    update_post_meta( $coupon_id, '_is_coupon_cashback', 'yes' );
}, 10, 4 );

Stop creating coupons

Add this snippet to give only points or credit. It stops all referral coupons, for advocates and friends, and the coupon emails that go with them. The friend’s First Purchase Discount still applies.

add_filter( 'gens_raf_generate_coupon', '__return_false' );

Change the reward text under Display Settings → Reward Box so the referral page says advocates earn points.

Check it worked

Complete a test referral and mark the order with your reward status. Then check the advocate’s points or wallet balance. If you added the stop snippet, no new RAF-… coupon should appear under Marketing → Coupons.

Related

Browse our plugins

Lightweight WooCommerce plugins built for speed. No bloat, no frameworks -- just clean code that works.

View all plugins
Stay in the loop

Get notified when we launch new plugins. No spam, just product updates.