View Categories

Make referral links work for a specific product or category of products

READ FIRST: Code is updated for plugin version 2.0! Also, this code needs to be added at the end of the functions.php file. If you are familiar with editing functions.php, feel free to continue reading. If you haven’t done this before, adding this code in the wrong place might bring the site down and the only way to access it is by editing functions.php file again via FTP. Feel free to contact us if you need help!

If you want to restrict the referral link to work only when purchasing a specific product, add the code below to functions.php file. Of course, change “12345” to your product ID:

function only_specific_product($raf_info,$order,$referrer_id) {
    $items = $order->get_items();
    $enable_referral = "no";
    foreach ( $items as $item ) {
      $product_id = $item['product_id'];
      if($product_id == "12345") {
      	$enable_referral = "yes";
      }
    }
    if($enable_referral === "no") {
    	$raf_info = array("info" => "Specific product wasnt in the cart, referral wont be generated.", "generate" => "false", "increase_referrals" => "false");
    }
    return $raf_info;
}
add_filter( 'gens_raf_order_info', 'only_specific_product',10,3);

And if you want to restrict a referral link to work only when purchasing a product from a specific category, add the code below to functions.php file. Just make sure to change “12345” to your product category ID:

function wpgens_only_specific_cat($raf_info,$order,$referrer_id) {
    $items = $order->get_items();
    $enable_referral = "no";
    foreach ( $items as $item ) {
      $product_id = $item['product_id'];
      $term_list = wp_get_post_terms($product_id, 'product_cat', array('fields' => 'ids'));
      if (is_array($term_list) && in_array("add_your_cat_id_here", $term_list)) {
      	$enable_referral = "yes";
      }
    }
    if($enable_referral === "no") {
    	$raf_info = array("info" => "Specific category wasnt in the cart, referral wont be generated.", "generate" => "false", "increase_referrals" => "false");
    }
    return $raf_info;
}
add_filter( 'gens_raf_order_info', 'wpgens_only_specific_cat',10,3);
What they say

Trusted by 7000+ customers

Our plugins are used by more than 7000 websites across the globe. All of our plugins are rated 5 stars on WordPress.org. Don’t just take our word for it, check what others are saying about WPGens.

I bought and tested the plugin with WooCommerce Subscription and it works like a charm. I had some specific questions to the developer and he responded very fast and helped me. I suggest the plugin!

Refer a Friend PREMIUM
@rinpocse91

If your looking to set up a referral program on your WooCommerce site to boost up your site sale “Refer A Friend for WooCommerce by WPGens” is your plugin to go for. Little blown away with an amazing support provided from (Goran) the plugin working exactly what you want to set up a referral system. Good job guys!

Refer a Friend PREMIUM
@samroon007

We deal with dozens of applications and plugins on a daily basis. Many of them are excellent, but few have truly excellent support. The Refer A Friend plugin is one of them: the response to my questions is always fast, friendly and very helpful.

Refer a Friend PREMIUM
@smartDIYer

This plugin is awesome. It looks good, it’s light weight, has great support – everything you can expect from a paid plugin, only it’s free!!!!

Swifty Bar
@ofirbeigel

Read all testimonials on WordPress Repository.

Get notified when we add new plugins.

We do not publish plugins often, but when we do, it's something awesome. No spam, we promise.