Skip to content

Instantly share code, notes, and snippets.

@alagesanbe08
Last active February 10, 2025 06:28
Show Gist options
  • Save alagesanbe08/4d1bdb4e7f800093c139835f7546976f to your computer and use it in GitHub Desktop.
Save alagesanbe08/4d1bdb4e7f800093c139835f7546976f to your computer and use it in GitHub Desktop.
WPLoyalty: Loyalty program based on user role
add_filter( 'woocommerce_account_menu_items', function ($items,$endpoints){
$user = wp_get_current_user();
$user_role = ! empty( $user->roles ) ? $user->roles : [];
if ( empty( $user ) || empty( $user_role ) ) {
return $items;
}
$dis_allowed_roles = [ 'wcwp_wholesale' ]; // Roles to block loyalty program
if ( ! empty( array_intersect( $dis_allowed_roles, $user_role ) ) && isset($items['loyalty_reward'])) {
unset($items['loyalty_reward']);
return $items;
}
return $items;
},1000,2 );
add_filter( 'wlr_before_add_to_loyalty_customer', function ( $status, $user_id, $email ) {
if ( ! $status ) {
return $status;
}
$user = get_user_by( 'email', $email );
$user_role = ! empty( $user->roles ) ? $user->roles : [];
if ( empty( $user ) || empty( $user_role ) ) {
return $status;
}
$dis_allowed_roles = [ 'wcwp_wholesale' ]; // Roles to block loyalty program
if ( ! empty( array_intersect( $dis_allowed_roles, $user_role ) ) ) {
return false;
}
return $status;
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment