Last active
February 26, 2025 11:02
-
-
Save goranefbl/3f77f1a37c7f8389a85760d7a31850ef to your computer and use it in GitHub Desktop.
Hide referral link for users that spent below 300
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(); | |
$total_spent = get_user_total_spent($current_user->ID); | |
if ($total_spent < 300) { | |
return 'Referral code is available only to users who have spent at least 300'; | |
} | |
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(); | |
$total_spent = get_user_total_spent($current_user->ID); | |
if ($total_spent < 300) { | |
return 'Referral link is available only to users who have spent at least 300'; | |
} | |
return $raf_link; | |
} | |
// Helper function to get the total amount spent by a user | |
function get_user_total_spent($user_id) { | |
$customer = new WC_Customer($user_id); | |
return $customer->get_total_spent(); | |
} | |
add_filter('body_class', 'add_spent_based_body_class'); | |
function add_spent_based_body_class($classes) { | |
$current_user = wp_get_current_user(); | |
if ($current_user->ID) { | |
$total_spent = get_user_total_spent($current_user->ID); | |
if ($total_spent < 300) { | |
$classes[] = 'hide-referral-elements'; | |
} | |
} | |
return $classes; | |
} | |
add_action('wp_footer', 'add_spent_based_css'); | |
function add_spent_based_css() { | |
$current_user = wp_get_current_user(); | |
if ($current_user->ID) { | |
$total_spent = get_user_total_spent($current_user->ID); | |
if ($total_spent < 300) { | |
echo '<style>.hide-referral-elements .gens-referral_coupons__table,.hide-referral-elements .gens-referral_coupons__title, .hide-referral-elements .gens-referral_coupons__title, .hide-referral-elements .gens-raf-field--social, .hide-referral-elements .gens-raf-field--email { display: none; }</style>'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment