Skip to content

Instantly share code, notes, and snippets.

@goranefbl
Created February 26, 2025 11:57
Show Gist options
  • Save goranefbl/8463e45f5be262709e54a19275bded03 to your computer and use it in GitHub Desktop.
Save goranefbl/8463e45f5be262709e54a19275bded03 to your computer and use it in GitHub Desktop.
WPGENS RAF: hide referral link for users without referral orders
<?php
add_filter('wpgens_raf_code', 'gens_raf_code', 10, 1);
function gens_raf_code($raf_code) {
$current_user = wp_get_current_user();
if (!user_has_friends($current_user->ID)) {
return 'Referral code is available only to users with friends';
}
return $raf_code;
}
add_filter('wpgens_raf_link', 'gens_raf_link', 10, 3);
function gens_raf_link($raf_link, $referral_id, $type) {
$current_user = wp_get_current_user();
if (!user_has_friends($current_user->ID)) {
return 'Referral link is available only to users with friends';
}
return $raf_link;
}
add_action('wp', 'wpgens_custom_account_tabs');
function wpgens_custom_account_tabs() {
$current_user = wp_get_current_user();
if (!user_has_friends($current_user->ID)) {
$gens_plugin = WPGens_RAF::instance();
remove_filter('woocommerce_account_menu_items', array($gens_plugin->my_account, 'gens_account_menu_item'), 10);
}
}
function user_has_friends($user_id) {
$num_friends = get_user_meta($user_id, 'gens_num_friends', true);
return !empty($num_friends) && intval($num_friends) >= 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment