Created
February 26, 2025 11:57
-
-
Save goranefbl/8463e45f5be262709e54a19275bded03 to your computer and use it in GitHub Desktop.
WPGENS RAF: hide referral link for users without referral orders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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