Created
June 24, 2024 11:35
-
-
Save goranefbl/7d13cc6597f1772550c4c4aa874251c9 to your computer and use it in GitHub Desktop.
Enable referral link for specific user roles, disable for users without 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_orders($current_user->ID) && !in_array('editor', $current_user->roles)) { | |
return 'Referral code is available only to users with orders or Editors'; | |
} | |
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_orders($current_user->ID) && !in_array('editor', $current_user->roles)) { | |
return 'Referral link is available only to users with orders or Editors'; | |
} | |
return $raf_link; | |
} | |
add_action('wp','wpgens_custom_account_tabs'); | |
function wpgens_custom_account_tabs(){ | |
$current_user = wp_get_current_user(); | |
if(!user_has_orders($current_user->ID) && !in_array('editor', $current_user->roles)) { | |
$gens_plugin = WPGens_RAF::instance(); | |
remove_filter( 'woocommerce_account_menu_items', array($gens_plugin->my_account,'gens_account_menu_item'),10); | |
} | |
} | |
function user_has_orders($user_id) { | |
$customer_orders = wc_get_orders( array( | |
'customer' => $user_id, | |
) ); | |
return count($customer_orders) > 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment